Skip to content

Commit

Permalink
copy circuits
Browse files Browse the repository at this point in the history
  • Loading branch information
sjdilkes committed Nov 13, 2024
1 parent 330df5a commit 3d66238
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
7 changes: 3 additions & 4 deletions pytket/tests/predicates_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1035,10 +1035,9 @@ def test_greedy_pauli_synth() -> None:
rega[0], regb[0]
).SWAP(regb[1], rega[0])
d = circ.copy()
pss = GreedyPauliSimp(0.5, 0.5)
assert not GreedyPauliSimp(0.5, 0.5, thread_timeout=0, only_reduce=False).apply(d)
assert pss.apply(d)
assert GreedyPauliSimp(0.5, 0.5, thread_timeout=10, trials=5, threads=5).apply(d)
assert not GreedyPauliSimp(0.5, 0.5, thread_timeout=0, only_reduce=True).apply(d)
assert GreedyPauliSimp(0.5, 0.5, thread_timeout=10, trials=5, threads=3).apply(d)

assert np.allclose(circ.get_unitary(), d.get_unitary())
assert d.name == "test"
# test gateset
Expand Down
8 changes: 4 additions & 4 deletions tket/include/tket/Transformations/GreedyPauliOptimisation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,10 +620,10 @@ gpg_from_unordered_set(const std::vector<SymPauliTensor>& unordered_set);
* @return Circuit
*/
Circuit greedy_pauli_graph_synthesis_flag(
const Circuit& circ, std::atomic<bool>& stop_flag,
double discount_rate = 0.7, double depth_weight = 0.3,
unsigned max_lookahead = 500, unsigned max_tqe_candidates = 500,
unsigned seed = 0, bool allow_zzphase = false);
Circuit circ, std::atomic<bool>& stop_flag, double discount_rate = 0.7,
double depth_weight = 0.3, unsigned max_lookahead = 500,
unsigned max_tqe_candidates = 500, unsigned seed = 0,
bool allow_zzphase = false);

/**
* @brief Converts the given circuit into a GPGraph and conjugates each node
Expand Down
6 changes: 4 additions & 2 deletions tket/src/Transformations/GreedyPauliOptimisation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ Circuit greedy_pauli_set_synthesis(
}

Circuit greedy_pauli_graph_synthesis_flag(
const Circuit& circ, std::shared_ptr<std::atomic<bool>> stop_flag,
Circuit circ, std::shared_ptr<std::atomic<bool>> stop_flag,
double discount_rate, double depth_weight, unsigned max_lookahead,
unsigned max_tqe_candidates, unsigned seed, bool allow_zzphase) {
if (max_lookahead == 0) {
Expand Down Expand Up @@ -845,6 +845,7 @@ Transform greedy_pauli_optimisation(
if (threads_started < trials && all_threads.size() < max_threads) {
std::shared_ptr<std::atomic<bool>> stop_flag =
std::make_shared<std::atomic<bool>>(false);
// Circuit copy(circ);
std::future<Circuit> future = std::async(
std::launch::async,
[&, stop_flag]() { // Capture `stop_flag` explicitly in the lambda
Expand All @@ -855,7 +856,7 @@ Transform greedy_pauli_optimisation(
all_threads.emplace(std::move(future), stop_flag);
threads_started++;
// continue to come straight back to this if statement, meaning we
// maximise threads
// maximise parallel threads
continue;
}

Expand All @@ -876,6 +877,7 @@ Transform greedy_pauli_optimisation(

// Return the smallest circuit if any were found within the single
// thread_timeout
// If none are found then return false
if (circuits.empty()) return false;
auto min = std::min_element(
circuits.begin(), circuits.end(),
Expand Down

0 comments on commit 3d66238

Please sign in to comment.