Skip to content

Commit 1107f8c

Browse files
Bug fix in HighLevelSynthesis fast-return mechanism (#14349) (#14358)
* HLS early termination bug fix * adding test * release notes: remove extra space (cherry picked from commit de41d1a) Co-authored-by: Alexander Ivrii <[email protected]>
1 parent 026cec1 commit 1107f8c

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

crates/accelerate/src/high_level_synthesis.rs

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

338338
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
@@ -732,6 +732,21 @@ def test_track_global_phase(self):
732732
expected_block.cx(0, 1)
733733
self.assertEqual(transpiled_block, expected_block)
734734

735+
def test_control_flow(self):
736+
"""Test that the pass recurses into control-flow ops."""
737+
clifford_circuit = QuantumCircuit(3)
738+
clifford_circuit.cx(1, 0)
739+
clifford_circuit.cz(0, 2)
740+
cliff = Clifford(clifford_circuit)
741+
742+
qc = QuantumCircuit(5, 5)
743+
with qc.for_loop(range(3)):
744+
qc.append(cliff, [0, 1, 4])
745+
746+
transpiled = HighLevelSynthesis(basis_gates=["cx", "u", "for_loop"])(qc)
747+
transpiled_block = transpiled[0].operation.blocks[0]
748+
self.assertNotIn("clifford", transpiled_block.count_ops())
749+
735750

736751
class TestPMHSynthesisLinearFunctionPlugin(QiskitTestCase):
737752
"""Tests for the PMHSynthesisLinearFunction plugin for synthesizing linear functions."""

0 commit comments

Comments
 (0)