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

Deprecate extensions on stable/0.46 #11498

Merged
merged 7 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
21 changes: 7 additions & 14 deletions qiskit/circuit/quantumcircuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -4283,9 +4283,8 @@ def unitary(
return self.append(gate, qubits, [])

@deprecate_func(
since="0.45.0",
since="0.46.0",
additional_msg="Instead, compose the circuit with a qiskit.circuit.library.Diagonal circuit.",
pending=True,
)
def diagonal(self, diag, qubit):
"""Attach a diagonal gate to a circuit.
Expand Down Expand Up @@ -4332,9 +4331,8 @@ def diagonal(self, diag, qubit):
return self.append(DiagonalGate(diag), qubit)

@deprecate_func(
since="0.45.0",
since="0.46.0",
additional_msg="Instead, append a qiskit.circuit.library.Isometry to the circuit.",
pending=True,
)
def iso(
self,
Expand Down Expand Up @@ -4402,9 +4400,8 @@ def iso(
)

@deprecate_func(
since="0.45.0",
since="0.46.0",
additional_msg="Instead, append a qiskit.circuit.library.HamiltonianGate to the circuit.",
pending=True,
)
def hamiltonian(self, operator, time, qubits, label=None):
"""Apply hamiltonian evolution to qubits.
Expand Down Expand Up @@ -4432,9 +4429,8 @@ def hamiltonian(self, operator, time, qubits, label=None):
return self.append(HamiltonianGate(data=operator, time=time, label=label), qubits, [])

@deprecate_func(
since="0.45.0",
since="0.46.0",
additional_msg="Instead, append a qiskit.circuit.library.UCGate to the circuit.",
pending=True,
)
def uc(self, gate_list, q_controls, q_target, up_to_diagonal=False):
"""Attach a uniformly controlled gates (also called multiplexed gates) to a circuit.
Expand Down Expand Up @@ -4500,9 +4496,8 @@ def uc(self, gate_list, q_controls, q_target, up_to_diagonal=False):
return self.append(UCGate(gate_list, up_to_diagonal), [q_target] + q_controls)

@deprecate_func(
since="0.45.0",
since="0.46.0",
additional_msg="Instead, append a qiskit.circuit.library.UCRXGate to the circuit.",
pending=True,
)
def ucrx(
self,
Expand Down Expand Up @@ -4561,9 +4556,8 @@ def ucrx(
return self.append(UCRXGate(angle_list), [q_target] + q_controls, [])

@deprecate_func(
since="0.45.0",
since="0.46.0",
additional_msg="Instead, append a qiskit.circuit.library.UCRYGate to the circuit.",
pending=True,
)
def ucry(
self,
Expand Down Expand Up @@ -4622,9 +4616,8 @@ def ucry(
return self.append(UCRYGate(angle_list), [q_target] + q_controls, [])

@deprecate_func(
since="0.45.0",
since="0.46.0",
additional_msg="Instead, append a qiskit.circuit.library.UCRZGate to the circuit.",
pending=True,
)
def ucrz(
self,
Expand Down
2 changes: 1 addition & 1 deletion qiskit/circuit/random/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def random_circuit(
"""Generate random circuit of arbitrary size and form.

This function will generate a random circuit by randomly selecting gates
from the set of standard gates in :mod:`qiskit.extensions`. For example:
from the set of standard gates in :mod:`qiskit.circuit.library.standard_gates`. For example:

.. plot::
:include-source:
Expand Down
7 changes: 3 additions & 4 deletions qiskit/extensions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,9 @@
)
from .simulator import Snapshot


warnings.warn(
"The qiskit.extensions module is pending deprecation since Qiskit 0.45.0. It will be deprecated "
"in a following release, no sooner than 3 months after the 0.45.0 release.",
"The qiskit.extensions module is deprecated since Qiskit 0.46.0. It will be deprecated "
"in a following release, no sooner than 3 months after the 0.46.0 release.",
stacklevel=2,
category=PendingDeprecationWarning,
category=DeprecationWarning,
)
4 changes: 1 addition & 3 deletions qiskit/visualization/circuit/matplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
)
from qiskit.circuit.controlflow import condition_resources
from qiskit.circuit.classical import expr
from qiskit.circuit.library import Initialize
from qiskit.circuit.library.standard_gates import (
SwapGate,
RZZGate,
Expand All @@ -47,7 +48,6 @@
from qiskit.qasm3.exporter import QASM3Builder
from qiskit.qasm3.printer import BasicPrinter

from qiskit.extensions import Initialize
from qiskit.circuit.tools.pi_check import pi_check
from qiskit.utils import optionals as _optionals

Expand Down Expand Up @@ -627,7 +627,6 @@ def _set_bit_reg_info(self, wire_map, qubits_dict, clbits_dict, glob_data):
idx = 0
pos = y_off = -len(self._qubits) + 1
for ii, wire in enumerate(wire_map):

# if it's a creg, register is the key and just load the index
if isinstance(wire, ClassicalRegister):
# If wire came from ControlFlowOp and not in clbits, don't draw it
Expand Down Expand Up @@ -1168,7 +1167,6 @@ def _condition(self, node, node_data, wire_map, outer_circuit, cond_xy, glob_dat
cond_pos = []

if isinstance(condition, expr.Expr):

# If fixing this, please update the docstrings of `QuantumCircuit.draw` and
# `visualization.circuit_drawer` to remove warnings.

Expand Down
27 changes: 27 additions & 0 deletions releasenotes/notes/deprecate-extensions-046-2b98dce6fdfadc72.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
deprecations:
- |
Deprecated the :mod:`qiskit.extensions` module, which has been pending deprecation since the 0.45 release.
Most objects have been moved to :mod:`qiskit.circuit.library`, including:

* :class:`~.library.DiagonalGate`,
* :class:`~.library.HamiltonianGateGate`,
* :class:`~.library.Initialize`,
* :class:`~.library.Isometry`,
* :class:`~.library.generalized_gates.mcg_up_diag.MCGupDiag`,
* :class:`~.library.UCGate`,
* :class:`~.library.UCPauliRotGate`,
* :class:`~.library.UCRXGate`,
* :class:`~.library.UCRYGate`,
* :class:`~.library.UCRZGate`,
* :class:`~.library.UnitaryGate`.

With the deprecation of the objects, the following circuit methods have also been deprecated:

* ``QuantumCircuit.diagonal``,
* ``QuantumCircuit.hamiltonian``,
* ``QuantumCircuit.isometry`` and ``QuantumCircuit.iso``,
* ``QuantumCircuit.uc``,
* ``QuantumCircuit.ucrx``,
* ``QuantumCircuit.ucry``,
* ``QuantumCircuit.ucrz``.
4 changes: 2 additions & 2 deletions test/python/circuit/test_circuit_load_from_qpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1458,14 +1458,14 @@ def test_incomplete_owned_bits(self):
def test_diagonal_gate(self):
"""Test that a `DiagonalGate` successfully roundtrips."""
qc = QuantumCircuit(2)
with self.assertWarns(PendingDeprecationWarning):
with self.assertWarns(DeprecationWarning):
qc.diagonal([1, -1, -1, 1], [0, 1])

with io.BytesIO() as fptr:
dump(qc, fptr)
fptr.seek(0)
new_circuit = load(fptr)[0]
# DiagonalGate (and a bunch of the qiskit.extensions gates) have non-deterministic
# DiagonalGate (and some of the qiskit.circuit.library gates) have non-deterministic
# definitions with regard to internal instruction names, so cannot be directly compared for
# equality.
self.assertIs(type(qc.data[0].operation), type(new_circuit.data[0].operation))
Expand Down
8 changes: 3 additions & 5 deletions test/python/circuit/test_controlled_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ def test_open_control_composite_unrolling(self):

@data(*ControlledGate.__subclasses__())
def test_standard_base_gate_setting(self, gate_class):
"""Test all gates in standard extensions which are of type ControlledGate
"""Test all standard gates which are of type ControlledGate
and have a base gate setting.
"""
if gate_class in {SingletonControlledGate, _SingletonControlledGateOverrides}:
Expand Down Expand Up @@ -1044,9 +1044,7 @@ def test_standard_base_gate_setting(self, gate_class):
ctrl_state=[None, 0, 1],
)
def test_all_inverses(self, gate, num_ctrl_qubits, ctrl_state):
"""Test all gates in standard extensions except those that cannot be controlled
or are being deprecated.
"""
"""Test all standard gates except those that cannot be controlled."""
if not (issubclass(gate, ControlledGate) or issubclass(gate, allGates.IGate)):
# only verify basic gates right now, as already controlled ones
# will generate differing definitions
Expand Down Expand Up @@ -1146,7 +1144,7 @@ def test_open_controlled_gate_raises(self):

def test_base_gate_params_reference(self):
"""
Test all gates in standard extensions which are of type ControlledGate and have a base gate
Test all standard gates which are of type ControlledGate and have a base gate
setting have params which reference the one in their base gate.
"""
num_ctrl_qubits = 1
Expand Down
6 changes: 3 additions & 3 deletions test/python/circuit/test_diagonal_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_diag_gate(self):
num_qubits = int(np.log2(len(diag)))
q = QuantumRegister(num_qubits)
qc = QuantumCircuit(q)
with self.assertWarns(PendingDeprecationWarning):
with self.assertWarns(DeprecationWarning):
qc.diagonal(diag, q[0:num_qubits])
# Decompose the gate
qc = transpile(qc, basis_gates=["u1", "u3", "u2", "cx", "id"], optimization_level=0)
Expand All @@ -62,15 +62,15 @@ def test_mod1_entries(self):
from qiskit.quantum_info.operators.predicates import ATOL_DEFAULT, RTOL_DEFAULT

with self.assertRaises(QiskitError):
with self.assertWarns(PendingDeprecationWarning):
with self.assertWarns(DeprecationWarning):
DiagonalGate([1, 1 - 2 * ATOL_DEFAULT - RTOL_DEFAULT])

def test_npcomplex_params_conversion(self):
"""Verify diagonal gate converts numpy.complex to complex."""
# ref: https://github.com/Qiskit/qiskit-aer/issues/696
diag = np.array([1 + 0j, 1 + 0j])
qc = QuantumCircuit(1)
with self.assertWarns(PendingDeprecationWarning):
with self.assertWarns(DeprecationWarning):
qc.diagonal(diag.tolist(), [0])

params = qc.data[0].operation.params
Expand Down
4 changes: 2 additions & 2 deletions test/python/circuit/test_isometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_isometry(self, iso):
q = QuantumRegister(num_q_output)
qc = QuantumCircuit(q)

with self.assertWarns(PendingDeprecationWarning):
with self.assertWarns(DeprecationWarning):
qc.iso(iso, q[:num_q_input], q[num_q_input:])

# Verify the circuit can be decomposed
Expand Down Expand Up @@ -97,7 +97,7 @@ def test_isometry_tolerance(self, iso):
qc = QuantumCircuit(q)

# Compute isometry with custom tolerance
with self.assertWarns(PendingDeprecationWarning):
with self.assertWarns(DeprecationWarning):
qc.isometry(iso, q[:num_q_input], q[num_q_input:], epsilon=1e-3)

# Verify the circuit can be decomposed
Expand Down
4 changes: 2 additions & 2 deletions test/python/circuit/test_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_pauli_as_operation(self):

def test_isometry_as_operation(self):
"""Test that we can instantiate an object of class
:class:`~qiskit.extensions.quantum_initializer.Isometry` and that
:class:`~qiskit.circuit.library.quantum_initializer.Isometry` and that
it has the expected name, num_qubits and num_clbits.
"""
op = Isometry(np.eye(4, 4), 3, 2)
Expand All @@ -113,7 +113,7 @@ def test_isometry_as_operation(self):

def test_initialize_as_operation(self):
"""Test that we can instantiate an object of class
:class:`~qiskit.extensions.quantum_initializer.Initialize` and that
:class:`~qiskit.circuit.library.quantum_initializer.Initialize` and that
it has the expected name, num_qubits and num_clbits.
"""
desired_vector = [0.5, 0.5, 0.5, 0.5]
Expand Down
2 changes: 1 addition & 1 deletion test/python/circuit/test_uc.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def test_ucg(self, squs, up_to_diagonal):
q = QuantumRegister(num_con + 1)
qc = QuantumCircuit(q)

with self.assertWarns(PendingDeprecationWarning):
with self.assertWarns(DeprecationWarning):
# TODO: change to directly appending UCGate once deprecation period of the method is over
qc.uc(squs, q[1:], q[0], up_to_diagonal=up_to_diagonal)

Expand Down
2 changes: 1 addition & 1 deletion test/python/circuit/test_ucx_y_z.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_ucy(self, use_method):
q = QuantumRegister(num_contr + 1)
qc = QuantumCircuit(q)
if use_method:
with self.assertWarns(PendingDeprecationWarning):
with self.assertWarns(DeprecationWarning):
getattr(qc, methods[rot_axis])(angles, q[1 : num_contr + 1], q[0])
else:
gate = gates[rot_axis](angles)
Expand Down
Loading