diff --git a/qiskit/circuit/instruction.py b/qiskit/circuit/instruction.py index 8676987be998..e5e52c1f3636 100644 --- a/qiskit/circuit/instruction.py +++ b/qiskit/circuit/instruction.py @@ -34,6 +34,8 @@ """ import copy from itertools import zip_longest +import warnings + import sympy import numpy @@ -52,11 +54,14 @@ class Instruction: def __init__(self, name, num_qubits, num_clbits, params): """Create a new instruction. + Args: name (str): instruction name num_qubits (int): instruction's qubit width num_clbits (int): instruction's clbit width - params (list[sympy.Basic|qasm.Node|int|float|complex|str|ndarray]): list of parameters + params (list[sympy.Basic||int|float|complex|str|ParameterExpressionndarray]): list of + parameters + Raises: QiskitError: when the register is not in the correct format. """ @@ -140,6 +145,15 @@ def params(self, parameters): self._params.append(single_param) # example: OpenQASM parsed instruction elif isinstance(single_param, node.Node): + warnings.warn('Using qasm ast node as a circuit.Instruction ' + 'parameter is deprecated as of the 0.10.0, and ' + 'will be removed no earlier than 3 months after ' + 'that release date. You should convert the qasm ' + 'node to a supported type int, float, complex, ' + 'str, circuit.ParameterExpression, or ndarray ' + 'before setting Instruction.parameters', + DeprecationWarning, stacklevel=3) + self._params.append(single_param.sym()) # example: u3(0.1, 0.2, 0.3) elif isinstance(single_param, (int, float)): @@ -344,7 +358,6 @@ def repeat(self, n): @property def control(self): """temporary classical control. Will be deprecated.""" - import warnings warnings.warn('The instruction attribute, "control", will be renamed ' 'to "condition". The "control" method will later be used ' 'to create quantum controlled gates') @@ -352,7 +365,6 @@ def control(self): @control.setter def control(self, value): - import warnings warnings.warn('The instruction attribute, "control", will be renamed ' 'to "condition". The "control" method will later be used ' 'to create quantum controlled gates') diff --git a/releasenotes/notes/deprecate-qasm-ast-node-params-3cc930ea2c677a96.yaml b/releasenotes/notes/deprecate-qasm-ast-node-params-3cc930ea2c677a96.yaml new file mode 100644 index 000000000000..627b8b906f2a --- /dev/null +++ b/releasenotes/notes/deprecate-qasm-ast-node-params-3cc930ea2c677a96.yaml @@ -0,0 +1,10 @@ +--- +deprecations: + - | + Support for setting ``qiskit.circuit.Instruction`` parameters with an object + of type ``qiskit.qasm.node.Node`` has been deprecated. ``Node`` objects that + were previously used as parameters should be converted to a supported type + prior to initializing a new ``Instruction`` object or calling the + ``Instruction.params`` setter. Supported types are ``int``, ``float``, + ``complex``, ``str``, ``qiskit.circuit.ParameterExpression``, or + ``numpy.ndarray``.