Skip to content

Commit

Permalink
Remove deprecated functionality from extensions, qasm, and dagcircuit…
Browse files Browse the repository at this point in the history
… modules (#7208)

* Remove deprecated functionality

This commit goes through qiskit.extensions, qiskit.qasm, qiskit.util,
and qiskit.dagcircuit modules and cleans up deprecated functionality
that has gone through a full deprecation cycle and no longer needs to
be supported.

* Restore qiskit/util.py

The qiskit/util.py will need to be deprecated a bit longer it's still in
active use by downstream packages and it was right on the boundary of
being deprecated long enough anyway so being a bit more conservative on
this is probably for the best anyway.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
mtreinish and mergify[bot] authored Nov 5, 2021
1 parent 5196d8e commit 6d88dd0
Show file tree
Hide file tree
Showing 32 changed files with 103 additions and 425 deletions.
74 changes: 2 additions & 72 deletions qiskit/dagcircuit/dagcircuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from collections import OrderedDict, defaultdict
import copy
import itertools
import warnings
import math

import numpy as np
Expand Down Expand Up @@ -628,36 +627,7 @@ def _map_condition(wire_map, condition, target_cregs):
new_condition = (new_creg, new_cond_val)
return new_condition

def extend_back(self, dag, edge_map=None):
"""DEPRECATED: Add `dag` at the end of `self`, using `edge_map`."""
warnings.warn(
"dag.extend_back is deprecated, please use dag.compose.",
DeprecationWarning,
stacklevel=2,
)
edge_map = edge_map or {}
for qreg in dag.qregs.values():
if qreg.name not in self.qregs:
self.add_qreg(QuantumRegister(qreg.size, qreg.name))
edge_map.update([(qbit, qbit) for qbit in qreg if qbit not in edge_map])

for creg in dag.cregs.values():
if creg.name not in self.cregs:
self.add_creg(ClassicalRegister(creg.size, creg.name))
edge_map.update([(cbit, cbit) for cbit in creg if cbit not in edge_map])

self.compose_back(dag, edge_map)

def compose_back(self, input_circuit, edge_map=None):
"""DEPRECATED: use DAGCircuit.compose() instead."""
warnings.warn(
"dag.compose_back is deprecated, please use dag.compose.",
DeprecationWarning,
stacklevel=2,
)
self.compose(input_circuit, edge_map)

def compose(self, other, edge_map=None, qubits=None, clbits=None, front=False, inplace=True):
def compose(self, other, qubits=None, clbits=None, front=False, inplace=True):
"""Compose the ``other`` circuit onto the output of this circuit.
A subset of input wires of ``other`` are mapped
Expand All @@ -667,9 +637,6 @@ def compose(self, other, edge_map=None, qubits=None, clbits=None, front=False, i
Args:
other (DAGCircuit): circuit to compose with self
edge_map (dict): DEPRECATED - a {Bit: Bit} map from input wires of other
to output wires of self (i.e. rhs->lhs).
The key, value pairs can be either Qubit or Clbit mappings.
qubits (list[Qubit|int]): qubits of self to compose onto.
clbits (list[Clbit|int]): clbits of self to compose onto.
front (bool): If True, front composition will be performed (not implemented yet)
Expand All @@ -689,15 +656,6 @@ def compose(self, other, edge_map=None, qubits=None, clbits=None, front=False, i
"Trying to compose with another DAGCircuit which has more 'in' edges."
)

if edge_map is not None:
warnings.warn(
"edge_map arg as a dictionary is deprecated. "
"Use qubits and clbits args to specify a list of "
"self edges to compose onto.",
DeprecationWarning,
stacklevel=2,
)

# number of qubits and clbits must match number in circuit or None
identity_qubit_map = dict(zip(other.qubits, self.qubits))
identity_clbit_map = dict(zip(other.clbits, self.clbits))
Expand Down Expand Up @@ -725,7 +683,7 @@ def compose(self, other, edge_map=None, qubits=None, clbits=None, front=False, i
other.clbits[i]: (self.clbits[c] if isinstance(c, int) else c)
for i, c in enumerate(clbits)
}
edge_map = edge_map or {**qubit_map, **clbit_map} or None
edge_map = {**qubit_map, **clbit_map} or None

# if no edge_map, try to do a 1-1 mapping in order
if edge_map is None:
Expand Down Expand Up @@ -1359,34 +1317,6 @@ def named_nodes(self, *names):
named_nodes.append(node)
return named_nodes

def twoQ_gates(self):
"""Get list of 2-qubit gates. Ignore snapshot, barriers, and the like."""
warnings.warn(
"deprecated function, use dag.two_qubit_ops(). "
"filter output by isinstance(op, Gate) to only get unitary Gates.",
DeprecationWarning,
stacklevel=2,
)
two_q_gates = []
for node in self.gate_nodes():
if len(node.qargs) == 2:
two_q_gates.append(node)
return two_q_gates

def threeQ_or_more_gates(self):
"""Get list of 3-or-more-qubit gates: (id, data)."""
warnings.warn(
"deprecated function, use dag.multi_qubit_ops(). "
"filter output by isinstance(op, Gate) to only get unitary Gates.",
DeprecationWarning,
stacklevel=2,
)
three_q_gates = []
for node in self.gate_nodes():
if len(node.qargs) >= 3:
three_q_gates.append(node)
return three_q_gates

def two_qubit_ops(self):
"""Get list of 2 qubit operations. Ignore directives like snapshot and barrier."""
ops = []
Expand Down
18 changes: 9 additions & 9 deletions qiskit/extensions/quantum_initializer/squ.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from qiskit.circuit.exceptions import CircuitError
from qiskit.quantum_info.operators.predicates import is_unitary_matrix
from qiskit.exceptions import QiskitError
from qiskit.utils.deprecation import deprecate_arguments

_EPS = 1e-10 # global variable used to chop very small numbers to zero

Expand All @@ -42,9 +41,7 @@ class SingleQubitUnitary(Gate):
gate d with u = d.dot(u').
"""

# pylint: disable=unused-argument
@deprecate_arguments({"u": "unitary_matrix"})
def __init__(self, unitary_matrix, mode="ZYZ", up_to_diagonal=False, u=None):
def __init__(self, unitary_matrix, mode="ZYZ", up_to_diagonal=False):
"""Create a new single qubit gate based on the unitary ``u``."""
if mode not in ["ZYZ"]:
raise QiskitError("The decomposition mode is not known.")
Expand Down Expand Up @@ -162,9 +159,13 @@ def validate_parameter(self, parameter):
raise CircuitError(f"invalid param type {type(parameter)} in gate {self.name}")


# pylint: disable=unused-argument, invalid-name, missing-type-doc, missing-param-doc
@deprecate_arguments({"u": "unitary"})
def squ(self, unitary_matrix, qubit, mode="ZYZ", up_to_diagonal=False, *, u=None):
def squ(
self,
unitary_matrix,
qubit,
mode="ZYZ",
up_to_diagonal=False,
):
"""Decompose an arbitrary 2*2 unitary into three rotation gates.
Note that the decomposition is up to a global phase shift.
Expand All @@ -173,13 +174,12 @@ def squ(self, unitary_matrix, qubit, mode="ZYZ", up_to_diagonal=False, *, u=None
Args:
unitary_matrix (ndarray): 2*2 unitary (given as a (complex) ndarray).
qubit (QuantumRegister | Qubit): The qubit which the gate is acting on.
qubit (QuantumRegister or Qubit): The qubit which the gate is acting on.
mode (string): determines the used decomposition by providing the rotation axes.
The allowed modes are: "ZYZ" (default)
up_to_diagonal (bool): if set to True, the single-qubit unitary is decomposed up to
a diagonal matrix, i.e. a unitary u' is implemented such that there exists a 2*2
diagonal gate d with u = d.dot(u')
u (ndarray): Deprecated, use ``unitary_matrix`` instead.
Returns:
InstructionSet: The single-qubit unitary instruction attached to the circuit.
Expand Down
10 changes: 1 addition & 9 deletions qiskit/qasm/node/barrier.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

"""Node for an OPENQASM barrier statement."""

import warnings

from .node import Node


Expand All @@ -27,12 +25,6 @@ def __init__(self, children):
"""Create the barrier node."""
super().__init__("barrier", children, None)

def qasm(self, prec=None):
def qasm(self):
"""Return the corresponding OPENQASM string."""
if prec is not None:
warnings.warn(
"Parameter 'Barrier.qasm(..., prec)' is no longer used and is being deprecated.",
DeprecationWarning,
2,
)
return "barrier " + self.children[0].qasm() + ";"
42 changes: 3 additions & 39 deletions qiskit/qasm/node/binaryop.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

"""Node for an OPENQASM binary operation expression."""

import warnings

from qiskit.exceptions import MissingOptionalLibraryError
from .node import Node

Expand All @@ -30,42 +28,14 @@ def __init__(self, children):
"""Create the binaryop node."""
super().__init__("binop", children, None)

def qasm(self, prec=None, nested_scope=None):
def qasm(self):
"""Return the corresponding OPENQASM string."""
if prec is not None:
warnings.warn(
"Parameter 'BinaryOp.qasm(..., prec)' is no longer "
"used and is being deprecated.",
DeprecationWarning,
2,
)
if nested_scope is not None:
warnings.warn(
"Parameter 'BinaryOp.qasm(..., nested_scope)' is no longer "
"used and is being deprecated.",
DeprecationWarning,
2,
)
return (
"(" + self.children[1].qasm() + self.children[0].value + self.children[2].qasm() + ")"
)

def latex(self, prec=None, nested_scope=None):
def latex(self):
"""Return the corresponding math mode latex string."""
if prec is not None:
warnings.warn(
"Parameter 'BinaryOp.latex(..., prec)' is no longer used "
"and is being deprecated.",
DeprecationWarning,
2,
)
if nested_scope is not None:
warnings.warn(
"Parameter 'BinaryOp.latex(..., nested_scope)' is no longer used "
"and is being deprecated.",
DeprecationWarning,
2,
)
try:
from pylatexenc.latexencode import utf8tolatex
except ImportError as ex:
Expand All @@ -74,14 +44,8 @@ def latex(self, prec=None, nested_scope=None):
) from ex
return utf8tolatex(self.sym())

def real(self, nested_scope=None):
def real(self):
"""Return the correspond floating point number."""
if nested_scope is not None:
warnings.warn(
"Parameter 'BinaryOp.real(..., nested_scope)' is no longer used and is"
" being deprecated.",
DeprecationWarning,
)
operation = self.children[0].operation()
lhs = self.children[1].real()
rhs = self.children[2].real()
Expand Down
10 changes: 1 addition & 9 deletions qiskit/qasm/node/binaryoperator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"""Node for an OPENQASM binary operator."""

import operator
import warnings

from .node import Node
from .nodeexception import NodeException
Expand Down Expand Up @@ -48,13 +47,6 @@ def operation(self):
except KeyError as ex:
raise NodeException(f"internal error: undefined operator '{self.value}'") from ex

def qasm(self, prec=None):
def qasm(self):
"""Return the QASM representation."""
if prec is not None:
warnings.warn(
"Parameter 'BinaryOperator.qasm(..., prec)' is no longer used and is "
"being deprecated.",
DeprecationWarning,
2,
)
return self.value
10 changes: 1 addition & 9 deletions qiskit/qasm/node/cnot.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

"""Node for an OPENQASM CNOT statement."""

import warnings

from .node import Node


Expand All @@ -28,12 +26,6 @@ def __init__(self, children):
"""Create the cnot node."""
super().__init__("cnot", children, None)

def qasm(self, prec=None):
def qasm(self):
"""Return the corresponding OPENQASM string."""
if prec is not None:
warnings.warn(
"Parameter 'Cnot.qasm(..., prec)' is no longer used and is being deprecated.",
DeprecationWarning,
2,
)
return "CX " + self.children[0].qasm() + "," + self.children[1].qasm() + ";"
10 changes: 1 addition & 9 deletions qiskit/qasm/node/creg.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
# that they have been altered from the originals.

"""Node for an OPENQASM creg statement."""
import warnings

from .node import Node


Expand Down Expand Up @@ -42,12 +40,6 @@ def to_string(self, indent):
print(ind, "creg")
self.children[0].to_string(indent + 3)

def qasm(self, prec=None):
def qasm(self):
"""Return the corresponding OPENQASM string."""
if prec is not None:
warnings.warn(
"Parameter 'Creg.qasm(..., prec)' is no longer used and is being deprecated.",
DeprecationWarning,
2,
)
return "creg " + self.id.qasm() + ";"
11 changes: 1 addition & 10 deletions qiskit/qasm/node/customunitary.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
# that they have been altered from the originals.

"""Node for an OPENQASM custom gate statement."""
import warnings

from .node import Node


Expand Down Expand Up @@ -42,15 +40,8 @@ def __init__(self, children):
self.arguments = None
self.bitlist = children[1]

def qasm(self, prec=None):
def qasm(self):
"""Return the corresponding OPENQASM string."""
if prec is not None:
warnings.warn(
"Parameter 'CustomUnitary.qasm(..., prec)' is no longer used and is "
"being deprecated.",
DeprecationWarning,
2,
)
string = self.name
if self.arguments is not None:
string += "(" + self.arguments.qasm() + ")"
Expand Down
11 changes: 1 addition & 10 deletions qiskit/qasm/node/expressionlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
# that they have been altered from the originals.

"""Node for an OPENQASM expression list."""
import warnings

from .node import Node


Expand All @@ -30,13 +28,6 @@ def size(self):
"""Return the number of expressions."""
return len(self.children)

def qasm(self, prec=None):
def qasm(self):
"""Return the corresponding OPENQASM string."""
if prec is not None:
warnings.warn(
"Parameter 'ExpressionList.qasm(..., prec)' is no longer used and is "
"being deprecated.",
DeprecationWarning,
2,
)
return ",".join([self.children[j].qasm() for j in range(self.size())])
Loading

0 comments on commit 6d88dd0

Please sign in to comment.