diff --git a/src/qibo/transpiler/blocks.py b/src/qibo/transpiler/blocks.py index 199979767e..6e2b1122a2 100644 --- a/src/qibo/transpiler/blocks.py +++ b/src/qibo/transpiler/blocks.py @@ -200,12 +200,11 @@ def block_decomposition(circuit: Circuit, fuse: bool = True): remove_list = [first_block] if len(initial_blocks[1:]) > 0: for second_block in initial_blocks[1:]: - try: + if second_block.qubits == first_block.qubits: first_block = first_block.fuse(second_block) remove_list.append(second_block) - except BlockingError: - if not first_block.commute(second_block): - break + elif not first_block.commute(second_block): + break blocks.append(first_block) _remove_gates(initial_blocks, remove_list) diff --git a/src/qibo/transpiler/router.py b/src/qibo/transpiler/router.py index 8a3bf54180..6023296d8c 100644 --- a/src/qibo/transpiler/router.py +++ b/src/qibo/transpiler/router.py @@ -379,7 +379,9 @@ def __call__(self, circuit: Circuit, initial_layout: dict): else: self._find_new_mapping() - routed_circuit = self.circuit.routed_circuit(circuit_kwargs=circuit.init_kwargs) + circuit_kwargs = circuit.init_kwargs + circuit_kwargs["wire_names"] = list(initial_layout.keys()) + routed_circuit = self.circuit.routed_circuit(circuit_kwargs=circuit_kwargs) if self._final_measurements is not None: routed_circuit = self._append_final_measurements( routed_circuit=routed_circuit @@ -658,7 +660,9 @@ def __call__(self, circuit: Circuit, initial_layout: dict): else: self._find_new_mapping() - routed_circuit = self.circuit.routed_circuit(circuit_kwargs=circuit.init_kwargs) + circuit_kwargs = circuit.init_kwargs + circuit_kwargs["wire_names"] = list(initial_layout.keys()) + routed_circuit = self.circuit.routed_circuit(circuit_kwargs=circuit_kwargs) if self._final_measurements is not None: routed_circuit = self._append_final_measurements( routed_circuit=routed_circuit diff --git a/src/qibo/transpiler/unroller.py b/src/qibo/transpiler/unroller.py index c62ae4e273..6b8f3e9c60 100644 --- a/src/qibo/transpiler/unroller.py +++ b/src/qibo/transpiler/unroller.py @@ -85,7 +85,7 @@ def __call__(self, circuit: Circuit): Returns: (:class:`qibo.models.circuit.Circuit`): equivalent circuit with native gates. """ - translated_circuit = circuit.__class__(circuit.nqubits) + translated_circuit = Circuit(**circuit.init_kwargs) for gate in circuit.queue: translated_circuit.add( translate_gate( diff --git a/tests/test_transpiler_pipeline.py b/tests/test_transpiler_pipeline.py index ce8afee66d..94d2c4b539 100644 --- a/tests/test_transpiler_pipeline.py +++ b/tests/test_transpiler_pipeline.py @@ -237,6 +237,7 @@ def test_custom_passes_restict(gates, placer, routing): final_layout=final_layout, native_gates=NativeGates.default(), ) + assert transpiled_circ.wire_names == ["q1", "q2", "q3"] def test_custom_passes_multiple_placer(): diff --git a/tests/test_transpiler_router.py b/tests/test_transpiler_router.py index 2cf2364fe9..7a7ef17583 100644 --- a/tests/test_transpiler_router.py +++ b/tests/test_transpiler_router.py @@ -348,6 +348,7 @@ def test_restrict_qubits(router_algorithm): ) assert_connectivity(restricted_connectivity, routed_circ) assert_placement(routed_circ, final_layout, connectivity=restricted_connectivity) + assert routed_circ.wire_names == ["q0", "q2", "q3"] def test_star_error_multi_qubit():