-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not unroll gates in basis in add_control
#13475
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -29,6 +29,7 @@ | |||||||
from qiskit.quantum_info.states import Statevector | ||||||||
import qiskit.circuit.add_control as ac | ||||||||
from qiskit.transpiler.passes import UnrollCustomDefinitions, BasisTranslator | ||||||||
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager | ||||||||
from qiskit.converters.circuit_to_dag import circuit_to_dag | ||||||||
from qiskit.converters.dag_to_circuit import dag_to_circuit | ||||||||
from qiskit.quantum_info import Operator | ||||||||
|
@@ -1560,6 +1561,9 @@ def test_single_controlled_rotation_gates(self, gate, cgate): | |||||||
op_mat = (np.cos(0.5 * self.theta) * iden - 1j * np.sin(0.5 * self.theta) * zgen).data | ||||||||
else: | ||||||||
op_mat = Operator(gate).data | ||||||||
|
||||||||
print(self.ugu1) | ||||||||
print(cgate) | ||||||||
Comment on lines
+1564
to
+1566
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sneaky prints!
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. heh classic -- sorry about this one, I think I should add a pre-commit hook to check for these 😂 |
||||||||
ref_mat = Operator(cgate).data | ||||||||
cop_mat = _compute_control_matrix(op_mat, self.num_ctrl) | ||||||||
self.assertTrue(matrix_equal(cop_mat, ref_mat)) | ||||||||
|
@@ -1577,7 +1581,7 @@ def test_single_controlled_rotation_gates(self, gate, cgate): | |||||||
elif gate.name == "rz": | ||||||||
self.assertLessEqual(uqc.size(), 43, f"\n{uqc}") | ||||||||
else: | ||||||||
self.assertLessEqual(uqc.size(), 20, f"\n{uqc}") | ||||||||
self.assertLessEqual(uqc.size(), 23, f"\n{uqc}") | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does the size increase in this test? shouldn't the decomposition be more efficient? (I admit I haven't looked in depth so I might be missing something) |
||||||||
|
||||||||
def test_composite(self): | ||||||||
"""Test composite gate count.""" | ||||||||
|
@@ -1595,6 +1599,25 @@ def test_composite(self): | |||||||
self.log.info("%s gate count: %d", uqc.name, uqc.size()) | ||||||||
self.assertLessEqual(uqc.size(), 96, f"\n{uqc}") # this limit could be changed | ||||||||
|
||||||||
def test_mcrz_complexity(self): | ||||||||
"""Test MCRZ is decomposed using the efficient MC-SU(2) algorithm. | ||||||||
Regression test of #13427. | ||||||||
""" | ||||||||
basis_gates = ["sx", "x", "rz", "ecr"] | ||||||||
pm = generate_preset_pass_manager( | ||||||||
optimization_level=3, basis_gates=basis_gates, seed_transpiler=12345 | ||||||||
) | ||||||||
|
||||||||
num_qubits = 6 | ||||||||
angle = np.pi / 7 | ||||||||
qc = QuantumCircuit(num_qubits) | ||||||||
qc.append(RZGate(angle).control(num_qubits - 1), qc.qubits) | ||||||||
|
||||||||
isa_qc = pm.run(qc) | ||||||||
|
||||||||
self.assertLessEqual(isa_qc.count_ops().get("ecr", 0), 65) | ||||||||
|
||||||||
|
||||||||
@ddt | ||||||||
class TestControlledStandardGates(QiskitTestCase): | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this todo completed? if not, how could we check if this is necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not yet: I was wondering whether this was necessary because here we don't decompose the gate which we want to control and shouldn't be able to accumulate any global phase. I left it for the first version since the previous code had it, but I'll try removing and see if everything passes 🙂