diff --git a/src/optimiser/taso.rs b/src/optimiser/taso.rs index c9c3fed1..4e299855 100644 --- a/src/optimiser/taso.rs +++ b/src/optimiser/taso.rs @@ -268,7 +268,9 @@ where drop(tx_result); // Queue the initial circuit - tx_work.send((initial_circ_hash, circ.clone())).unwrap(); + tx_work + .send(vec![(initial_circ_hash, circ.clone())]) + .unwrap(); // A counter of circuits seen. let mut circ_cnt = 1; @@ -295,19 +297,18 @@ where match msg { Ok(hashed_circs) => { jobs_completed += 1; - for (circ_hash, circ) in hashed_circs { + for (circ_hash, circ) in &hashed_circs { circ_cnt += 1; if circ_cnt % 1000 == 0 { // TODO: Add a minimum time between logs log_progress::<_,u64,usize>(log_config.progress_log.as_mut(), circ_cnt, None, &seen_hashes) .expect("Failed to write to progress log"); } - if seen_hashes.contains(&circ_hash) { + if !seen_hashes.insert(*circ_hash) { continue; } - seen_hashes.insert(circ_hash); - let cost = (self.cost)(&circ); + let cost = (self.cost)(circ); // Check if we got a new best circuit if cost < best_circ_cost { @@ -315,14 +316,13 @@ where best_circ_cost = cost; log_best(best_circ_cost, log_candidates.as_mut()).unwrap(); } - - // Fill the workqueue with data from pq - if tx_work.send((circ_hash, circ)).is_err() { - eprintln!("All our workers panicked. Stopping optimisation."); - break; - }; jobs_sent += 1; } + // Fill the workqueue with data from pq + if tx_work.send(hashed_circs).is_err() { + eprintln!("All our workers panicked. Stopping optimisation."); + break; + }; // If there is no more data to process, we are done. // diff --git a/src/optimiser/taso/hugr_pchannel.rs b/src/optimiser/taso/hugr_pchannel.rs index 3684e94c..c3e157cf 100644 --- a/src/optimiser/taso/hugr_pchannel.rs +++ b/src/optimiser/taso/hugr_pchannel.rs @@ -27,7 +27,7 @@ where /// /// Get back a channel on which to queue hugrs with their hash, and /// a channel on which to receive the output. - pub fn init(cost_fn: C, queue_capacity: usize) -> (Sender, Receiver) { + pub fn init(cost_fn: C, queue_capacity: usize) -> (Sender>, Receiver) { let (ins, inr) = crossbeam_channel::unbounded(); let (outs, outr) = crossbeam_channel::bounded(0); Self::run(inr, outs, cost_fn, queue_capacity); @@ -36,7 +36,7 @@ where /// Run the queuer as a thread. fn run( - in_channel_orig: Receiver<(u64, Hugr)>, + in_channel_orig: Receiver>, out_channel_orig: Sender<(u64, Hugr)>, cost_fn: C, queue_capacity: usize, @@ -54,8 +54,10 @@ where if pq.is_empty() { // Nothing queued to go out. Wait for input. match in_channel.recv() { - Ok((hash, circ)) => { - pq.push_with_hash_unchecked(circ, hash); + Ok(new_circs) => { + for (hash, circ) in new_circs { + pq.push_with_hash_unchecked(circ, hash); + } } // The sender has closed the channel, we can stop. Err(_) => break, @@ -64,8 +66,10 @@ where select! { recv(in_channel) -> result => { match result { - Ok((hash, circ)) => { - pq.push_with_hash_unchecked(circ, hash); + Ok(new_circs) => { + for (hash, circ) in new_circs { + pq.push_with_hash_unchecked(circ, hash); + } } // The sender has closed the channel, we can stop. Err(_) => break,