Skip to content

Commit de41d1a

Browse files
Bug fix in HighLevelSynthesis fast-return mechanism (#14349)
* HLS early termination bug fix * adding test * release notes: remove extra space
1 parent 844de63 commit de41d1a

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

crates/transpiler/src/passes/high_level_synthesis.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ fn all_instructions_supported(
333333
data: &Bound<HighLevelSynthesisData>,
334334
dag: &DAGCircuit,
335335
) -> PyResult<bool> {
336-
let ops = dag.count_ops(py, false)?;
336+
let ops = dag.count_ops(py, true)?;
337337
let mut op_keys = ops.keys();
338338

339339
let borrowed_data = data.borrow();
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
fixes:
3+
- |
4+
Fixed a problem in :class:`.HighLevelSynthesis` transpiler pass that caused
5+
it to erroneously terminate early on certain circuits with control flow
6+
operations.
7+
Fixed `#14338 <https://github.com/Qiskit/qiskit-terra/issues/14338>`__

test/python/transpiler/test_high_level_synthesis.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,21 @@ def test_track_global_phase(self):
742742
expected_block.cx(0, 1)
743743
self.assertEqual(transpiled_block, expected_block)
744744

745+
def test_control_flow(self):
746+
"""Test that the pass recurses into control-flow ops."""
747+
clifford_circuit = QuantumCircuit(3)
748+
clifford_circuit.cx(1, 0)
749+
clifford_circuit.cz(0, 2)
750+
cliff = Clifford(clifford_circuit)
751+
752+
qc = QuantumCircuit(5, 5)
753+
with qc.for_loop(range(3)):
754+
qc.append(cliff, [0, 1, 4])
755+
756+
transpiled = HighLevelSynthesis(basis_gates=["cx", "u", "for_loop"])(qc)
757+
transpiled_block = transpiled[0].operation.blocks[0]
758+
self.assertNotIn("clifford", transpiled_block.count_ops())
759+
745760

746761
class TestHighLevelSynthesisQuality(QiskitTestCase):
747762
"""Test the "quality" of circuits produced by HighLevelSynthesis."""

0 commit comments

Comments
 (0)