Skip to content
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

remove internal add_control #13177

Merged
merged 5 commits into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
2 changes: 1 addition & 1 deletion qiskit/circuit/gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def control(
"""
if not annotated: # captures both None and False
# pylint: disable=cyclic-import
from .add_control import add_control
from ._add_control import add_control

return add_control(self, num_ctrl_qubits, label, ctrl_state)

Expand Down
6 changes: 6 additions & 0 deletions releasenotes/notes/private-add_control-2367872c0f7136c4.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
upgrade_circuits:
- |
The internal function ``qiskit.circuit.add_control.add_control`` was removed, as it is not part of the
public API. It had fragile preconditions to uphold and was a common source of bugs. Uses of ``add_control(SomeGate(...), ...)``
should change to ``SomeGate(...).control(...)`` using :meth:`.Gate.control` instead, which is far safer.
9 changes: 4 additions & 5 deletions test/python/circuit/test_controlled_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
from qiskit.quantum_info.operators.predicates import matrix_equal, is_unitary_matrix
from qiskit.quantum_info.random import random_unitary
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
Expand Down Expand Up @@ -1584,10 +1583,10 @@ class TestSingleControlledRotationGates(QiskitTestCase):
gry = ry.RYGate(theta)
grz = rz.RZGate(theta)

ugu1 = ac._unroll_gate(gu1, ["p", "u", "cx"])
ugrx = ac._unroll_gate(grx, ["p", "u", "cx"])
ugry = ac._unroll_gate(gry, ["p", "u", "cx"])
ugrz = ac._unroll_gate(grz, ["p", "u", "cx"])
ugu1 = u1.U1Gate(theta).definition
ugrx = rx.RXGate(theta).definition
ugry = ry.RYGate(theta).definition
ugrz = rz.RZGate(theta).definition
ugrz.params = grz.params

cgu1 = ugu1.control(num_ctrl)
Expand Down