Skip to content

Commit

Permalink
Merge pull request #1250 from qiboteam/copy_M
Browse files Browse the repository at this point in the history
Fix deep copy of `gates.M` in `Circuit.copy()`
  • Loading branch information
renatomello authored Mar 14, 2024
2 parents 3474d5e + 8208831 commit 66252b6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/qibo/models/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,10 @@ def copy(self, deep: bool = False):
NotImplementedError,
"Cannot create deep copy of fused circuit.",
)
new_circuit.add(copy.copy(gate))
if isinstance(gate, gates.M):
new_circuit.add(gate.__class__(*gate.init_args, **gate.init_kwargs))
else:
new_circuit.add(copy.copy(gate))
else:
if self.accelerators: # pragma: no cover
raise_error(
Expand Down
9 changes: 3 additions & 6 deletions tests/test_transpiler_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,7 @@ def test_sabre_random_circuits(n_gates, look, decay, placer, connectivity):
final_map=final_qubit_map,
initial_map=initial_layout,
)
circuit_result = transpiled_circuit.execute(nshots=100)
assert circuit_result.frequencies() == measurement.result.frequencies()
assert transpiled_circuit.queue[-1].result is measurement.result
assert transpiled_circuit.queue[-1].register_name == measurement.register_name


def test_sabre_memory_map():
Expand All @@ -324,9 +322,8 @@ def test_sabre_intermediate_measurements():
connectivity.add_edges_from([(0, 1), (1, 2)])
router = Sabre(connectivity=connectivity)
initial_layout = {"q0": 0, "q1": 1, "q2": 2}
routed_circ, final_layout = router(circuit=circ, initial_layout=initial_layout)
circuit_result = routed_circ.execute(nshots=100)
assert routed_circ.queue[3].result is measurement.result
routed_circ, _ = router(circuit=circ, initial_layout=initial_layout)
assert routed_circ.queue[3].register_name == measurement.register_name


@pytest.mark.parametrize("router_algorithm", [Sabre, ShortestPaths])
Expand Down

0 comments on commit 66252b6

Please sign in to comment.