@@ -95,7 +95,9 @@ impl Default for BadgerOptions {
95
95
/// always processing the circuit with the lowest cost first. Rewrites are
96
96
/// computed for that circuit and all new circuit obtained are added to the queue.
97
97
///
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.
99
101
///
100
102
/// [Quartz]: https://arxiv.org/abs/2204.09033
101
103
/// [TASO]: https://dl.acm.org/doi/10.1145/3341301.3359630
@@ -141,15 +143,20 @@ where
141
143
log_config : BadgerLogger ,
142
144
options : BadgerOptions ,
143
145
) -> Circuit {
144
- if options. split_circuit && options. n_threads . get ( ) > 1 {
145
- return self . split_run ( circ, log_config, options) . unwrap ( ) ;
146
- }
147
146
match options. n_threads . get ( ) {
148
147
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
+ }
150
156
}
151
157
}
152
158
159
+ /// Run the Badger optimiser on a circuit, using a single thread.
153
160
#[ tracing:: instrument( target = "badger::metrics" , skip( self , circ, logger) ) ]
154
161
fn badger (
155
162
& self ,
@@ -249,8 +256,8 @@ where
249
256
250
257
/// Run the Badger optimiser on a circuit, using multiple threads.
251
258
///
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 .
254
261
#[ tracing:: instrument( target = "badger::metrics" , skip( self , circ, logger) ) ]
255
262
fn badger_multithreaded (
256
263
& self ,
@@ -382,9 +389,11 @@ where
382
389
best_circ
383
390
}
384
391
392
+ /// Run the Badger optimiser on a circuit, with data parallel multithreading.
393
+ ///
385
394
/// Split the circuit into chunks and process each in a separate thread.
386
395
#[ tracing:: instrument( target = "badger::metrics" , skip( self , circ, logger) ) ]
387
- fn split_run (
396
+ fn badger_split_multithreaded (
388
397
& self ,
389
398
circ : & Circuit < impl HugrView > ,
390
399
mut logger : BadgerLogger ,
0 commit comments