Skip to content

Commit a5d550f

Browse files
Fully adapting solution for synthesizing base operation of an annotated gates from add_control, but with the twist that some other high-level gate names are also supported; fixing failing tests that are synthesized differently (and actually better) using the new flow
1 parent 3cd9a20 commit a5d550f

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

qiskit/transpiler/passes/synthesis/annotated_synthesis.py

+19-4
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,32 @@ def run(self, high_level_object, coupling_map=None, target=None, qubits=None, **
8181
# (including annotated operations) as the HighLevelSynthesis transpiler pass will
8282
# recursively re-synthesize this circuit, However, we should always guarantee that some
8383
# progress is made.
84-
device_ops = data.get_device_insts().copy()
85-
additional_ops = {"annotated", "mcx", "cz", "qft"}
86-
device_ops = device_ops.union(additional_ops)
84+
basis = {
85+
"p",
86+
"u",
87+
"x",
88+
"z",
89+
"y",
90+
"h",
91+
"sx",
92+
"sxdg",
93+
"rx",
94+
"ry",
95+
"rz",
96+
"cx",
97+
"cz",
98+
"annotated",
99+
"mcx",
100+
"qft",
101+
}
87102
base_synthesis_data = HighLevelSynthesisData(
88103
hls_config=data.get_hls_config(),
89104
hls_plugin_manager=data.get_hls_plugin_manager(),
90105
coupling_map=None,
91106
target=None,
92107
equivalence_library=data.get_equivalence_library(),
93108
hls_op_names=data.get_hls_op_names(),
94-
device_insts=device_ops,
109+
device_insts=basis,
95110
use_qubit_indices=data.get_use_qubit_indices(),
96111
min_qubits=0,
97112
unroll_definitions=data.get_unroll_definitions(),

test/python/transpiler/test_high_level_synthesis.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -792,9 +792,17 @@ def test_controlled_qft_adder(self):
792792
gate = HalfAdderGate(3).control(2, annotated=True)
793793
qc = QuantumCircuit(gate.num_qubits)
794794
qc.append(gate, qc.qubits)
795-
qct = HighLevelSynthesis(basis_gates=["cx", "u"], qubits_initially_zero=True)(qc)
795+
qct = HighLevelSynthesis(basis_gates=["cx", "u"], qubits_initially_zero=False)(qc)
796796
self.assertLessEqual(qct.count_ops()["cx"], 450)
797797

798+
def test_controlled_qft(self):
799+
"""Test controlled QFT-gate."""
800+
gate = QFTGate(3).control(2, annotated=True)
801+
qc = QuantumCircuit(gate.num_qubits)
802+
qc.append(gate, qc.qubits)
803+
qct = HighLevelSynthesis(basis_gates=["cx", "u"], qubits_initially_zero=False)(qc)
804+
self.assertLessEqual(qct.count_ops()["cx"], 198)
805+
798806

799807
class TestPMHSynthesisLinearFunctionPlugin(QiskitTestCase):
800808
"""Tests for the PMHSynthesisLinearFunction plugin for synthesizing linear functions."""
@@ -1267,7 +1275,7 @@ def test_multiple_controls(self):
12671275
circuit.append(lazy_gate1, [0, 1, 2, 3, 4])
12681276
transpiled_circuit = HighLevelSynthesis()(circuit)
12691277
expected_circuit = QuantumCircuit(5)
1270-
expected_circuit.append(SwapGate().control(2).control(1), [0, 1, 2, 3, 4])
1278+
expected_circuit.append(SwapGate().control(3), [0, 1, 2, 3, 4])
12711279
self.assertEqual(transpiled_circuit, expected_circuit)
12721280

12731281
def test_nested_controls(self):
@@ -1278,7 +1286,7 @@ def test_nested_controls(self):
12781286
circuit.append(lazy_gate2, [0, 1, 2, 3, 4])
12791287
transpiled_circuit = HighLevelSynthesis()(circuit)
12801288
expected_circuit = QuantumCircuit(5)
1281-
expected_circuit.append(SwapGate().control(2).control(1), [0, 1, 2, 3, 4])
1289+
expected_circuit.append(SwapGate().control(3), [0, 1, 2, 3, 4])
12821290
self.assertEqual(transpiled_circuit, expected_circuit)
12831291

12841292
def test_nested_controls_permutation(self):

0 commit comments

Comments
 (0)