From 03dbb2399caffbbcb835479a584be6adf5f4df89 Mon Sep 17 00:00:00 2001 From: changsookim <> Date: Fri, 15 Nov 2024 15:46:04 +0400 Subject: [PATCH] fix: copy wire_names --- src/qibo/models/circuit.py | 1 + src/qibo/transpiler/optimizer.py | 7 +++++-- src/qibo/transpiler/placer.py | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/qibo/models/circuit.py b/src/qibo/models/circuit.py index 4e65259719..3be87e5bf1 100644 --- a/src/qibo/models/circuit.py +++ b/src/qibo/models/circuit.py @@ -325,6 +325,7 @@ def wire_names(self, wire_names: Union[list, dict]): ] else: self._wire_names = [f"q{i}" for i in range(self.nqubits)] + self.init_kwargs["wire_names"] = self._wire_names @property def repeated_execution(self): diff --git a/src/qibo/transpiler/optimizer.py b/src/qibo/transpiler/optimizer.py index 7008957627..f8a3b10ada 100644 --- a/src/qibo/transpiler/optimizer.py +++ b/src/qibo/transpiler/optimizer.py @@ -27,7 +27,10 @@ def __call__(self, circuit: Circuit) -> Circuit: ) if logical_qubits == physical_qubits: return circuit - new_circuit = Circuit(physical_qubits) + new_wire_names = circuit.wire_names + list( + self.connectivity.nodes - circuit.wire_names + ) + new_circuit = Circuit(nqubits=physical_qubits, wire_names=new_wire_names) for gate in circuit.queue: new_circuit.add(gate) return new_circuit @@ -48,7 +51,7 @@ def __init__(self, max_qubits: int = 1): def __call__(self, circuit: Circuit): fused_circuit = circuit.fuse(max_qubits=self.max_qubits) - new = circuit.__class__(circuit.nqubits) + new = Circuit(**circuit.init_kwargs) for fgate in fused_circuit.queue: if isinstance(fgate, gates.FusedGate): new.add(gates.Unitary(fgate.matrix(), *fgate.qubits)) diff --git a/src/qibo/transpiler/placer.py b/src/qibo/transpiler/placer.py index 7944ea81f2..b00541192f 100644 --- a/src/qibo/transpiler/placer.py +++ b/src/qibo/transpiler/placer.py @@ -461,7 +461,7 @@ def _assemble_circuit(self, circuit: Circuit): gates_qubits_pairs.reverse() assembled_gates_qubits_pairs += gates_qubits_pairs[0:remainder] - new_circuit = Circuit(circuit.nqubits) + new_circuit = Circuit(**circuit.init_kwargs) for qubits in assembled_gates_qubits_pairs: # As only the connectivity is important here we can replace everything with CZ gates new_circuit.add(gates.CZ(qubits[0], qubits[1]))