Skip to content

Commit 1049ece

Browse files
mergify[bot]jakelishmanmtreinish
authored
Fix circuit-metadata propagation in SabreLayout (backport Qiskit#14186) (Qiskit#14190)
* Fix circuit-metadata propagation in `SabreLayout` (Qiskit#14186) This has been a bug since Qiskitgh-10712, but wasn't caught by the integration test in the test suite because the circuit has a perfect layout, so the layout stage was short-circuiting out after VF2. (cherry picked from commit 2504bde) # Conflicts: # qiskit/transpiler/passes/layout/sabre_layout.py * Fix merge conflicts * Adjust plugins used in testing for 1.4.x --------- Co-authored-by: Jake Lishman <[email protected]> Co-authored-by: Matthew Treinish <[email protected]>
1 parent 0db5b7a commit 1049ece

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

qiskit/transpiler/passes/layout/sabre_layout.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,9 @@ def run(self, dag):
305305
# the layout and routing together as part of resolving the Sabre result.
306306
physical_qubits = QuantumRegister(self.coupling_map.size(), "q")
307307
mapped_dag = DAGCircuit()
308+
mapped_dag.name = dag.name
309+
mapped_dag.metadata = dag.metadata
310+
mapped_dag.global_phase = dag.global_phase
308311
mapped_dag.add_qreg(physical_qubits)
309312
mapped_dag.add_clbits(dag.clbits)
310313
for creg in dag.cregs.values():
@@ -315,7 +318,7 @@ def run(self, dag):
315318
mapped_dag.add_captured_var(var)
316319
for var in dag.iter_declared_vars():
317320
mapped_dag.add_declared_var(var)
318-
mapped_dag.global_phase = dag.global_phase
321+
319322
self.property_set["original_qubit_indices"] = {
320323
bit: index for index, bit in enumerate(dag.qubits)
321324
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
fixes:
3+
- |
4+
:class:`.SabreLayout` will now correctly propagate a circuit's :attr:`~.DAGCircuit.name` and
5+
:attr:`~.DAGCircuit.metadata` fields when performing as a joint layout and routing pass.

test/python/transpiler/test_preset_passmanagers.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,8 +1576,15 @@ def test_parse_seed_transpiler_raises_value_error(self):
15761576
):
15771577
generate_preset_pass_manager(seed_transpiler=0.1)
15781578

1579-
@data(0, 1, 2, 3)
1580-
def test_preserves_circuit_metadata(self, optimization_level):
1579+
@combine(
1580+
optimization_level=[0, 1, 2, 3],
1581+
layout_method=["default", "dense", "sabre"],
1582+
routing_method=["sabre", "lookahead"],
1583+
translation_method=["translator", "synthesis"],
1584+
)
1585+
def test_preserves_circuit_metadata(
1586+
self, optimization_level, layout_method, routing_method, translation_method
1587+
):
15811588
"""Test that basic metadata is preserved."""
15821589
metadata = {"experiment_id": "1234", "execution_number": 4}
15831590
name = "my circuit"
@@ -1592,7 +1599,12 @@ def test_preserves_circuit_metadata(self, optimization_level):
15921599
target.add_instruction(CXGate(), {pair: None for pair in CouplingMap.from_line(num_qubits)})
15931600

15941601
pm = generate_preset_pass_manager(
1595-
optimization_level=optimization_level, target=target, seed_transpiler=42
1602+
optimization_level=optimization_level,
1603+
target=target,
1604+
seed_transpiler=42,
1605+
layout_method=layout_method,
1606+
routing_method=routing_method,
1607+
translation_method=translation_method,
15961608
)
15971609
res = pm.run(circuit)
15981610
self.assertEqual(res.metadata, metadata)

0 commit comments

Comments
 (0)