Skip to content

Commit 4052714

Browse files
authored
docs: Improved multi-threading docs for Badger (#495)
1 parent d9a713c commit 4052714

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

tket2/src/optimiser/badger.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ impl Default for BadgerOptions {
9595
/// always processing the circuit with the lowest cost first. Rewrites are
9696
/// computed for that circuit and all new circuit obtained are added to the queue.
9797
///
98-
/// This optimiser is single-threaded.
98+
/// There are a single-threaded and two multi-threaded versions of the optimiser,
99+
/// controlled by setting the [`BadgerOptions::n_threads`] and
100+
/// [`BadgerOptions::split_circuit`] fields.
99101
///
100102
/// [Quartz]: https://arxiv.org/abs/2204.09033
101103
/// [TASO]: https://dl.acm.org/doi/10.1145/3341301.3359630
@@ -141,15 +143,20 @@ where
141143
log_config: BadgerLogger,
142144
options: BadgerOptions,
143145
) -> Circuit {
144-
if options.split_circuit && options.n_threads.get() > 1 {
145-
return self.split_run(circ, log_config, options).unwrap();
146-
}
147146
match options.n_threads.get() {
148147
1 => self.badger(circ, log_config, options),
149-
_ => self.badger_multithreaded(circ, log_config, options),
148+
_ => {
149+
if options.split_circuit {
150+
self.badger_split_multithreaded(circ, log_config, options)
151+
.unwrap()
152+
} else {
153+
self.badger_multithreaded(circ, log_config, options)
154+
}
155+
}
150156
}
151157
}
152158

159+
/// Run the Badger optimiser on a circuit, using a single thread.
153160
#[tracing::instrument(target = "badger::metrics", skip(self, circ, logger))]
154161
fn badger(
155162
&self,
@@ -249,8 +256,8 @@ where
249256

250257
/// Run the Badger optimiser on a circuit, using multiple threads.
251258
///
252-
/// This is the multi-threaded version of [`badger`]. See [`BadgerOptimiser`] for
253-
/// more details.
259+
/// This is the multi-threaded version of [`Self::badger`], using a single
260+
/// priority queue and multiple workers to process the circuits in parallel.
254261
#[tracing::instrument(target = "badger::metrics", skip(self, circ, logger))]
255262
fn badger_multithreaded(
256263
&self,
@@ -382,9 +389,11 @@ where
382389
best_circ
383390
}
384391

392+
/// Run the Badger optimiser on a circuit, with data parallel multithreading.
393+
///
385394
/// Split the circuit into chunks and process each in a separate thread.
386395
#[tracing::instrument(target = "badger::metrics", skip(self, circ, logger))]
387-
fn split_run(
396+
fn badger_split_multithreaded(
388397
&self,
389398
circ: &Circuit<impl HugrView>,
390399
mut logger: BadgerLogger,

0 commit comments

Comments
 (0)