From 49d325f21fe6cdf20d8a53e64b29c682b430a707 Mon Sep 17 00:00:00 2001 From: Matthew Silverman Date: Wed, 5 Jul 2023 18:17:19 -0400 Subject: [PATCH] remove do_queue everywhere (#4317) * remove do_queue everywhere * do not queue adjoint tape * override adjoint in QuantumTape so it queues * fix bad merge conflict --- doc/development/adding_operators.rst | 9 +- doc/development/deprecations.rst | 14 +- doc/releases/changelog-dev.md | 4 + pennylane/operation.py | 43 +--- pennylane/ops/channel.py | 74 ++----- pennylane/ops/cv.py | 192 +++++------------- pennylane/ops/identity.py | 7 +- pennylane/ops/op_math/adjoint.py | 6 +- pennylane/ops/op_math/composite.py | 20 +- pennylane/ops/op_math/controlled.py | 16 +- pennylane/ops/op_math/controlled_ops.py | 15 +- pennylane/ops/op_math/evolution.py | 9 +- pennylane/ops/op_math/exp.py | 7 +- pennylane/ops/op_math/pow.py | 28 +-- pennylane/ops/op_math/prod.py | 18 +- pennylane/ops/op_math/sprod.py | 22 +- pennylane/ops/op_math/sum.py | 16 +- pennylane/ops/op_math/symbolicop.py | 25 +-- pennylane/ops/qubit/arithmetic_ops.py | 11 +- pennylane/ops/qubit/hamiltonian.py | 3 +- pennylane/ops/qubit/matrix_ops.py | 16 +- pennylane/ops/qubit/non_parametric_ops.py | 35 ++-- pennylane/ops/qubit/observables.py | 30 +-- .../ops/qubit/parametric_ops_controlled.py | 64 ++---- .../ops/qubit/parametric_ops_multi_qubit.py | 64 ++---- .../ops/qubit/parametric_ops_single_qubit.py | 64 ++---- pennylane/ops/qubit/qchem_ops.py | 60 ++---- pennylane/ops/qubit/special_unitary.py | 8 +- pennylane/ops/qubit/state_preparation.py | 13 +- pennylane/ops/qutrit/matrix_ops.py | 21 +- pennylane/ops/qutrit/non_parametric_ops.py | 8 +- pennylane/ops/qutrit/observables.py | 12 +- pennylane/ops/qutrit/parametric_ops.py | 22 +- pennylane/ops/snapshot.py | 7 +- pennylane/pulse/parametrized_evolution.py | 9 +- pennylane/tape/qscript.py | 18 +- pennylane/tape/tape.py | 20 +- pennylane/templates/embeddings/amplitude.py | 7 +- pennylane/templates/embeddings/angle.py | 7 +- pennylane/templates/embeddings/basis.py | 4 +- .../templates/embeddings/displacement.py | 4 +- pennylane/templates/embeddings/iqp.py | 4 +- .../templates/embeddings/qaoaembedding.py | 4 +- pennylane/templates/embeddings/squeezing.py | 4 +- pennylane/templates/layers/basic_entangler.py | 4 +- pennylane/templates/layers/cv_neural_net.py | 2 - pennylane/templates/layers/gate_fabric.py | 4 +- .../layers/particle_conserving_u1.py | 4 +- .../layers/particle_conserving_u2.py | 4 +- pennylane/templates/layers/random.py | 3 +- .../templates/layers/simplified_two_design.py | 4 +- .../templates/layers/strongly_entangling.py | 4 +- .../arbitrary_state_preparation.py | 4 +- .../templates/state_preparations/basis.py | 4 +- .../state_preparations/basis_qutrit.py | 4 +- .../templates/state_preparations/mottonen.py | 4 +- .../subroutines/all_singles_doubles.py | 6 +- .../subroutines/approx_time_evolution.py | 4 +- .../subroutines/arbitrary_unitary.py | 4 +- .../templates/subroutines/basis_rotation.py | 4 +- .../subroutines/commuting_evolution.py | 6 +- .../fermionic_double_excitation.py | 4 +- .../fermionic_single_excitation.py | 4 +- pennylane/templates/subroutines/flip_sign.py | 4 +- pennylane/templates/subroutines/grover.py | 4 +- .../templates/subroutines/hilbert_schmidt.py | 4 +- .../templates/subroutines/interferometer.py | 3 +- pennylane/templates/subroutines/kupccgsd.py | 4 +- pennylane/templates/subroutines/permute.py | 4 +- pennylane/templates/subroutines/qft.py | 4 +- pennylane/templates/subroutines/qmc.py | 4 +- pennylane/templates/subroutines/qpe.py | 4 +- pennylane/templates/subroutines/qsvt.py | 4 +- pennylane/templates/subroutines/uccsd.py | 6 +- pennylane/templates/swapnetworks/ccl2.py | 5 +- pennylane/templates/tensornetworks/mera.py | 3 +- pennylane/templates/tensornetworks/mps.py | 3 +- pennylane/templates/tensornetworks/ttn.py | 3 +- pennylane/transforms/condition.py | 7 +- pennylane/transforms/qcut/qcut.py | 8 +- tests/ops/op_math/test_adjoint.py | 14 -- tests/ops/op_math/test_composite.py | 15 -- tests/ops/op_math/test_controlled.py | 14 -- tests/ops/op_math/test_pow_op.py | 24 --- tests/ops/op_math/test_prod.py | 20 +- tests/ops/op_math/test_sprod.py | 2 +- tests/ops/op_math/test_symbolic_op.py | 14 -- tests/tape/test_tape.py | 10 - .../templates/test_subroutines/test_grover.py | 15 -- tests/test_operation.py | 30 +-- 90 files changed, 348 insertions(+), 1005 deletions(-) diff --git a/doc/development/adding_operators.rst b/doc/development/adding_operators.rst index 03cc8b39a0f..4343e2183ee 100644 --- a/doc/development/adding_operators.rst +++ b/doc/development/adding_operators.rst @@ -148,8 +148,7 @@ knows a native implementation for ``FlipAndRotate``). It also defines an adjoint # we request parameter-shift (or "analytic") differentiation. grad_method = "A" - def __init__(self, angle, wire_rot, wire_flip=None, do_flip=False, - do_queue=None, id=None): + def __init__(self, angle, wire_rot, wire_flip=None, do_flip=False, id=None): # checking the inputs -------------- @@ -177,11 +176,7 @@ knows a native implementation for ``FlipAndRotate``). It also defines an adjoint # The parent class expects all trainable parameters to be fed as positional # arguments, and all wires acted on fed as a keyword argument. # The id keyword argument allows users to give their instance a custom name. - # The do_queue keyword argument specifies whether or not - # the operator is queued when created in a tape context. - # Note that do_queue is deprecated. In the future, please use - # qml.QueuingManager.stop_recording(). - super().__init__(angle, wires=all_wires, do_queue=do_queue, id=id) + super().__init__(angle, wires=all_wires, id=id) @property def num_params(self): diff --git a/doc/development/deprecations.rst b/doc/development/deprecations.rst index 2c952d75c14..3dd1aa270f1 100644 --- a/doc/development/deprecations.rst +++ b/doc/development/deprecations.rst @@ -6,13 +6,6 @@ Deprecations Pending deprecations -------------------- -* The ``do_queue`` keyword argument in ``qml.operation.Operator`` is deprecated. This affects - all child classes, such as ``Operation``, ``Observable``, ``SymbolicOp`` and more. Instead of - setting ``do_queue=False``, use the ``qml.QueuingManager.stop_recording()`` context. - - - Deprecated in v0.31 - - Will be removed in v0.32 - * ``qml.math.purity``, ``qml.math.vn_entropy``, ``qml.math.mutual_info``, ``qml.math.fidelity``, ``qml.math.relative_entropy``, and ``qml.math.max_entropy`` no longer support state vectors as input. Please call ``qml.math.dm_from_state_vector`` on the input before passing to any of these functions. @@ -66,6 +59,13 @@ Pending deprecations Completed deprecation cycles ---------------------------- +* The ``do_queue`` keyword argument in ``qml.operation.Operator`` has been removed. This affects + all child classes, such as ``Operation``, ``Observable``, ``SymbolicOp`` and more. Instead of + setting ``do_queue=False``, use the ``qml.QueuingManager.stop_recording()`` context. + + - Deprecated in v0.31 + - Removed in v0.32 + * The ``qml.specs`` dictionary longer supports direct key access to certain keys. Instead these quantities can be accessed as fields of the new ``Resources`` object saved under ``specs_dict["resources"]``: diff --git a/doc/releases/changelog-dev.md b/doc/releases/changelog-dev.md index 852e0539ee7..4edefdc75a1 100644 --- a/doc/releases/changelog-dev.md +++ b/doc/releases/changelog-dev.md @@ -8,6 +8,10 @@

Breaking changes 💔

+* The `do_queue` keyword argument in `qml.operation.Operator` has been removed. Instead of + setting `do_queue=False`, use the `qml.QueuingManager.stop_recording()` context. + [(#4317)](https://github.com/PennyLaneAI/pennylane/pull/4317) + * The `grouping_type` and `grouping_method` keyword arguments are removed from `qchem.molecular_hamiltonian`. * `zyz_decomposition` and `xyx_decomposition` are removed. Use `one_qubit_decomposition` instead. diff --git a/pennylane/operation.py b/pennylane/operation.py index a299c909933..fd2c03be1c8 100644 --- a/pennylane/operation.py +++ b/pennylane/operation.py @@ -420,9 +420,6 @@ class Operator(abc.ABC): *params (tuple[tensor_like]): trainable parameters wires (Iterable[Any] or Any): Wire label(s) that the operator acts on. If not given, args[-1] is interpreted as wires. - do_queue (bool): indicates whether the operator should be recorded when created in - a tape context. This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str): custom label given to an operator instance, can be useful for some applications where the instance has to be identified @@ -451,8 +448,7 @@ class FlipAndRotate(qml.operation.Operation): # we request parameter-shift (or "analytic") differentiation. grad_method = "A" - def __init__(self, angle, wire_rot, wire_flip=None, do_flip=False, - do_queue=None, id=None): + def __init__(self, angle, wire_rot, wire_flip=None, do_flip=False, id=None): # checking the inputs -------------- @@ -474,11 +470,7 @@ def __init__(self, angle, wire_rot, wire_flip=None, do_flip=False, # The parent class expects all trainable parameters to be fed as positional # arguments, and all wires acted on fed as a keyword argument. # The id keyword argument allows users to give their instance a custom name. - # The do_queue keyword argument specifies whether or not - # the operator is queued when created in a tape context. - # Note that do_queue is deprecated. In the future, please use - # qml.QueuingManager.stop_recording(). - super().__init__(angle, wires=all_wires, do_queue=do_queue, id=id) + super().__init__(angle, wires=all_wires, id=id) @property def num_params(self): @@ -973,7 +965,7 @@ def _format(x): param_string = ",\n".join(_format(p) for p in params) return f"{op_label}\n({param_string})" - def __init__(self, *params, wires=None, do_queue=None, id=None): + def __init__(self, *params, wires=None, id=None): # pylint: disable=too-many-branches self._name = self.__class__.__name__ #: str: name of the operator self._id = id @@ -1026,15 +1018,7 @@ def __init__(self, *params, wires=None, do_queue=None, id=None): self.data = tuple(np.array(p) if isinstance(p, (list, tuple)) else p for p in params) - if do_queue is not None: - do_queue_deprecation_warning = ( - "The do_queue keyword argument is deprecated. Instead of setting " - "it to False, use qml.queuing.QueuingManager.stop_recording()" - ) - warnings.warn(do_queue_deprecation_warning, UserWarning) - - if do_queue or do_queue is None: - self.queue() + self.queue() def _check_batching(self, params): """Check if the expected numbers of dimensions of parameters coincides with the @@ -1526,9 +1510,6 @@ class Operation(Operator): params (tuple[tensor_like]): trainable parameters wires (Iterable[Any] or Any): Wire label(s) that the operator acts on. If not given, args[-1] is interpreted as wires. - do_queue (bool): indicates whether the operator should be - recorded when created in a tape context. This argument is deprecated, - instead of setting it to ``False`` use :meth:`~.queuing.QueuingManager.stop_recording`. id (str): custom label given to an operator instance, can be useful for some applications where the instance has to be identified """ @@ -1659,8 +1640,8 @@ def parameter_frequencies(self): "and parameter frequencies can not be computed as no generator is defined." ) - def __init__(self, *params, wires=None, do_queue=None, id=None): - super().__init__(*params, wires=wires, do_queue=do_queue, id=id) + def __init__(self, *params, wires=None, id=None): + super().__init__(*params, wires=wires, id=id) # check the grad_recipe validity if self.grad_recipe is None: @@ -1678,9 +1659,6 @@ class Channel(Operation, abc.ABC): params (tuple[tensor_like]): trainable parameters wires (Iterable[Any] or Any): Wire label(s) that the operator acts on. If not given, args[-1] is interpreted as wires. - do_queue (bool): indicates whether the operator should be - recorded when created in a tape context. This argument is deprecated, - instead of setting it to ``False`` use :meth:`~.queuing.QueuingManager.stop_recording`. id (str): custom label given to an operator instance, can be useful for some applications where the instance has to be identified """ @@ -1750,9 +1728,6 @@ class Observable(Operator): params (tuple[tensor_like]): trainable parameters wires (Iterable[Any] or Any): Wire label(s) that the operator acts on. If not given, args[-1] is interpreted as wires. - do_queue (bool): indicates whether the operator should be - recorded when created in a tape context. This argument is deprecated, - instead of setting it to ``False`` use :meth:`~.queuing.QueuingManager.stop_recording`. id (str): custom label given to an operator instance, can be useful for some applications where the instance has to be identified """ @@ -2560,9 +2535,6 @@ class CVOperation(CV, Operation): params (tuple[tensor_like]): trainable parameters wires (Iterable[Any] or Any): Wire label(s) that the operator acts on. If not given, args[-1] is interpreted as wires. - do_queue (bool): indicates whether the operator should be - recorded when created in a tape context. This argument is deprecated, - instead of setting it to ``False`` use :meth:`~.queuing.QueuingManager.stop_recording`. id (str): custom label given to an operator instance, can be useful for some applications where the instance has to be identified """ @@ -2686,9 +2658,6 @@ class CVObservable(CV, Observable): params (tuple[tensor_like]): trainable parameters wires (Iterable[Any] or Any): Wire label(s) that the operator acts on. If not given, args[-1] is interpreted as wires. - do_queue (bool): indicates whether the operator should be - recorded when created in a tape context. This argument is deprecated, - instead of setting it to ``False`` use :meth:`~.queuing.QueuingManager.stop_recording`. id (str): custom label given to an operator instance, can be useful for some applications where the instance has to be identified """ diff --git a/pennylane/ops/channel.py b/pennylane/ops/channel.py index 4e2df6f430e..c3a12a4c46a 100644 --- a/pennylane/ops/channel.py +++ b/pennylane/ops/channel.py @@ -51,16 +51,14 @@ class AmplitudeDamping(Channel): Args: gamma (float): amplitude damping probability wires (Sequence[int] or int): the wire the channel acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional) id (str or None): String representing the operation (optional) """ num_params = 1 num_wires = 1 grad_method = "F" - def __init__(self, gamma, wires, do_queue=None, id=None): - super().__init__(gamma, wires=wires, do_queue=do_queue, id=id) + def __init__(self, gamma, wires, id=None): + super().__init__(gamma, wires=wires, id=id) @staticmethod def compute_kraus_matrices(gamma): # pylint:disable=arguments-differ @@ -131,18 +129,14 @@ class GeneralizedAmplitudeDamping(Channel): gamma (float): amplitude damping probability p (float): excitation probability wires (Sequence[int] or int): the wire the channel acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_params = 2 num_wires = 1 grad_method = "F" - def __init__(self, gamma, p, wires, do_queue=None, id=None): - super().__init__(gamma, p, wires=wires, do_queue=do_queue, id=id) + def __init__(self, gamma, p, wires, id=None): + super().__init__(gamma, p, wires=wires, id=id) @staticmethod def compute_kraus_matrices(gamma, p): # pylint:disable=arguments-differ @@ -219,8 +213,8 @@ class PhaseDamping(Channel): num_wires = 1 grad_method = "F" - def __init__(self, gamma, wires, do_queue=None, id=None): - super().__init__(gamma, wires=wires, do_queue=do_queue, id=id) + def __init__(self, gamma, wires, id=None): + super().__init__(gamma, wires=wires, id=id) @staticmethod def compute_kraus_matrices(gamma): # pylint:disable=arguments-differ @@ -298,10 +292,6 @@ class DepolarizingChannel(Channel): Args: p (float): Each Pauli gate is applied with probability :math:`\frac{p}{3}` wires (Sequence[int] or int): the wire the channel acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_params = 1 @@ -309,8 +299,8 @@ class DepolarizingChannel(Channel): grad_method = "A" grad_recipe = ([[1, 0, 1], [-1, 0, 0]],) - def __init__(self, p, wires, do_queue=None, id=None): - super().__init__(p, wires=wires, do_queue=do_queue, id=id) + def __init__(self, p, wires, id=None): + super().__init__(p, wires=wires, id=id) @staticmethod def compute_kraus_matrices(p): # pylint:disable=arguments-differ @@ -375,10 +365,6 @@ class BitFlip(Channel): Args: p (float): The probability that a bit flip error occurs. wires (Sequence[int] or int): the wire the channel acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_params = 1 @@ -386,8 +372,8 @@ class BitFlip(Channel): grad_method = "A" grad_recipe = ([[1, 0, 1], [-1, 0, 0]],) - def __init__(self, p, wires, do_queue=None, id=None): - super().__init__(p, wires=wires, do_queue=do_queue, id=id) + def __init__(self, p, wires, id=None): + super().__init__(p, wires=wires, id=id) @staticmethod def compute_kraus_matrices(p): # pylint:disable=arguments-differ @@ -461,18 +447,14 @@ class ResetError(Channel): p_0 (float): The probability that a reset to 0 error occurs. p_1 (float): The probability that a reset to 1 error occurs. wires (Sequence[int] or int): the wire the channel acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_params = 2 num_wires = 1 grad_method = "F" - def __init__(self, p0, p1, wires, do_queue=None, id=None): - super().__init__(p0, p1, wires=wires, do_queue=do_queue, id=id) + def __init__(self, p0, p1, wires, id=None): + super().__init__(p0, p1, wires=wires, id=id) @staticmethod def compute_kraus_matrices(p_0, p_1): # pylint:disable=arguments-differ @@ -555,10 +537,6 @@ class PauliError(Channel): operators (str): The Pauli operators acting on the specified (groups of) wires p (float): The probability of the operator being applied wires (Sequence[int] or int): The wires the channel acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) **Example:** @@ -578,8 +556,8 @@ class PauliError(Channel): num_params = 2 """int: Number of trainable parameters that the operator depends on.""" - def __init__(self, operators, p, wires=None, do_queue=None, id=None): - super().__init__(operators, p, wires=wires, do_queue=do_queue, id=id) + def __init__(self, operators, p, wires=None, id=None): + super().__init__(operators, p, wires=wires, id=id) # check if the specified operators are legal if not set(operators).issubset({"X", "Y", "Z"}): @@ -671,10 +649,6 @@ class PhaseFlip(Channel): Args: p (float): The probability that a phase flip error occurs. wires (Sequence[int] or int): the wire the channel acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_params = 1 @@ -682,8 +656,8 @@ class PhaseFlip(Channel): grad_method = "A" grad_recipe = ([[1, 0, 1], [-1, 0, 0]],) - def __init__(self, p, wires, do_queue=None, id=None): - super().__init__(p, wires=wires, do_queue=do_queue, id=id) + def __init__(self, p, wires, id=None): + super().__init__(p, wires=wires, id=id) @staticmethod def compute_kraus_matrices(p): # pylint:disable=arguments-differ @@ -725,17 +699,13 @@ class QubitChannel(Channel): Args: K_list (list[array[complex]]): list of Kraus matrices wires (Union[Wires, Sequence[int], or int]): the wire(s) the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_wires = AnyWires grad_method = None - def __init__(self, K_list, wires=None, do_queue=None, id=None): - super().__init__(*K_list, wires=wires, do_queue=do_queue, id=id) + def __init__(self, K_list, wires=None, id=None): + super().__init__(*K_list, wires=wires, id=id) # check all Kraus matrices are square matrices if not all(K.shape[0] == K.shape[1] for K in K_list): @@ -855,18 +825,14 @@ class ThermalRelaxationError(Channel): t2 (float): the :math:`T_2` dephasing constant. Must be less than :math:`2 T_1` tg (float): the gate time for relaxation error wires (Sequence[int] or int): the wire the channel acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_params = 4 num_wires = 1 grad_method = "F" - def __init__(self, pe, t1, t2, tq, wires, do_queue=None, id=None): - super().__init__(pe, t1, t2, tq, wires=wires, do_queue=do_queue, id=id) + def __init__(self, pe, t1, t2, tq, wires, id=None): + super().__init__(pe, t1, t2, tq, wires=wires, id=id) @staticmethod def compute_kraus_matrices(pe, t1, t2, tg): # pylint:disable=arguments-differ diff --git a/pennylane/ops/cv.py b/pennylane/ops/cv.py index 316ed709f1d..7a36d9a7ee8 100644 --- a/pennylane/ops/cv.py +++ b/pennylane/ops/cv.py @@ -101,10 +101,6 @@ class Rotation(CVOperation): Args: phi (float): the rotation angle wires (Sequence[Any] or Any): the wire the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_params = 1 @@ -112,8 +108,8 @@ class Rotation(CVOperation): grad_method = "A" grad_recipe = (_two_term_shift_rule,) - def __init__(self, phi, wires, do_queue=None, id=None): - super().__init__(phi, wires=wires, do_queue=do_queue, id=id) + def __init__(self, phi, wires, id=None): + super().__init__(phi, wires=wires, id=id) @staticmethod def _heisenberg_rep(p): @@ -154,10 +150,6 @@ class Squeezing(CVOperation): r (float): squeezing amount phi (float): squeezing phase angle :math:`\phi` wires (Sequence[Any] or Any): the wire the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_params = 2 @@ -169,8 +161,8 @@ class Squeezing(CVOperation): a = 1 grad_recipe = ([[multiplier, a, shift], [-multiplier, a, -shift]], _two_term_shift_rule) - def __init__(self, r, phi, wires, do_queue=None, id=None): - super().__init__(r, phi, wires=wires, do_queue=do_queue, id=id) + def __init__(self, r, phi, wires, id=None): + super().__init__(r, phi, wires=wires, id=id) @staticmethod def _heisenberg_rep(p): @@ -213,10 +205,6 @@ class Displacement(CVOperation): a (float): displacement magnitude :math:`a=|\alpha|` phi (float): phase angle :math:`\phi` wires (Sequence[Any] or Any): the wire the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_params = 2 @@ -228,8 +216,8 @@ class Displacement(CVOperation): a = 1 grad_recipe = ([[multiplier, a, shift], [-multiplier, a, -shift]], _two_term_shift_rule) - def __init__(self, a, phi, wires, do_queue=None, id=None): - super().__init__(a, phi, wires=wires, do_queue=do_queue, id=id) + def __init__(self, a, phi, wires, id=None): + super().__init__(a, phi, wires=wires, id=id) @staticmethod def _heisenberg_rep(p): @@ -278,10 +266,6 @@ class Beamsplitter(CVOperation): beamsplitter is :math:`r = e^{i\phi}\sin(\theta)`. The value :math:`\phi = \pi/2` gives the symmetric beamsplitter. wires (Sequence[Any]): the wire the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_params = 2 @@ -289,8 +273,8 @@ class Beamsplitter(CVOperation): grad_method = "A" grad_recipe = (_two_term_shift_rule, _two_term_shift_rule) - def __init__(self, theta, phi, wires, do_queue=None, id=None): - super().__init__(theta, phi, wires=wires, do_queue=do_queue, id=id) + def __init__(self, theta, phi, wires, id=None): + super().__init__(theta, phi, wires=wires, id=id) # For the beamsplitter, both parameters are rotation-like @staticmethod @@ -344,10 +328,6 @@ class TwoModeSqueezing(CVOperation): r (float): squeezing amount phi (float): squeezing phase angle :math:`\phi` wires (Sequence[Any]): the wire the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_params = 2 @@ -360,8 +340,8 @@ class TwoModeSqueezing(CVOperation): a = 1 grad_recipe = ([[multiplier, a, shift], [-multiplier, a, -shift]], _two_term_shift_rule) - def __init__(self, r, phi, wires, do_queue=None, id=None): - super().__init__(r, phi, wires=wires, do_queue=do_queue, id=id) + def __init__(self, r, phi, wires, id=None): + super().__init__(r, phi, wires=wires, id=id) @staticmethod def _heisenberg_rep(p): @@ -410,10 +390,6 @@ class QuadraticPhase(CVOperation): Args: s (float): parameter wires (Sequence[Any] or Any): the wire the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_params = 1 @@ -426,8 +402,8 @@ class QuadraticPhase(CVOperation): a = 1 grad_recipe = ([[multiplier, a, shift], [-multiplier, a, -shift]],) - def __init__(self, s, wires, do_queue=None, id=None): - super().__init__(s, wires=wires, do_queue=do_queue, id=id) + def __init__(self, s, wires, id=None): + super().__init__(s, wires=wires, id=id) @staticmethod def _heisenberg_rep(p): @@ -468,10 +444,6 @@ class ControlledAddition(CVOperation): Args: s (float): addition multiplier wires (Sequence[Any]): the wire the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_params = 1 @@ -483,8 +455,8 @@ class ControlledAddition(CVOperation): a = 1 grad_recipe = ([[multiplier, a, shift], [-multiplier, a, -shift]],) - def __init__(self, s, wires, do_queue=None, id=None): - super().__init__(s, wires=wires, do_queue=do_queue, id=id) + def __init__(self, s, wires, id=None): + super().__init__(s, wires=wires, id=id) @staticmethod def _heisenberg_rep(p): @@ -529,10 +501,6 @@ class ControlledPhase(CVOperation): Args: s (float): phase shift multiplier wires (Sequence[Any]): the wire the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_params = 1 @@ -544,8 +512,8 @@ class ControlledPhase(CVOperation): a = 1 grad_recipe = ([[multiplier, a, shift], [-multiplier, a, -shift]],) - def __init__(self, s, wires, do_queue=None, id=None): - super().__init__(s, wires=wires, do_queue=do_queue, id=id) + def __init__(self, s, wires, id=None): + super().__init__(s, wires=wires, id=id) @staticmethod def _heisenberg_rep(p): @@ -577,18 +545,14 @@ class Kerr(CVOperation): Args: kappa (float): parameter wires (Sequence[Any] or Any): the wire the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_params = 1 num_wires = 1 grad_method = "F" - def __init__(self, kappa, wires, do_queue=None, id=None): - super().__init__(kappa, wires=wires, do_queue=do_queue, id=id) + def __init__(self, kappa, wires, id=None): + super().__init__(kappa, wires=wires, id=id) def adjoint(self): return Kerr(-self.parameters[0], wires=self.wires) @@ -610,18 +574,14 @@ class CrossKerr(CVOperation): Args: kappa (float): parameter wires (Sequence[Any]): the wire the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_params = 1 num_wires = 2 grad_method = "F" - def __init__(self, kappa, wires, do_queue=None, id=None): - super().__init__(kappa, wires=wires, do_queue=do_queue, id=id) + def __init__(self, kappa, wires, id=None): + super().__init__(kappa, wires=wires, id=id) def adjoint(self): return CrossKerr(-self.parameters[0], wires=self.wires) @@ -643,18 +603,14 @@ class CubicPhase(CVOperation): Args: gamma (float): parameter wires (Sequence[Any] or Any): the wire the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_params = 1 num_wires = 1 grad_method = "F" - def __init__(self, gamma, wires, do_queue=None, id=None): - super().__init__(gamma, wires=wires, do_queue=do_queue, id=id) + def __init__(self, gamma, wires, id=None): + super().__init__(gamma, wires=wires, id=id) def adjoint(self): return CubicPhase(-self.parameters[0], wires=self.wires) @@ -696,10 +652,6 @@ class InterferometerUnitary(CVOperation): Args: U (array): A shape ``(len(wires), len(wires))`` complex unitary matrix wires (Sequence[Any] or Any): the wires the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_params = 1 @@ -707,8 +659,8 @@ class InterferometerUnitary(CVOperation): grad_method = None grad_recipe = None - def __init__(self, U, wires, do_queue=None, id=None): - super().__init__(U, wires=wires, do_queue=do_queue, id=id) + def __init__(self, U, wires, id=None): + super().__init__(U, wires=wires, id=id) @staticmethod def _heisenberg_rep(p): @@ -752,18 +704,14 @@ class CoherentState(CVOperation): a (float): displacement magnitude :math:`r=|\alpha|` phi (float): phase angle :math:`\phi` wires (Sequence[Any] or Any): the wire the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_params = 2 num_wires = 1 grad_method = "F" - def __init__(self, a, phi, wires, do_queue=None, id=None): - super().__init__(a, phi, wires=wires, do_queue=do_queue, id=id) + def __init__(self, a, phi, wires, id=None): + super().__init__(a, phi, wires=wires, id=id) class SqueezedState(CVOperation): @@ -780,18 +728,14 @@ class SqueezedState(CVOperation): r (float): squeezing magnitude phi (float): squeezing angle :math:`\phi` wires (Sequence[Any] or Any): the wire the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_params = 2 num_wires = 1 grad_method = "F" - def __init__(self, r, phi, wires, do_queue=None, id=None): - super().__init__(r, phi, wires=wires, do_queue=do_queue, id=id) + def __init__(self, r, phi, wires, id=None): + super().__init__(r, phi, wires=wires, id=id) class DisplacedSqueezedState(CVOperation): @@ -818,18 +762,14 @@ class DisplacedSqueezedState(CVOperation): r (float): squeezing magnitude :math:`r=|z|` phi_r (float): squeezing angle :math:`\phi_r` wires (Sequence[Any] or Any): the wire the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_params = 4 num_wires = 1 grad_method = "F" - def __init__(self, a, phi_a, r, phi_r, wires, do_queue=None, id=None): - super().__init__(a, phi_a, r, phi_r, wires=wires, do_queue=do_queue, id=id) + def __init__(self, a, phi_a, r, phi_r, wires, id=None): + super().__init__(a, phi_a, r, phi_r, wires=wires, id=id) class ThermalState(CVOperation): @@ -845,18 +785,14 @@ class ThermalState(CVOperation): Args: nbar (float): mean thermal population of the mode wires (Sequence[Any] or Any): the wire the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_params = 1 num_wires = 1 grad_method = "F" - def __init__(self, nbar, wires, do_queue=None, id=None): - super().__init__(nbar, wires=wires, do_queue=do_queue, id=id) + def __init__(self, nbar, wires, id=None): + super().__init__(nbar, wires=wires, id=id) def label(self, decimals=None, base_label=None, cache=None): return super().label(decimals=decimals, base_label=base_label or "Thermal", cache=cache) @@ -877,18 +813,14 @@ class GaussianState(CVOperation): r (array): a length :math:`2N` vector of means, of the form :math:`(\x_0,\dots,\x_{N-1},\p_0,\dots,\p_{N-1})` wires (Sequence[Any] or Any): the wire the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_params = 2 num_wires = AnyWires grad_method = "F" - def __init__(self, V, r, wires, do_queue=None, id=None): - super().__init__(V, r, wires=wires, do_queue=do_queue, id=id) + def __init__(self, V, r, wires, id=None): + super().__init__(V, r, wires=wires, id=id) def label(self, decimals=None, base_label=None, cache=None): return super().label(decimals=decimals, base_label=base_label or "Gaussian", cache=cache) @@ -907,18 +839,14 @@ class FockState(CVOperation): Args: n (int): Fock state to prepare wires (Sequence[Any] or Any): the wire the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_params = 1 num_wires = 1 grad_method = None - def __init__(self, n, wires, do_queue=None, id=None): - super().__init__(n, wires=wires, do_queue=do_queue, id=id) + def __init__(self, n, wires, id=None): + super().__init__(n, wires=wires, id=id) def label(self, decimals=None, base_label=None, cache=None): r"""A customizable string representation of the operator. @@ -961,10 +889,6 @@ class FockStateVector(CVOperation): state (array): a single ket vector, for single mode state preparation, or a multimode ket, with one array dimension per mode wires (Sequence[Any] or Any): the wire the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) .. details:: @@ -1012,8 +936,8 @@ def circuit(): num_wires = AnyWires grad_method = "F" - def __init__(self, state, wires, do_queue=None, id=None): - super().__init__(state, wires=wires, do_queue=do_queue, id=id) + def __init__(self, state, wires, id=None): + super().__init__(state, wires=wires, id=id) def label(self, decimals=None, base_label=None, cache=None): r"""A customizable string representation of the operator. @@ -1054,18 +978,14 @@ class FockDensityMatrix(CVOperation): state (array): a single mode matrix :math:`\rho_{ij}`, or a multimode tensor :math:`\rho_{ij,kl,\dots,mn}`, with two indices per mode wires (Sequence[Any] or Any): the wire the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_params = 1 num_wires = AnyWires grad_method = "F" - def __init__(self, state, wires, do_queue=None, id=None): - super().__init__(state, wires=wires, do_queue=do_queue, id=id) + def __init__(self, state, wires, id=None): + super().__init__(state, wires=wires, id=id) class CatState(CVOperation): @@ -1093,18 +1013,14 @@ class CatState(CVOperation): p (float): parity, where :math:`p=0` corresponds to an even cat state, and :math:`p=1` an odd cat state. wires (Sequence[Any] or Any): the wire the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_params = 3 num_wires = 1 grad_method = "F" - def __init__(self, a, phi, p, wires, do_queue=None, id=None): - super().__init__(a, phi, p, wires=wires, do_queue=do_queue, id=id) + def __init__(self, a, phi, p, wires, id=None): + super().__init__(a, phi, p, wires=wires, id=id) # ============================================================================= @@ -1302,10 +1218,6 @@ class QuadOperator(CVObservable): phi (float): axis in the phase space at which to calculate the generalized quadrature observable wires (Sequence[Any] or Any): the wire the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_params = 1 @@ -1314,8 +1226,8 @@ class QuadOperator(CVObservable): grad_method = "A" ev_order = 1 - def __init__(self, phi, wires, do_queue=None, id=None): - super().__init__(phi, wires=wires, do_queue=do_queue, id=id) + def __init__(self, phi, wires, id=None): + super().__init__(phi, wires=wires, id=id) @staticmethod def _heisenberg_rep(p): @@ -1383,10 +1295,6 @@ class PolyXP(CVObservable): Args: q (array[float]): expansion coefficients wires (Sequence[Any] or Any): the wire the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ @@ -1396,8 +1304,8 @@ class PolyXP(CVObservable): grad_method = "F" ev_order = 2 - def __init__(self, q, wires, do_queue=None, id=None): - super().__init__(q, wires=wires, do_queue=do_queue, id=id) + def __init__(self, q, wires, id=None): + super().__init__(q, wires=wires, id=id) @staticmethod def _heisenberg_rep(p): @@ -1446,10 +1354,6 @@ class FockStateProjector(CVObservable): Note that ``len(n)==len(wires)``, and that ``len(n)`` cannot exceed the total number of wires in the QNode. wires (Sequence[Any] or Any): the wire the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_params = 1 @@ -1458,8 +1362,8 @@ class FockStateProjector(CVObservable): grad_method = None ev_order = None - def __init__(self, n, wires, do_queue=None, id=None): - super().__init__(n, wires=wires, do_queue=do_queue, id=id) + def __init__(self, n, wires, id=None): + super().__init__(n, wires=wires, id=id) def label(self, decimals=None, base_label=None, cache=None): r"""A customizable string representation of the operator. diff --git a/pennylane/ops/identity.py b/pennylane/ops/identity.py index 3129100106c..dcacc99b32f 100644 --- a/pennylane/ops/identity.py +++ b/pennylane/ops/identity.py @@ -34,9 +34,6 @@ class Identity(CVObservable, Operation): Args: wires (Iterable[Any] or Any): Wire label(s) that the identity acts on. - do_queue (bool): indicates whether the operator should be recorded when created in - a tape context. This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str): custom label given to an operator instance, can be useful for some applications where the instance has to be identified. @@ -54,8 +51,8 @@ class Identity(CVObservable, Operation): ev_order = 1 - def __init__(self, *params, wires=None, do_queue=None, id=None): - super().__init__(*params, wires=wires, do_queue=do_queue, id=id) + def __init__(self, *params, wires=None, id=None): + super().__init__(*params, wires=wires, id=id) self._hyperparameters = {"n_wires": len(self.wires)} self._pauli_rep = qml.pauli.PauliSentence({qml.pauli.PauliWord({}): 1.0}) diff --git a/pennylane/ops/op_math/adjoint.py b/pennylane/ops/op_math/adjoint.py index f51a5524a49..30823e4c826 100644 --- a/pennylane/ops/op_math/adjoint.py +++ b/pennylane/ops/op_math/adjoint.py @@ -209,7 +209,7 @@ class Adjoint(SymbolicOp): _observable_type = None # type if base inherits from observable and not operation # pylint: disable=unused-argument - def __new__(cls, base=None, do_queue=None, id=None): + def __new__(cls, base=None, id=None): """Mixes in parents based on inheritance structure of base. Though all the types will be named "Adjoint", their *identity* and location in memory will @@ -252,9 +252,9 @@ def __new__(cls, base=None, do_queue=None, id=None): return object.__new__(Adjoint) - def __init__(self, base=None, do_queue=None, id=None): + def __init__(self, base=None, id=None): self._name = f"Adjoint({base.name})" - super().__init__(base, do_queue=do_queue, id=id) + super().__init__(base, id=id) def __repr__(self): return f"Adjoint({self.base})" diff --git a/pennylane/ops/op_math/composite.py b/pennylane/ops/op_math/composite.py index 2535b9a59f1..b0a2f832c71 100644 --- a/pennylane/ops/op_math/composite.py +++ b/pennylane/ops/op_math/composite.py @@ -17,7 +17,6 @@ # pylint: disable=too-many-instance-attributes import abc from typing import Callable, List -import warnings import copy import numpy as np @@ -37,9 +36,6 @@ class CompositeOp(Operator): operands: (tuple[~.operation.Operator]): a tuple of operators which will be combined. Keyword Args: - do_queue (bool): determines if the operator will be queued. - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): id for the operator. Default is None. The child composite operator should define the `_op_symbol` property @@ -49,9 +45,7 @@ class CompositeOp(Operator): _eigs = {} # cache eigen vectors and values like in qml.Hermitian - def __init__( - self, *operands: Operator, do_queue=None, id=None - ): # pylint: disable=super-init-not-called + def __init__(self, *operands: Operator, id=None): # pylint: disable=super-init-not-called self._id = id self.queue_idx = None self._name = self.__class__.__name__ @@ -65,17 +59,7 @@ def __init__( self._has_overlapping_wires = None self._overlapping_ops = None self._pauli_rep = self._build_pauli_rep() - - if do_queue is not None: - do_queue_deprecation_warning = ( - "The do_queue keyword argument is deprecated. " - "Instead of setting it to False, use qml.queuing.QueuingManager.stop_recording()" - ) - warnings.warn(do_queue_deprecation_warning, UserWarning) - - if do_queue or do_queue is None: - self.queue() - + self.queue() self._check_batching(None) # unused param def _check_batching(self, _): diff --git a/pennylane/ops/op_math/controlled.py b/pennylane/ops/op_math/controlled.py index 392ecb26748..cf5e1edc3e2 100644 --- a/pennylane/ops/op_math/controlled.py +++ b/pennylane/ops/op_math/controlled.py @@ -151,10 +151,6 @@ class Controlled(SymbolicOp): length as ``control_wires``. Defaults to ``True`` for all control wires. Provided values are converted to `Bool` internally. work_wires (Any): Any auxiliary wires that can be used in the decomposition - do_queue(bool): indicates whether the operator should be - recorded when created in a tape context. - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. .. note:: This class, ``Controlled``, denotes a controlled version of any individual operation. @@ -249,9 +245,7 @@ def __new__(cls, base, *_, **__): return object.__new__(Controlled) # pylint: disable=too-many-function-args - def __init__( - self, base, control_wires, control_values=None, work_wires=None, do_queue=None, id=None - ): + def __init__(self, base, control_wires, control_values=None, work_wires=None, id=None): control_wires = Wires(control_wires) work_wires = Wires([]) if work_wires is None else Wires(work_wires) @@ -289,7 +283,7 @@ def __init__( self._name = f"C({base.name})" - super().__init__(base, do_queue, id) + super().__init__(base, id) @property def hash(self): @@ -615,10 +609,8 @@ def __new__(cls, *_, **__): return object.__new__(cls) # pylint: disable=too-many-function-args - def __init__( - self, base, control_wires, control_values=None, work_wires=None, do_queue=None, id=None - ): - super().__init__(base, control_wires, control_values, work_wires, do_queue, id) + def __init__(self, base, control_wires, control_values=None, work_wires=None, id=None): + super().__init__(base, control_wires, control_values, work_wires, id) # check the grad_recipe validity if self.grad_recipe is None: # Make sure grad_recipe is an iterable of correct length instead of None diff --git a/pennylane/ops/op_math/controlled_ops.py b/pennylane/ops/op_math/controlled_ops.py index 6a052d21741..2b09b1bb692 100644 --- a/pennylane/ops/op_math/controlled_ops.py +++ b/pennylane/ops/op_math/controlled_ops.py @@ -56,9 +56,6 @@ class ControlledQubitUnitary(ControlledOp): wires (Union[Wires, Sequence[int], or int]): the wire(s) the unitary acts on (optional if U is provided as a QubitUnitary) control_values (List[int, bool]): a list providing the state of the control qubits to control on (default is the all 1s state) unitary_check (bool): whether to check whether an array U is unitary when creating the operator (default False) - do_queue (bool): indicates whether the operator should be recorded when created in a tape context. - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. **Example** @@ -112,7 +109,6 @@ def __init__( control_wires, wires=None, control_values=None, - do_queue=None, unitary_check=False, work_wires=None, ): @@ -129,20 +125,18 @@ def __init__( control_wires, control_values=control_values, work_wires=work_wires, - do_queue=do_queue, ) self._name = "ControlledQubitUnitary" def _controlled(self, wire): ctrl_wires = self.control_wires + wire values = None if self.control_values is None else self.control_values + [True] - new_op = ControlledQubitUnitary( + return ControlledQubitUnitary( self.base, control_wires=ctrl_wires, control_values=values, work_wires=self.work_wires, ) - return new_op class CY(ControlledOp): @@ -165,9 +159,6 @@ class CY(ControlledOp): Args: wires (Sequence[int]): the wires the operation acts on - do_queue (bool): indicates whether the operator should be recorded when created in - a tape context. This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str): custom label given to an operator instance, can be useful for some applications where the instance has to be identified. """ @@ -183,11 +174,11 @@ class CY(ControlledOp): grad_method = None """Gradient computation method.""" - def __init__(self, wires, do_queue=None, id=None): + def __init__(self, wires, id=None): control_wire, wire = wires base = PauliY(wire) - super().__init__(base, control_wire, do_queue=do_queue, id=id) + super().__init__(base, control_wire, id=id) self._name = "CY" @staticmethod diff --git a/pennylane/ops/op_math/evolution.py b/pennylane/ops/op_math/evolution.py index 9b30ec3a9ab..256217d74d3 100644 --- a/pennylane/ops/op_math/evolution.py +++ b/pennylane/ops/op_math/evolution.py @@ -34,9 +34,6 @@ class Evolution(Exp): num_steps (int): The number of steps used in the decomposition of the exponential operator, also known as the Trotter number. If this value is `None` and the Suzuki-Trotter decomposition is needed, an error will be raised. - do_queue (bool): determines if the sum operator will be queued. - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str): id for the Evolution operator. Default is None. Returns: @@ -81,10 +78,8 @@ class Evolution(Exp): num_params = 1 # pylint: disable=too-many-arguments - def __init__(self, generator, param=1, num_steps=None, do_queue=None, id=None): - super().__init__( - generator, coeff=-1j * param, num_steps=num_steps, do_queue=do_queue, id=id - ) + def __init__(self, generator, param=1, num_steps=None, id=None): + super().__init__(generator, coeff=-1j * param, num_steps=num_steps, id=id) self._data = (param,) def __repr__(self): diff --git a/pennylane/ops/op_math/exp.py b/pennylane/ops/op_math/exp.py index 26df89c569a..6580e352ea3 100644 --- a/pennylane/ops/op_math/exp.py +++ b/pennylane/ops/op_math/exp.py @@ -123,9 +123,6 @@ class Exp(ScalarSymbolicOp, Operation): num_steps (int): The number of steps used in the decomposition of the exponential operator, also known as the Trotter number. If this value is `None` and the Suzuki-Trotter decomposition is needed, an error will be raised. - do_queue (bool): determines if the sum operator will be queued. - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str): id for the Exp operator. Default is None. **Example** @@ -171,8 +168,8 @@ class Exp(ScalarSymbolicOp, Operation): _name = "Exp" # pylint: disable=too-many-arguments - def __init__(self, base, coeff=1, num_steps=None, do_queue=None, id=None): - super().__init__(base, scalar=coeff, do_queue=do_queue, id=id) + def __init__(self, base, coeff=1, num_steps=None, id=None): + super().__init__(base, scalar=coeff, id=id) self.grad_recipe = [None] self.num_steps = num_steps diff --git a/pennylane/ops/op_math/pow.py b/pennylane/ops/op_math/pow.py index 72e73fda8e7..0fcfc6ef7ef 100644 --- a/pennylane/ops/op_math/pow.py +++ b/pennylane/ops/op_math/pow.py @@ -16,7 +16,6 @@ """ import copy from typing import Union -import warnings from scipy.linalg import fractional_matrix_power @@ -37,7 +36,7 @@ _superscript = str.maketrans("0123456789.+-", "⁰¹²³⁴⁵⁶⁷⁸⁹⋅⁺⁻") -def pow(base, z=1, lazy=True, do_queue=None, id=None): +def pow(base, z=1, lazy=True, id=None): """Raise an Operator to a power. Args: @@ -47,10 +46,6 @@ def pow(base, z=1, lazy=True, do_queue=None, id=None): Keyword Args: lazy=True (bool): In lazy mode, all operations are wrapped in a ``Pow`` class and handled later. If ``lazy=False``, operation-specific simplifications are first attempted. - do_queue (bool): indicates whether the operator should be - recorded when created in a tape context. - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str): custom label given to an operator instance, can be useful for some applications where the instance has to be identified @@ -93,11 +88,11 @@ def pow(base, z=1, lazy=True, do_queue=None, id=None): """ if lazy: - return Pow(base, z, do_queue=do_queue, id=id) + return Pow(base, z, id=id) try: pow_ops = base.pow(z) except PowUndefinedError: - return Pow(base, z, do_queue=do_queue, id=id) + return Pow(base, z, id=id) num_ops = len(pow_ops) if num_ops == 0: @@ -106,16 +101,7 @@ def pow(base, z=1, lazy=True, do_queue=None, id=None): pow_op = pow_ops[0] else: pow_op = qml.prod(*pow_ops) - - if do_queue is not None: - do_queue_deprecation_warning = ( - "The do_queue keyword argument is deprecated. " - "Instead of setting it to False, use qml.queuing.QueuingManager.stop_recording()" - ) - warnings.warn(do_queue_deprecation_warning, UserWarning) - - if do_queue or do_queue is None: - QueuingManager.remove(base) + QueuingManager.remove(base) return pow_op @@ -177,7 +163,7 @@ class Pow(ScalarSymbolicOp): _observable_type = None # type if base inherits from observable and not oepration # pylint: disable=unused-argument - def __new__(cls, base=None, z=1, do_queue=None, id=None): + def __new__(cls, base=None, z=1, id=None): """Mixes in parents based on inheritance structure of base. Though all the types will be named "Pow", their *identity* and location in memory will be @@ -218,11 +204,11 @@ def __new__(cls, base=None, z=1, do_queue=None, id=None): return object.__new__(Pow) - def __init__(self, base=None, z=1, do_queue=None, id=None): + def __init__(self, base=None, z=1, id=None): self.hyperparameters["z"] = z self._name = f"{base.name}**{z}" - super().__init__(base, scalar=z, do_queue=do_queue, id=id) + super().__init__(base, scalar=z, id=id) if isinstance(self.z, int) and self.z > 0: if (base_pauli_rep := getattr(self.base, "_pauli_rep", None)) and ( diff --git a/pennylane/ops/op_math/prod.py b/pennylane/ops/op_math/prod.py index 38c15a6575a..ff62ecda506 100644 --- a/pennylane/ops/op_math/prod.py +++ b/pennylane/ops/op_math/prod.py @@ -42,7 +42,7 @@ computing the sparse matrix representation.""" -def prod(*ops, do_queue=None, id=None, lazy=True): +def prod(*ops, id=None, lazy=True): """Construct an operator which represents the generalized product of the operators provided. @@ -55,9 +55,6 @@ def prod(*ops, do_queue=None, id=None, lazy=True): Alternatively, a single qfunc that queues operators can be passed to this function. Keyword Args: - do_queue (bool): determines if the product operator will be queued. - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): id for the product operator. Default is None. lazy=True (bool): If ``lazy=False``, a simplification will be performed such that when any of the operators is already a product operator, its operands will be used instead. @@ -109,22 +106,20 @@ def prod(*ops, do_queue=None, id=None, lazy=True): @wraps(fn) def wrapper(*args, **kwargs): qs = qml.tape.make_qscript(fn)(*args, **kwargs) - return prod(*qs.operations[::-1], do_queue=do_queue, id=id, lazy=lazy) + return prod(*qs.operations[::-1], id=id, lazy=lazy) return wrapper if lazy: - return Prod(*ops, do_queue=do_queue, id=id) + return Prod(*ops, id=id) ops_simp = Prod( *itertools.chain.from_iterable([op if isinstance(op, Prod) else [op] for op in ops]), - do_queue=do_queue, id=id, ) - if do_queue or do_queue is None: - for op in ops: - QueuingManager.remove(op) + for op in ops: + QueuingManager.remove(op) return ops_simp @@ -137,9 +132,6 @@ class Prod(CompositeOp): together. Keyword Args: - do_queue (bool): determines if the product operator will be queued. - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): id for the product operator. Default is None. .. seealso:: :func:`~.ops.op_math.prod` diff --git a/pennylane/ops/op_math/sprod.py b/pennylane/ops/op_math/sprod.py index a59f4a8875f..a2745ead622 100644 --- a/pennylane/ops/op_math/sprod.py +++ b/pennylane/ops/op_math/sprod.py @@ -28,7 +28,7 @@ from .symbolicop import ScalarSymbolicOp -def s_prod(scalar, operator, lazy=True, do_queue=None, id=None): +def s_prod(scalar, operator, lazy=True, id=None): r"""Construct an operator which is the scalar product of the given scalar and operator provided. @@ -38,9 +38,6 @@ def s_prod(scalar, operator, lazy=True, do_queue=None, id=None): Keyword Args: lazy=True (bool): If ``lazy=False`` and the operator is already a scalar product operator, the scalar provided will simply be combined with the existing scaling factor. - do_queue (bool): determines if the scalar product operator will be queued. - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): id for the scalar product operator. Default is None. Returns: ~ops.op_math.SProd: The operator representing the scalar product. @@ -76,13 +73,10 @@ def s_prod(scalar, operator, lazy=True, do_queue=None, id=None): [ 2., 0.]]) """ if lazy or not isinstance(operator, SProd): - return SProd(scalar, operator, do_queue=do_queue, id=id) - - sprod_op = SProd(scalar=scalar * operator.scalar, base=operator.base, do_queue=do_queue, id=id) - - if do_queue or do_queue is None: - QueuingManager.remove(operator) + return SProd(scalar, operator, id=id) + sprod_op = SProd(scalar=scalar * operator.scalar, base=operator.base, id=id) + QueuingManager.remove(operator) return sprod_op @@ -95,10 +89,6 @@ class SProd(ScalarSymbolicOp): base (~.operation.Operator): the operator which will get scaled. Keyword Args: - do_queue (bool): determines if the scalar product operator will be queued - (currently not supported). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): id for the scalar product operator. Default is None. .. note:: @@ -139,8 +129,8 @@ def circuit(scalar, theta): """ _name = "SProd" - def __init__(self, scalar: Union[int, float, complex], base: Operator, do_queue=None, id=None): - super().__init__(base=base, scalar=scalar, do_queue=do_queue, id=id) + def __init__(self, scalar: Union[int, float, complex], base: Operator, id=None): + super().__init__(base=base, scalar=scalar, id=id) if (base_pauli_rep := getattr(self.base, "_pauli_rep", None)) and (self.batch_size is None): scalar = copy(self.scalar) diff --git a/pennylane/ops/op_math/sum.py b/pennylane/ops/op_math/sum.py index 03081c31623..0cfff8aa560 100644 --- a/pennylane/ops/op_math/sum.py +++ b/pennylane/ops/op_math/sum.py @@ -30,16 +30,13 @@ from .composite import CompositeOp -def sum(*summands, do_queue=None, id=None, lazy=True): +def sum(*summands, id=None, lazy=True): r"""Construct an operator which is the sum of the given operators. Args: *summands (tuple[~.operation.Operator]): the operators we want to sum together. Keyword Args: - do_queue (bool): determines if the sum operator will be queued (currently not supported). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): id for the Sum operator. Default is None. lazy=True (bool): If ``lazy=False``, a simplification will be performed such that when any of the operators is already a sum operator, its operands (summands) will be used instead. @@ -72,17 +69,15 @@ def sum(*summands, do_queue=None, id=None, lazy=True): [ 1, -1]]) """ if lazy: - return Sum(*summands, do_queue=do_queue, id=id) + return Sum(*summands, id=id) summands_simp = Sum( *itertools.chain.from_iterable([op if isinstance(op, Sum) else [op] for op in summands]), - do_queue=do_queue, id=id, ) - if do_queue or do_queue is None: - for op in summands: - QueuingManager.remove(op) + for op in summands: + QueuingManager.remove(op) return summands_simp @@ -94,9 +89,6 @@ class Sum(CompositeOp): *summands (tuple[~.operation.Operator]): a tuple of operators which will be summed together. Keyword Args: - do_queue (bool): determines if the sum operator will be queued. - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): id for the sum operator. Default is None. .. note:: diff --git a/pennylane/ops/op_math/symbolicop.py b/pennylane/ops/op_math/symbolicop.py index dafedf0d67c..67b9e3b708e 100644 --- a/pennylane/ops/op_math/symbolicop.py +++ b/pennylane/ops/op_math/symbolicop.py @@ -16,7 +16,6 @@ """ from abc import abstractmethod from copy import copy -import warnings import numpy as np @@ -30,10 +29,6 @@ class SymbolicOp(Operator): Args: base (~.operation.Operator): the base operation that is modified symbolicly - do_queue (bool): indicates whether the operator should be - recorded when created in a tape context. - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str): custom label given to an operator instance, can be useful for some applications where the instance has to be identified @@ -69,21 +64,12 @@ def __copy__(self): return copied_op # pylint: disable=super-init-not-called - def __init__(self, base, do_queue=None, id=None): + def __init__(self, base, id=None): self.hyperparameters["base"] = base self._id = id self.queue_idx = None self._pauli_rep = None - - if do_queue is not None: - do_queue_deprecation_warning = ( - "The do_queue keyword argument is deprecated. " - "Instead of setting it to False, use qml.queuing.QueuingManager.stop_recording()" - ) - warnings.warn(do_queue_deprecation_warning, UserWarning) - - if do_queue or do_queue is None: - self.queue() + self.queue() @property def batch_size(self): @@ -163,9 +149,6 @@ class ScalarSymbolicOp(SymbolicOp): Args: base (~.operation.Operator): the base operation that is modified symbolicly scalar (float): the scalar coefficient - do_queue (bool): indicates whether the operator should be recorded when created in a tape - context. This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str): custom label given to an operator instance, can be useful for some applications where the instance has to be identified @@ -175,9 +158,9 @@ class ScalarSymbolicOp(SymbolicOp): _name = "ScalarSymbolicOp" - def __init__(self, base, scalar: float, do_queue=None, id=None): + def __init__(self, base, scalar: float, id=None): self.scalar = np.array(scalar) if isinstance(scalar, list) else scalar - super().__init__(base, do_queue=do_queue, id=id) + super().__init__(base, id=id) self._batch_size = self._check_and_compute_batch_size(scalar) @property diff --git a/pennylane/ops/qubit/arithmetic_ops.py b/pennylane/ops/qubit/arithmetic_ops.py index 7dab8f09df3..9dcd554c906 100644 --- a/pennylane/ops/qubit/arithmetic_ops.py +++ b/pennylane/ops/qubit/arithmetic_ops.py @@ -360,14 +360,7 @@ class IntegerComparator(Operation): grad_method = None # pylint: disable=too-many-arguments - def __init__( - self, - value, - geq=True, - wires=None, - work_wires=None, - do_queue=None, - ): + def __init__(self, value, geq=True, wires=None, work_wires=None): if not isinstance(value, int): raise ValueError(f"The compared value must be an int. Got {type(value)}.") if wires is None: @@ -395,7 +388,7 @@ def __init__( self.geq = geq self.value = value - super().__init__(wires=total_wires, do_queue=do_queue) + super().__init__(wires=total_wires) def label(self, decimals=None, base_label=None, cache=None): return base_label or f">={self.value}" if self.geq else f"<{self.value}" diff --git a/pennylane/ops/qubit/hamiltonian.py b/pennylane/ops/qubit/hamiltonian.py index e59aadb3d73..e552c40dc4b 100644 --- a/pennylane/ops/qubit/hamiltonian.py +++ b/pennylane/ops/qubit/hamiltonian.py @@ -174,7 +174,6 @@ def __init__( grouping_type=None, method="rlf", id=None, - do_queue=None, ): if qml.math.shape(coeffs)[0] != len(observables): raise ValueError( @@ -216,7 +215,7 @@ def __init__( # create the operator using each coefficient as a separate parameter; # this causes H.data to be a list of tensor scalars, # while H.coeffs is the original tensor - super().__init__(*coeffs_flat, wires=self._wires, id=id, do_queue=do_queue) + super().__init__(*coeffs_flat, wires=self._wires, id=id) def _check_batching(self, params): """Override for Hamiltonian, batching is not yet supported.""" diff --git a/pennylane/ops/qubit/matrix_ops.py b/pennylane/ops/qubit/matrix_ops.py index 0e1a69dbb62..65df517da16 100644 --- a/pennylane/ops/qubit/matrix_ops.py +++ b/pennylane/ops/qubit/matrix_ops.py @@ -86,10 +86,6 @@ class QubitUnitary(Operation): Args: U (array[complex]): square unitary matrix wires (Sequence[int] or int): the wire(s) the operation acts on - do_queue (bool): indicates whether the operator should be - recorded when created in a tape context. - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str): custom label given to an operator instance, can be useful for some applications where the instance has to be identified unitary_check (bool): check for unitarity of the given matrix @@ -121,7 +117,7 @@ class QubitUnitary(Operation): """Gradient computation method.""" def __init__( - self, U, wires, do_queue=None, id=None, unitary_check=False + self, U, wires, id=None, unitary_check=False ): # pylint: disable=too-many-arguments wires = Wires(wires) U_shape = qml.math.shape(U) @@ -151,7 +147,7 @@ def __init__( UserWarning, ) - super().__init__(U, wires=wires, do_queue=do_queue, id=id) + super().__init__(U, wires=wires, id=id) @staticmethod def compute_matrix(U): # pylint: disable=arguments-differ @@ -443,10 +439,6 @@ class BlockEncode(Operation): Args: A (tensor_like): a general :math:`(n \times m)` matrix to be encoded wires (Iterable[int, str], Wires): the wires the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) Raises: @@ -507,7 +499,7 @@ class BlockEncode(Operation): grad_method = None """Gradient computation method.""" - def __init__(self, A, wires, do_queue=None, id=None): + def __init__(self, A, wires, id=None): shape_a = qml.math.shape(A) if shape_a == () or all(x == 1 for x in shape_a): A = qml.math.reshape(A, [1, 1]) @@ -533,7 +525,7 @@ def __init__(self, A, wires, do_queue=None, id=None): f" Cannot be embedded in a {len(wires)} qubit system." ) - super().__init__(A, wires=wires, do_queue=do_queue, id=id) + super().__init__(A, wires=wires, id=id) self.hyperparameters["norm"] = normalization self.hyperparameters["subspace"] = subspace diff --git a/pennylane/ops/qubit/non_parametric_ops.py b/pennylane/ops/qubit/non_parametric_ops.py index de5e57a47b5..4bf3442460f 100644 --- a/pennylane/ops/qubit/non_parametric_ops.py +++ b/pennylane/ops/qubit/non_parametric_ops.py @@ -202,8 +202,8 @@ class PauliX(Observable, Operation): _queue_category = "_ops" - def __init__(self, *params, wires=None, do_queue=None, id=None): - super().__init__(*params, wires=wires, do_queue=do_queue, id=id) + def __init__(self, *params, wires=None, id=None): + super().__init__(*params, wires=wires, id=id) self._pauli_rep = qml.pauli.PauliSentence({qml.pauli.PauliWord({self.wires[0]: "X"}): 1.0}) def label(self, decimals=None, base_label=None, cache=None): @@ -357,8 +357,8 @@ class PauliY(Observable, Operation): _queue_category = "_ops" - def __init__(self, *params, wires=None, do_queue=None, id=None): - super().__init__(*params, wires=wires, do_queue=do_queue, id=id) + def __init__(self, *params, wires=None, id=None): + super().__init__(*params, wires=wires, id=id) self._pauli_rep = qml.pauli.PauliSentence({qml.pauli.PauliWord({self.wires[0]: "Y"}): 1.0}) def label(self, decimals=None, base_label=None, cache=None): @@ -509,8 +509,8 @@ class PauliZ(Observable, Operation): _queue_category = "_ops" - def __init__(self, *params, wires=None, do_queue=None, id=None): - super().__init__(*params, wires=wires, do_queue=do_queue, id=id) + def __init__(self, *params, wires=None, id=None): + super().__init__(*params, wires=wires, id=id) self._pauli_rep = qml.pauli.PauliSentence({qml.pauli.PauliWord({self.wires[0]: "Z"}): 1.0}) def label(self, decimals=None, base_label=None, cache=None): @@ -1254,10 +1254,6 @@ class ECR(Operation): Args: wires (int): the subsystem the gate acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ @@ -2068,14 +2064,7 @@ class MultiControlledX(Operation): grad_method = None # pylint: disable=too-many-arguments - def __init__( - self, - control_wires=None, - wires=None, - control_values=None, - work_wires=None, - do_queue=None, - ): + def __init__(self, control_wires=None, wires=None, control_values=None, work_wires=None): if wires is None: raise ValueError("Must specify the wires where the operation acts on") if control_wires is None: @@ -2115,7 +2104,7 @@ def __init__( self.hyperparameters["control_values"] = control_values self.total_wires = total_wires - super().__init__(wires=self.total_wires, do_queue=do_queue) + super().__init__(wires=self.total_wires) def __repr__(self): return f'MultiControlledX(wires={list(self.total_wires._labels)}, control_values="{self.hyperparameters["control_values"]}")' @@ -2354,10 +2343,10 @@ class Barrier(Operation): num_wires = AnyWires par_domain = None - def __init__(self, wires=Wires([]), only_visual=False, do_queue=None, id=None): + def __init__(self, wires=Wires([]), only_visual=False, id=None): self.only_visual = only_visual self.hyperparameters["only_visual"] = only_visual - super().__init__(wires=wires, do_queue=do_queue, id=id) + super().__init__(wires=wires, id=id) @staticmethod def compute_decomposition(wires, only_visual=False): # pylint: disable=unused-argument @@ -2426,13 +2415,13 @@ class WireCut(Operation): num_wires = AnyWires grad_method = None - def __init__(self, *params, wires=None, do_queue=None, id=None): + def __init__(self, *params, wires=None, id=None): if wires == []: raise ValueError( f"{self.__class__.__name__}: wrong number of wires. " f"At least one wire has to be given." ) - super().__init__(*params, wires=wires, do_queue=do_queue, id=id) + super().__init__(*params, wires=wires, id=id) @staticmethod def compute_decomposition(wires): # pylint: disable=unused-argument diff --git a/pennylane/ops/qubit/observables.py b/pennylane/ops/qubit/observables.py index fc550333983..9246de99dc7 100644 --- a/pennylane/ops/qubit/observables.py +++ b/pennylane/ops/qubit/observables.py @@ -52,10 +52,6 @@ class Hermitian(Observable): Args: A (array or Sequence): square hermitian matrix wires (Sequence[int] or int): the wire(s) the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_wires = AnyWires @@ -68,7 +64,7 @@ class Hermitian(Observable): _num_basis_states = 2 _eigs = {} - def __init__(self, A, wires, do_queue=None, id=None): + def __init__(self, A, wires, id=None): A = np.array(A) if isinstance(A, list) else A if not qml.math.is_abstract(A): if isinstance(wires, Sequence) and not isinstance(wires, str): @@ -83,7 +79,7 @@ def __init__(self, A, wires, do_queue=None, id=None): Hermitian._validate_input(A, expected_mx_shape) - super().__init__(A, wires=wires, do_queue=do_queue, id=id) + super().__init__(A, wires=wires, id=id) @staticmethod def _validate_input(A, expected_mx_shape=None): @@ -221,10 +217,6 @@ class SparseHamiltonian(Observable): H (csr_matrix): a sparse matrix in SciPy Compressed Sparse Row (CSR) format with dimension :math:`(2^n, 2^n)`, where :math:`n` is the number of wires. wires (Sequence[int]): the wire(s) the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) **Example** @@ -248,10 +240,10 @@ class SparseHamiltonian(Observable): grad_method = None - def __init__(self, H, wires=None, do_queue=None, id=None): + def __init__(self, H, wires=None, id=None): if not isinstance(H, csr_matrix): raise TypeError("Observable must be a scipy sparse csr_matrix.") - super().__init__(H, wires=wires, do_queue=do_queue, id=id) + super().__init__(H, wires=wires, id=id) mat_len = 2 ** len(self.wires) if H.shape != (mat_len, mat_len): raise ValueError( @@ -330,7 +322,7 @@ def compute_sparse_matrix(H): # pylint: disable=arguments-differ class Projector(Observable): - r"""Projector(state, wires, do_queue=None, id=None) + r"""Projector(state, wires, id=None) Observable corresponding to the state projector :math:`P=\ket{\phi}\bra{\phi}`. The expectation of this observable returns the value @@ -350,10 +342,6 @@ class Projector(Observable): state (tensor-like): Input state of shape ``(n,)`` for a basis-state projector, or ``(2**n,)`` for a state-vector projector. wires (Iterable): wires that the projector acts on. - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional). **Example** @@ -443,14 +431,14 @@ def __copy__(self): class _BasisStateProjector(Observable): # The call signature should be the same as Projector.__new__ for the positional # arguments, but with free key word arguments. - def __init__(self, state, wires, do_queue=None, id=None): + def __init__(self, state, wires, id=None): wires = Wires(wires) state = list(qml.math.toarray(state)) if not set(state).issubset({0, 1}): raise ValueError(f"Basis state must only consist of 0s and 1s; got {state}") - super().__init__(state, wires=wires, do_queue=do_queue, id=id) + super().__init__(state, wires=wires, id=id) def label(self, decimals=None, base_label=None, cache=None): r"""A customizable string representation of the operator. @@ -568,11 +556,11 @@ def compute_diagonalizing_gates( class _StateVectorProjector(Observable): # The call signature should be the same as Projector.__new__ for the positional # arguments, but with free key word arguments. - def __init__(self, state, wires, do_queue=None, id=None): + def __init__(self, state, wires, id=None): wires = Wires(wires) state = list(qml.math.toarray(state)) - super().__init__(state, wires=wires, do_queue=do_queue, id=id) + super().__init__(state, wires=wires, id=id) def label(self, decimals=None, base_label=None, cache=None): r"""A customizable string representation of the operator. diff --git a/pennylane/ops/qubit/parametric_ops_controlled.py b/pennylane/ops/qubit/parametric_ops_controlled.py index a7d555cfa0a..a037c83cca3 100644 --- a/pennylane/ops/qubit/parametric_ops_controlled.py +++ b/pennylane/ops/qubit/parametric_ops_controlled.py @@ -51,10 +51,6 @@ class ControlledPhaseShift(Operation): Args: phi (float): rotation angle :math:`\phi` wires (Sequence[int]): the wire the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_wires = 2 @@ -71,8 +67,8 @@ class ControlledPhaseShift(Operation): def generator(self): return qml.Projector(np.array([1, 1]), wires=self.wires) - def __init__(self, phi, wires, do_queue=None, id=None): - super().__init__(phi, wires=wires, do_queue=do_queue, id=id) + def __init__(self, phi, wires, id=None): + super().__init__(phi, wires=wires, id=id) def label(self, decimals=None, base_label=None, cache=None): return super().label(decimals=decimals, base_label=base_label or "Rϕ", cache=cache) @@ -244,10 +240,6 @@ class CPhaseShift00(Operation): Args: phi (float): rotation angle :math:`\phi` wires (Sequence[int]): the wire the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_wires = 2 @@ -263,8 +255,8 @@ class CPhaseShift00(Operation): def generator(self): return qml.Projector(np.array([0, 0]), wires=self.wires) - def __init__(self, phi, wires, do_queue=None, id=None): - super().__init__(phi, wires=wires, do_queue=do_queue, id=id) + def __init__(self, phi, wires, id=None): + super().__init__(phi, wires=wires, id=id) def label(self, decimals=None, base_label=None, cache=None): return super().label(decimals=decimals, base_label="Rϕ(00)", cache=cache) @@ -434,10 +426,6 @@ class CPhaseShift01(Operation): Args: phi (float): rotation angle :math:`\phi` wires (Sequence[int]): the wire the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_wires = 2 @@ -453,8 +441,8 @@ class CPhaseShift01(Operation): def generator(self): return qml.Projector(np.array([0, 1]), wires=self.wires) - def __init__(self, phi, wires, do_queue=None, id=None): - super().__init__(phi, wires=wires, do_queue=do_queue, id=id) + def __init__(self, phi, wires, id=None): + super().__init__(phi, wires=wires, id=id) def label(self, decimals=None, base_label=None, cache=None): return super().label(decimals=decimals, base_label="Rϕ(01)", cache=cache) @@ -616,10 +604,6 @@ class CPhaseShift10(Operation): Args: phi (float): rotation angle :math:`\phi` wires (Any, Wires): the wire the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_wires = 2 @@ -635,8 +619,8 @@ class CPhaseShift10(Operation): def generator(self): return qml.Projector(np.array([1, 0]), wires=self.wires) - def __init__(self, phi, wires, do_queue=None, id=None): - super().__init__(phi, wires=wires, do_queue=do_queue, id=id) + def __init__(self, phi, wires, id=None): + super().__init__(phi, wires=wires, id=id) def label(self, decimals=None, base_label=None, cache=None): return super().label(decimals=decimals, base_label="Rϕ(10)", cache=cache) @@ -802,10 +786,6 @@ class CRX(Operation): Args: phi (float): rotation angle :math:`\phi` wires (Sequence[int]): the wire the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_wires = 2 @@ -822,8 +802,8 @@ class CRX(Operation): def generator(self): return -0.5 * qml.Projector(np.array([1]), wires=self.wires[0]) @ PauliX(self.wires[1]) - def __init__(self, phi, wires, do_queue=None, id=None): - super().__init__(phi, wires=wires, do_queue=do_queue, id=id) + def __init__(self, phi, wires, id=None): + super().__init__(phi, wires=wires, id=id) def label(self, decimals=None, base_label=None, cache=None): return super().label(decimals=decimals, base_label=base_label or "RX", cache=cache) @@ -968,10 +948,6 @@ class CRY(Operation): Args: phi (float): rotation angle :math:`\phi` wires (Sequence[int]): the wire the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_wires = 2 @@ -988,8 +964,8 @@ class CRY(Operation): def generator(self): return -0.5 * qml.Projector(np.array([1]), wires=self.wires[0]) @ PauliY(self.wires[1]) - def __init__(self, phi, wires, do_queue=None, id=None): - super().__init__(phi, wires=wires, do_queue=do_queue, id=id) + def __init__(self, phi, wires, id=None): + super().__init__(phi, wires=wires, id=id) def label(self, decimals=None, base_label=None, cache=None): return super().label(decimals=decimals, base_label=base_label or "RY", cache=cache) @@ -1133,10 +1109,6 @@ class CRZ(Operation): Args: phi (float): rotation angle :math:`\phi` wires (Sequence[int]): the wire the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_wires = 2 @@ -1153,8 +1125,8 @@ class CRZ(Operation): def generator(self): return -0.5 * qml.Projector(np.array([1]), wires=self.wires[0]) @ PauliZ(self.wires[1]) - def __init__(self, phi, wires, do_queue=None, id=None): - super().__init__(phi, wires=wires, do_queue=do_queue, id=id) + def __init__(self, phi, wires, id=None): + super().__init__(phi, wires=wires, id=id) def label(self, decimals=None, base_label=None, cache=None): return super().label(decimals=decimals, base_label=base_label or "RZ", cache=cache) @@ -1328,10 +1300,6 @@ class CRot(Operation): theta (float): rotation angle :math:`\theta` omega (float): rotation angle :math:`\omega` wires (Sequence[int]): the wire the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_wires = 2 @@ -1344,8 +1312,8 @@ class CRot(Operation): grad_method = "A" parameter_frequencies = [(0.5, 1.0), (0.5, 1.0), (0.5, 1.0)] - def __init__(self, phi, theta, omega, wires, do_queue=None, id=None): - super().__init__(phi, theta, omega, wires=wires, do_queue=do_queue, id=id) + def __init__(self, phi, theta, omega, wires, id=None): + super().__init__(phi, theta, omega, wires=wires, id=id) def label(self, decimals=None, base_label=None, cache=None): return super().label(decimals=decimals, base_label=base_label or "Rot", cache=cache) diff --git a/pennylane/ops/qubit/parametric_ops_multi_qubit.py b/pennylane/ops/qubit/parametric_ops_multi_qubit.py index fd86b3c45be..60fe4f9fffa 100644 --- a/pennylane/ops/qubit/parametric_ops_multi_qubit.py +++ b/pennylane/ops/qubit/parametric_ops_multi_qubit.py @@ -55,10 +55,6 @@ class MultiRZ(Operation): Args: theta (tensor_like or float): rotation angle :math:`\theta` wires (Sequence[int] or int): the wires the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_wires = AnyWires @@ -71,10 +67,10 @@ class MultiRZ(Operation): grad_method = "A" parameter_frequencies = [(1,)] - def __init__(self, theta, wires=None, do_queue=None, id=None): + def __init__(self, theta, wires=None, id=None): wires = Wires(wires) self.hyperparameters["num_wires"] = len(wires) - super().__init__(theta, wires=wires, do_queue=do_queue, id=id) + super().__init__(theta, wires=wires, id=id) @staticmethod def compute_matrix(theta, num_wires): # pylint: disable=arguments-differ @@ -228,10 +224,6 @@ class PauliRot(Operation): theta (float): rotation angle :math:`\theta` pauli_word (string): the Pauli word defining the rotation wires (Sequence[int] or int): the wire the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) **Example** @@ -263,8 +255,8 @@ class PauliRot(Operation): "Z": np.array([[1, 0], [0, 1]]), } - def __init__(self, theta, pauli_word, wires=None, do_queue=None, id=None): - super().__init__(theta, wires=wires, do_queue=do_queue, id=id) + def __init__(self, theta, pauli_word, wires=None, id=None): + super().__init__(theta, wires=wires, id=id) self.hyperparameters["pauli_word"] = pauli_word if not PauliRot._check_pauli_word(pauli_word): @@ -538,10 +530,6 @@ class PCPhase(Operation): phi (float): rotation angle :math:`\phi` dim (int): the dimension of the subspace wires (Iterable[int, str], Wires): the wires the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) **Example:** @@ -588,7 +576,7 @@ def generator(self): mat = np.diag([1 if index < dim else -1 for index in range(shape)]) return qml.Hermitian(mat, wires=self.wires) - def __init__(self, phi, dim, wires, do_queue=None, id=None): + def __init__(self, phi, dim, wires, id=None): wires = wires if isinstance(wires, Wires) else Wires(wires) if not (isinstance(dim, int) and (dim <= 2 ** len(wires))): @@ -597,7 +585,7 @@ def __init__(self, phi, dim, wires, do_queue=None, id=None): f"the max size of the matrix {2 ** len(wires)}. Try adding more wires." ) - super().__init__(phi, wires=wires, do_queue=do_queue, id=id) + super().__init__(phi, wires=wires, id=id) self.hyperparameters["dimension"] = (dim, 2 ** len(wires)) @staticmethod @@ -762,10 +750,6 @@ class IsingXX(Operation): Args: phi (float): the phase angle wires (int): the subsystem the gate acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_wires = 2 @@ -781,8 +765,8 @@ class IsingXX(Operation): def generator(self): return -0.5 * PauliX(wires=self.wires[0]) @ PauliX(wires=self.wires[1]) - def __init__(self, phi, wires, do_queue=None, id=None): - super().__init__(phi, wires=wires, do_queue=do_queue, id=id) + def __init__(self, phi, wires, id=None): + super().__init__(phi, wires=wires, id=id) @staticmethod def compute_matrix(phi): # pylint: disable=arguments-differ @@ -901,10 +885,6 @@ class IsingYY(Operation): Args: phi (float): the phase angle wires (int): the subsystem the gate acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_wires = 2 @@ -920,8 +900,8 @@ class IsingYY(Operation): def generator(self): return -0.5 * PauliY(wires=self.wires[0]) @ PauliY(wires=self.wires[1]) - def __init__(self, phi, wires, do_queue=None, id=None): - super().__init__(phi, wires=wires, do_queue=do_queue, id=id) + def __init__(self, phi, wires, id=None): + super().__init__(phi, wires=wires, id=id) @staticmethod def compute_decomposition(phi, wires): @@ -1047,10 +1027,6 @@ class IsingZZ(Operation): Args: phi (float): the phase angle wires (int): the subsystem the gate acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_wires = 2 @@ -1066,8 +1042,8 @@ class IsingZZ(Operation): def generator(self): return -0.5 * PauliZ(wires=self.wires[0]) @ PauliZ(wires=self.wires[1]) - def __init__(self, phi, wires, do_queue=None, id=None): - super().__init__(phi, wires=wires, do_queue=do_queue, id=id) + def __init__(self, phi, wires, id=None): + super().__init__(phi, wires=wires, id=id) @staticmethod def compute_decomposition(phi, wires): @@ -1233,10 +1209,6 @@ class IsingXY(Operation): Args: phi (float): the phase angle wires (int): the subsystem the gate acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_wires = 2 @@ -1255,8 +1227,8 @@ def generator(self): + PauliY(wires=self.wires[0]) @ PauliY(wires=self.wires[1]) ) - def __init__(self, phi, wires, do_queue=None, id=None): - super().__init__(phi, wires=wires, do_queue=do_queue, id=id) + def __init__(self, phi, wires, id=None): + super().__init__(phi, wires=wires, id=id) @staticmethod def compute_decomposition(phi, wires): @@ -1415,10 +1387,6 @@ class PSWAP(Operation): Args: phi (float): the phase angle wires (int): the subsystem the gate acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_wires = 2 @@ -1428,8 +1396,8 @@ class PSWAP(Operation): grad_method = "A" grad_recipe = ([[0.5, 1, np.pi / 2], [-0.5, 1, -np.pi / 2]],) - def __init__(self, phi, wires, do_queue=None, id=None): - super().__init__(phi, wires=wires, do_queue=do_queue, id=id) + def __init__(self, phi, wires, id=None): + super().__init__(phi, wires=wires, id=id) @staticmethod def compute_decomposition(phi, wires): diff --git a/pennylane/ops/qubit/parametric_ops_single_qubit.py b/pennylane/ops/qubit/parametric_ops_single_qubit.py index f1edb946bb0..c9b19e8d216 100644 --- a/pennylane/ops/qubit/parametric_ops_single_qubit.py +++ b/pennylane/ops/qubit/parametric_ops_single_qubit.py @@ -55,10 +55,6 @@ class RX(Operation): Args: phi (float): rotation angle :math:`\phi` wires (Sequence[int] or int): the wire the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_wires = 1 @@ -75,8 +71,8 @@ class RX(Operation): def generator(self): return -0.5 * PauliX(wires=self.wires) - def __init__(self, phi, wires, do_queue=None, id=None): - super().__init__(phi, wires=wires, do_queue=do_queue, id=id) + def __init__(self, phi, wires, id=None): + super().__init__(phi, wires=wires, id=id) @staticmethod def compute_matrix(theta): # pylint: disable=arguments-differ @@ -154,10 +150,6 @@ class RY(Operation): Args: phi (float): rotation angle :math:`\phi` wires (Sequence[int] or int): the wire the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_wires = 1 @@ -174,8 +166,8 @@ class RY(Operation): def generator(self): return -0.5 * PauliY(wires=self.wires) - def __init__(self, phi, wires, do_queue=None, id=None): - super().__init__(phi, wires=wires, do_queue=do_queue, id=id) + def __init__(self, phi, wires, id=None): + super().__init__(phi, wires=wires, id=id) @staticmethod def compute_matrix(theta): # pylint: disable=arguments-differ @@ -252,10 +244,6 @@ class RZ(Operation): Args: phi (float): rotation angle :math:`\phi` wires (Sequence[int] or int): the wire the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_wires = 1 @@ -272,8 +260,8 @@ class RZ(Operation): def generator(self): return -0.5 * PauliZ(wires=self.wires) - def __init__(self, phi, wires, do_queue=None, id=None): - super().__init__(phi, wires=wires, do_queue=do_queue, id=id) + def __init__(self, phi, wires, id=None): + super().__init__(phi, wires=wires, id=id) @staticmethod def compute_matrix(theta): # pylint: disable=arguments-differ @@ -391,10 +379,6 @@ class PhaseShift(Operation): Args: phi (float): rotation angle :math:`\phi` wires (Sequence[int] or int): the wire the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_wires = 1 @@ -411,8 +395,8 @@ class PhaseShift(Operation): def generator(self): return qml.Projector(np.array([1]), wires=self.wires) - def __init__(self, phi, wires, do_queue=None, id=None): - super().__init__(phi, wires=wires, do_queue=do_queue, id=id) + def __init__(self, phi, wires, id=None): + super().__init__(phi, wires=wires, id=id) def label(self, decimals=None, base_label=None, cache=None): return super().label(decimals=decimals, base_label=base_label or "Rϕ", cache=cache) @@ -569,10 +553,6 @@ class Rot(Operation): theta (float): rotation angle :math:`\theta` omega (float): rotation angle :math:`\omega` wires (Any, Wires): the wire the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_wires = 1 @@ -585,8 +565,8 @@ class Rot(Operation): grad_method = "A" parameter_frequencies = [(1,), (1,), (1,)] - def __init__(self, phi, theta, omega, wires, do_queue=None, id=None): - super().__init__(phi, theta, omega, wires=wires, do_queue=do_queue, id=id) + def __init__(self, phi, theta, omega, wires, id=None): + super().__init__(phi, theta, omega, wires=wires, id=id) @staticmethod def compute_matrix(phi, theta, omega): # pylint: disable=arguments-differ @@ -736,10 +716,6 @@ class U1(Operation): Args: phi (float): rotation angle :math:`\phi` wires (Sequence[int] or int): the wire the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_wires = 1 @@ -755,8 +731,8 @@ class U1(Operation): def generator(self): return qml.Projector(np.array([1]), wires=self.wires) - def __init__(self, phi, wires, do_queue=None, id=None): - super().__init__(phi, wires=wires, do_queue=do_queue, id=id) + def __init__(self, phi, wires, id=None): + super().__init__(phi, wires=wires, id=id) @staticmethod def compute_matrix(phi): # pylint: disable=arguments-differ @@ -867,10 +843,6 @@ class U2(Operation): phi (float): azimuthal angle :math:`\phi` delta (float): quantum phase :math:`\delta` wires (Sequence[int] or int): the subsystem the gate acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_wires = 1 @@ -883,8 +855,8 @@ class U2(Operation): grad_method = "A" parameter_frequencies = [(1,), (1,)] - def __init__(self, phi, delta, wires, do_queue=None, id=None): - super().__init__(phi, delta, wires=wires, do_queue=do_queue, id=id) + def __init__(self, phi, delta, wires, id=None): + super().__init__(phi, delta, wires=wires, id=id) @staticmethod def compute_matrix(phi, delta): # pylint: disable=arguments-differ @@ -1012,10 +984,6 @@ class U3(Operation): phi (float): azimuthal angle :math:`\phi` delta (float): quantum phase :math:`\delta` wires (Sequence[int] or int): the subsystem the gate acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_wires = 1 @@ -1028,8 +996,8 @@ class U3(Operation): grad_method = "A" parameter_frequencies = [(1,), (1,), (1,)] - def __init__(self, theta, phi, delta, wires, do_queue=None, id=None): - super().__init__(theta, phi, delta, wires=wires, do_queue=do_queue, id=id) + def __init__(self, theta, phi, delta, wires, id=None): + super().__init__(theta, phi, delta, wires=wires, id=id) @staticmethod def compute_matrix(theta, phi, delta): # pylint: disable=arguments-differ diff --git a/pennylane/ops/qubit/qchem_ops.py b/pennylane/ops/qubit/qchem_ops.py index d2a56d14e6e..d9606dc5b40 100644 --- a/pennylane/ops/qubit/qchem_ops.py +++ b/pennylane/ops/qubit/qchem_ops.py @@ -134,10 +134,6 @@ class SingleExcitation(Operation): Args: phi (float): rotation angle :math:`\phi` wires (Sequence[int]): the wires the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) **Example** @@ -177,8 +173,8 @@ def generator(self): w1, w2 = self.wires return 0.25 * (qml.PauliX(w1) @ qml.PauliY(w2) - qml.PauliY(w1) @ qml.PauliX(w2)) - def __init__(self, phi, wires, do_queue=None, id=None): - super().__init__(phi, wires=wires, do_queue=do_queue, id=id) + def __init__(self, phi, wires, id=None): + super().__init__(phi, wires=wires, id=id) @staticmethod def compute_matrix(phi): # pylint: disable=arguments-differ @@ -299,10 +295,6 @@ class SingleExcitationMinus(Operation): Args: phi (float): rotation angle :math:`\phi` wires (Sequence[int] or int): the wires the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False```` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ @@ -330,8 +322,8 @@ def generator(self): - qml.PauliZ(w1) @ qml.PauliZ(w2) ) - def __init__(self, phi, wires, do_queue=None, id=None): - super().__init__(phi, wires=wires, do_queue=do_queue, id=id) + def __init__(self, phi, wires, id=None): + super().__init__(phi, wires=wires, id=id) @staticmethod def compute_matrix(phi): # pylint: disable=arguments-differ @@ -432,10 +424,6 @@ class SingleExcitationPlus(Operation): Args: phi (float): rotation angle :math:`\phi` wires (Sequence[int] or int): the wires the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ @@ -463,8 +451,8 @@ def generator(self): + qml.PauliZ(w1) @ qml.PauliZ(w2) ) - def __init__(self, phi, wires, do_queue=None, id=None): - super().__init__(phi, wires=wires, do_queue=do_queue, id=id) + def __init__(self, phi, wires, id=None): + super().__init__(phi, wires=wires, id=id) @staticmethod def compute_matrix(phi): # pylint: disable=arguments-differ @@ -572,10 +560,6 @@ class DoubleExcitation(Operation): Args: phi (float): rotation angle :math:`\phi` wires (Sequence[int]): the wires the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) **Example** @@ -629,8 +613,8 @@ def generator(self): def pow(self, z): return [DoubleExcitation(self.data[0] * z, wires=self.wires)] - def __init__(self, phi, wires, do_queue=None, id=None): - super().__init__(phi, wires=wires, do_queue=do_queue, id=id) + def __init__(self, phi, wires, id=None): + super().__init__(phi, wires=wires, id=id) mask_s = np.zeros((16, 16)) mask_s[3, 12] = -1 @@ -775,10 +759,6 @@ class DoubleExcitationPlus(Operation): Args: phi (float): rotation angle :math:`\phi` wires (Sequence[int]): the wires the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_wires = 4 @@ -804,8 +784,8 @@ def generator(self): H = csr_matrix(-0.5 * G) return qml.SparseHamiltonian(H, wires=self.wires) - def __init__(self, phi, wires, do_queue=None, id=None): - super().__init__(phi, wires=wires, do_queue=do_queue, id=id) + def __init__(self, phi, wires, id=None): + super().__init__(phi, wires=wires, id=id) @staticmethod def compute_matrix(phi): # pylint: disable=arguments-differ @@ -860,10 +840,6 @@ class DoubleExcitationMinus(Operation): Args: phi (float): rotation angle :math:`\phi` wires (Sequence[int]): the wires the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) """ num_wires = 4 @@ -952,10 +928,6 @@ class OrbitalRotation(Operation): Args: phi (float): rotation angle :math:`\phi` wires (Sequence[int]): the wires the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) **Example** @@ -1000,8 +972,8 @@ def generator(self): - (qml.PauliY(w1) @ qml.PauliZ(w2) @ qml.PauliX(w3)) ) - def __init__(self, phi, wires, do_queue=None, id=None): - super().__init__(phi, wires=wires, do_queue=do_queue, id=id) + def __init__(self, phi, wires, id=None): + super().__init__(phi, wires=wires, id=id) mask_s = np.zeros((16, 16)) mask_s[1, 4] = mask_s[2, 8] = mask_s[13, 7] = mask_s[14, 11] = -1 @@ -1145,10 +1117,6 @@ class FermionicSWAP(Operation): Args: phi (float): rotation angle :math:`\phi` wires (Sequence[int]): the wires the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) **Example** @@ -1192,8 +1160,8 @@ def generator(self): + qml.PauliY(w1) @ qml.PauliY(w2) ) - def __init__(self, phi, wires, do_queue=None, id=None): - super().__init__(phi, wires=wires, do_queue=do_queue, id=id) + def __init__(self, phi, wires, id=None): + super().__init__(phi, wires=wires, id=id) @staticmethod def compute_matrix(phi): # pylint: disable=arguments-differ diff --git a/pennylane/ops/qubit/special_unitary.py b/pennylane/ops/qubit/special_unitary.py index aece5555183..501c2ff36e2 100644 --- a/pennylane/ops/qubit/special_unitary.py +++ b/pennylane/ops/qubit/special_unitary.py @@ -204,10 +204,6 @@ class SpecialUnitary(Operation): theta (tensor_like): Pauli coordinates of the exponent :math:`A(\bm{\theta})`. See details below for the order of the Pauli words. wires (Sequence[int] or int): The wire(s) the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) Raises: @@ -406,7 +402,7 @@ class SpecialUnitary(Operation): grad_method = None """Gradient computation method.""" - def __init__(self, theta, wires, do_queue=None, id=None): + def __init__(self, theta, wires, id=None): num_wires = 1 if isinstance(wires, int) else len(wires) self.hyperparameters["num_wires"] = num_wires theta_shape = qml.math.shape(theta) @@ -424,7 +420,7 @@ def __init__(self, theta, wires, do_queue=None, id=None): f"{expected_dim}). The parameters have shape {theta_shape}" ) - super().__init__(theta, wires=wires, do_queue=do_queue, id=id) + super().__init__(theta, wires=wires, id=id) @staticmethod def compute_matrix(theta, num_wires): diff --git a/pennylane/ops/qubit/state_preparation.py b/pennylane/ops/qubit/state_preparation.py index 392b3712003..54fdd010127 100644 --- a/pennylane/ops/qubit/state_preparation.py +++ b/pennylane/ops/qubit/state_preparation.py @@ -46,9 +46,6 @@ class BasisState(StatePrep): array of integers from the set :math:`\{0, 1\}`, i.e., if ``n = np.array([0, 1, 0])``, prepares the state :math:`|010\rangle`. wires (Sequence[int] or int): the wire(s) the operation acts on - do_queue (bool): indicates whether the operator should be recorded when created in - a tape context. This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str): custom label given to an operator instance, can be useful for some applications where the instance has to be identified. @@ -138,9 +135,6 @@ class QubitStateVector(StatePrep): Args: state (array[complex]): a state vector of size 2**len(wires) wires (Sequence[int] or int): the wire(s) the operation acts on - do_queue (bool): indicates whether the operator should be recorded when created in - a tape context. This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str): custom label given to an operator instance, can be useful for some applications where the instance has to be identified. @@ -161,8 +155,8 @@ class QubitStateVector(StatePrep): ndim_params = (1,) """int: Number of dimensions per trainable parameter of the operator.""" - def __init__(self, state, wires, do_queue=None, id=None): - super().__init__(state, wires=wires, do_queue=do_queue, id=id) + def __init__(self, state, wires, id=None): + super().__init__(state, wires=wires, id=id) state = self.parameters[0] if len(state.shape) == 1: @@ -259,9 +253,6 @@ class QubitDensityMatrix(Operation): Args: state (array[complex]): a density matrix of size ``(2**len(wires), 2**len(wires))`` wires (Sequence[int] or int): the wire(s) the operation acts on - do_queue (bool): indicates whether the operator should be recorded when created in - a tape context. This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str): custom label given to an operator instance, can be useful for some applications where the instance has to be identified. diff --git a/pennylane/ops/qutrit/matrix_ops.py b/pennylane/ops/qutrit/matrix_ops.py index 9592b09515e..7fdd4b914cc 100644 --- a/pennylane/ops/qutrit/matrix_ops.py +++ b/pennylane/ops/qutrit/matrix_ops.py @@ -35,9 +35,6 @@ class QutritUnitary(Operation): Args: U (array[complex]): square unitary matrix wires(Sequence[int] or int): the wire(s) the operation acts on - do_queue (bool): indicates whether the operator should be recorded when created in - a tape context. This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str): custom label given to an operator instance, can be useful for some applications where the instance has to be identified. @@ -65,7 +62,7 @@ class QutritUnitary(Operation): grad_method = None """Gradient computation method.""" - def __init__(self, *params, wires, do_queue=None): + def __init__(self, *params, wires): wires = Wires(wires) # For pure QutritUnitary operations (not controlled), check that the number @@ -98,7 +95,7 @@ def __init__(self, *params, wires, do_queue=None): UserWarning, ) - super().__init__(*params, wires=wires, do_queue=do_queue) + super().__init__(*params, wires=wires) @staticmethod def compute_matrix(U): # pylint: disable=arguments-differ @@ -167,9 +164,6 @@ class ControlledQutritUnitary(QutritUnitary): wires (Union[Wires, Sequence[int], or int]): the wire(s) the unitary acts on control_values (str): a string of trits representing the state of the control qutrits to control on (default is the all 2s state) - do_queue (bool): indicates whether the operator should be recorded when created in - a tape context. This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. **Example** @@ -203,14 +197,7 @@ class ControlledQutritUnitary(QutritUnitary): grad_method = None """Gradient computation method.""" - def __init__( - self, - *params, - control_wires=None, - wires=None, - control_values=None, - do_queue=None, - ): + def __init__(self, *params, control_wires=None, wires=None, control_values=None): if control_wires is None: raise ValueError("Must specify control wires") @@ -229,7 +216,7 @@ def __init__( } total_wires = control_wires + wires - super().__init__(*params, wires=total_wires, do_queue=do_queue) + super().__init__(*params, wires=total_wires) @staticmethod def compute_matrix( diff --git a/pennylane/ops/qutrit/non_parametric_ops.py b/pennylane/ops/qutrit/non_parametric_ops.py index b236623c713..7727ad62d42 100644 --- a/pennylane/ops/qutrit/non_parametric_ops.py +++ b/pennylane/ops/qutrit/non_parametric_ops.py @@ -432,10 +432,6 @@ class THadamard(Operation): wires (Sequence[int] or int): the wire the operation acts on subspace (Optional[Sequence[int]]): the 2D subspace on which to apply the operation. This should be `None` for the generalized Hadamard. - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. **Example** @@ -469,13 +465,13 @@ class THadamard(Operation): def label(self, decimals=None, base_label=None, cache=None): return base_label or "TH" - def __init__(self, wires, subspace=None, do_queue=None): + def __init__(self, wires, subspace=None): self._subspace = Operation.validate_subspace(subspace) if subspace is not None else None self._hyperparameters = { "subspace": self.subspace, } - super().__init__(wires=wires, do_queue=do_queue) + super().__init__(wires=wires) @property def subspace(self): diff --git a/pennylane/ops/qutrit/observables.py b/pennylane/ops/qutrit/observables.py index f6004df8441..7f451153e1b 100644 --- a/pennylane/ops/qutrit/observables.py +++ b/pennylane/ops/qutrit/observables.py @@ -59,10 +59,6 @@ class THermitian(Hermitian): Args: A (array): square Hermitian matrix wires (Sequence[int] or int): the wire(s) the operation acts on - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) .. note:: @@ -182,10 +178,6 @@ class GellMann(Observable): wires (Sequence[int] or int): the wire(s) the observable acts on index (int): The index of the Gell-Mann matrix to be used. Must be between 1 and 8 inclusive - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) **Example:** @@ -209,7 +201,7 @@ class GellMann(Observable): num_params = 0 """int: Number of trainable parameters the operator depends on""" - def __init__(self, wires, index=1, do_queue=None, id=None): + def __init__(self, wires, index=1, id=None): if not isinstance(index, int) or index < 1 or index > 8: raise ValueError( "The index of a Gell-Mann observable must be an integer between 1 and 8 inclusive." @@ -217,7 +209,7 @@ def __init__(self, wires, index=1, do_queue=None, id=None): self.hyperparameters["index"] = index - super().__init__(wires=wires, do_queue=do_queue, id=id) + super().__init__(wires=wires, id=id) def label(self, decimals=None, base_label=None, cache=None): return base_label or f"GellMann({self.hyperparameters['index']})" diff --git a/pennylane/ops/qutrit/parametric_ops.py b/pennylane/ops/qutrit/parametric_ops.py index d008ad6516e..b267174143e 100644 --- a/pennylane/ops/qutrit/parametric_ops.py +++ b/pennylane/ops/qutrit/parametric_ops.py @@ -50,10 +50,6 @@ class TRX(Operation): phi (float): rotation angle :math:`\phi` wires (Sequence[int] or int): the wire the operation acts on subspace (Sequence[int]): the 2D subspace on which to apply operation - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional). - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) **Example** @@ -92,12 +88,12 @@ class TRX(Operation): def generator(self): return qml.s_prod(-0.5, qml.GellMann(self.wires, index=self._index_dict[self.subspace])) - def __init__(self, phi, wires, subspace=(0, 1), do_queue=True, id=None): + def __init__(self, phi, wires, subspace=(0, 1), id=None): self._subspace = self.validate_subspace(subspace) self._hyperparameters = { "subspace": self._subspace, } - super().__init__(phi, wires=wires, do_queue=do_queue, id=id) + super().__init__(phi, wires=wires, id=id) @property def subspace(self): @@ -201,10 +197,6 @@ class TRY(Operation): phi (float): rotation angle :math:`\phi` wires (Sequence[int] or int): the wire the operation acts on subspace (Sequence[int]): the 2D subspace on which to apply operation - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue. - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): String representing the operation (optional) **Example** @@ -243,12 +235,12 @@ class TRY(Operation): def generator(self): return qml.s_prod(-0.5, qml.GellMann(self.wires, index=self._index_dict[self.subspace])) - def __init__(self, phi, wires, subspace=(0, 1), do_queue=None, id=None): + def __init__(self, phi, wires, subspace=(0, 1), id=None): self._subspace = self.validate_subspace(subspace) self._hyperparameters = { "subspace": self._subspace, } - super().__init__(phi, wires=wires, do_queue=do_queue, id=id) + super().__init__(phi, wires=wires, id=id) @property def subspace(self): @@ -349,8 +341,6 @@ class TRZ(Operation): phi (float): rotation angle :math:`\phi` wires (Sequence[int] or int): the wire the operation acts on subspace (Sequence[int]): the 2D subspace on which to apply operation - do_queue (bool): Indicates whether the operator should be - immediately pushed into the Operator queue (optional) id (str or None): String representing the operation (optional) **Example** @@ -396,12 +386,12 @@ def generator(self): obs = [qml.GellMann(wires=self.wires, index=3), qml.GellMann(wires=self.wires, index=8)] return qml.dot(coeffs, obs) - def __init__(self, phi, wires, subspace=(0, 1), do_queue=True, id=None): + def __init__(self, phi, wires, subspace=(0, 1), id=None): self._subspace = self.validate_subspace(subspace) self._hyperparameters = { "subspace": self._subspace, } - super().__init__(phi, wires=wires, do_queue=do_queue, id=id) + super().__init__(phi, wires=wires, id=id) @property def subspace(self): diff --git a/pennylane/ops/snapshot.py b/pennylane/ops/snapshot.py index 2d24b352f9d..10d050c6a36 100644 --- a/pennylane/ops/snapshot.py +++ b/pennylane/ops/snapshot.py @@ -33,9 +33,6 @@ class Snapshot(Operation): Args: tag (str or None): An optional custom tag for the snapshot, used to index it in the snapshots dictionary. - do_queue (bool): indicates whether the operator should be recorded when created in - a tape context. This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. **Example** @@ -64,9 +61,9 @@ def circuit(): num_params = 0 grad_method = None - def __init__(self, tag=None, do_queue=None): + def __init__(self, tag=None): self.tag = tag - super().__init__(wires=[], do_queue=do_queue) + super().__init__(wires=[]) def label(self, decimals=None, base_label=None, cache=None): return "|Snap|" diff --git a/pennylane/pulse/parametrized_evolution.py b/pennylane/pulse/parametrized_evolution.py index 31987efddcd..383698decf0 100644 --- a/pennylane/pulse/parametrized_evolution.py +++ b/pennylane/pulse/parametrized_evolution.py @@ -40,7 +40,7 @@ class ParametrizedEvolution(Operation): r""" - ParametrizedEvolution(H, params=None, t=None, return_intermediate=False, complementary=False, do_queue=None, id=None, **odeint_kwargs) + ParametrizedEvolution(H, params=None, t=None, return_intermediate=False, complementary=False, id=None, **odeint_kwargs) Parametrized evolution gate, created by passing a :class:`~.ParametrizedHamiltonian` to the :func:`~.pennylane.evolve` function @@ -69,9 +69,6 @@ class ParametrizedEvolution(Operation): ``ParametrizedEvolution`` and will not affect other gates. To return the matrix at intermediate evolution times, activate ``return_intermediate`` (see below). - do_queue (bool): determines if the scalar product operator will be queued. - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str or None): id for the scalar product operator. Default is None. Keyword Args: @@ -376,7 +373,6 @@ def __init__( return_intermediate: bool = False, complementary: bool = False, dense: bool = None, - do_queue=None, id=None, **odeint_kwargs, ): @@ -407,7 +403,7 @@ def __init__( f"in the Hamiltonian must be the same. Received {len(params)=} parameters but " f"expected {len(H.coeffs_parametrized)} parameters." ) - super().__init__(*params, wires=H.wires, do_queue=do_queue, id=id) + super().__init__(*params, wires=H.wires, id=id) self.hyperparameters["return_intermediate"] = return_intermediate self.hyperparameters["complementary"] = complementary self._check_time_batching() @@ -442,7 +438,6 @@ def __call__( return_intermediate=return_intermediate, complementary=complementary, dense=dense, - do_queue=None, id=self.id, **odeint_kwargs, ) diff --git a/pennylane/tape/qscript.py b/pennylane/tape/qscript.py index cae07c720da..6c943f51411 100644 --- a/pennylane/tape/qscript.py +++ b/pennylane/tape/qscript.py @@ -21,7 +21,6 @@ import copy from collections import Counter from typing import List, Union, Optional, Sequence -import warnings import pennylane as qml from pennylane.measurements import ( @@ -172,10 +171,6 @@ class QuantumScript: """ - do_queue = False - """Whether or not to queue the object. Assumed ``False`` for a vanilla Quantum Script, but may be - True for its child Quantum Tape.""" - def __init__( self, ops=None, @@ -1134,21 +1129,10 @@ def adjoint(self): """ with qml.QueuingManager.stop_recording(): ops_adj = [qml.adjoint(op, lazy=False) for op in reversed(self._ops)] - adj = self.__class__( + return self.__class__( ops=ops_adj, measurements=self.measurements, prep=self._prep, shots=self.shots ) - if self.do_queue is not None: - do_queue_deprecation_warning = ( - "The do_queue keyword argument is deprecated. " - "Instead of setting it to False, use qml.queuing.QueuingManager.stop_recording()" - ) - warnings.warn(do_queue_deprecation_warning, UserWarning) - - if self.do_queue or self.do_queue is None: - qml.QueuingManager.append(adj) - return adj - def unwrap(self): """A context manager that unwraps a quantum script with tensor-like parameters to NumPy arrays. diff --git a/pennylane/tape/tape.py b/pennylane/tape/tape.py index 93834c49157..409cc85ee1b 100644 --- a/pennylane/tape/tape.py +++ b/pennylane/tape/tape.py @@ -17,7 +17,6 @@ # pylint: disable=too-many-instance-attributes,protected-access,too-many-branches,too-many-public-methods, too-many-arguments import copy from threading import RLock -import warnings import pennylane as qml from pennylane.measurements import CountsMP, ProbabilityMP, SampleMP @@ -243,9 +242,6 @@ class QuantumTape(QuantumScript, AnnotatedQueue): Keyword Args: shots (None, int, Sequence[int], ~.Shots): Number and/or batches of shots for execution. Note that this property is still experimental and under development. - do_queue (bool): Whether or not to queue. - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. _update=True (bool): Whether or not to set various properties on initialization. Setting ``_update=False`` reduces computations if the tape is only an intermediary step. @@ -372,23 +368,14 @@ def __init__( measurements=None, prep=None, shots=None, - do_queue=None, _update=True, ): # pylint: disable=too-many-arguments - if do_queue is not None: - do_queue_deprecation_warning = ( - "The do_queue keyword argument is deprecated. " - "Instead of setting it to False, use qml.queuing.QueuingManager.stop_recording()" - ) - warnings.warn(do_queue_deprecation_warning, UserWarning) - self.do_queue = do_queue AnnotatedQueue.__init__(self) QuantumScript.__init__(self, ops, measurements, prep, shots, _update=_update) def __enter__(self): QuantumTape._lock.acquire() - if self.do_queue or self.do_queue is None: - QueuingManager.append(self) + QueuingManager.append(self) QueuingManager.add_active_queue(self) return self @@ -397,6 +384,11 @@ def __exit__(self, exception_type, exception_value, traceback): QuantumTape._lock.release() self._process_queue() + def adjoint(self): + adjoint_tape = super().adjoint() + QueuingManager.append(adjoint_tape) + return adjoint_tape + # ======================================================== # construction methods # ======================================================== diff --git a/pennylane/templates/embeddings/amplitude.py b/pennylane/templates/embeddings/amplitude.py index 424f6058ec5..5ea33431a37 100644 --- a/pennylane/templates/embeddings/amplitude.py +++ b/pennylane/templates/embeddings/amplitude.py @@ -51,9 +51,6 @@ class AmplitudeEmbedding(Operation): wires (Any or Iterable[Any]): wires that the template acts on pad_with (float or complex): if not None, the input is padded with this constant to size :math:`2^n` normalize (bool): whether to automatically normalize the features - do_queue (bool): indicates whether the operator should be recorded when created in - a tape context. This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str): custom label given to an operator instance, can be useful for some applications where the instance has to be identified. @@ -126,12 +123,12 @@ def circuit(f=None): num_wires = AnyWires grad_method = None - def __init__(self, features, wires, pad_with=None, normalize=False, do_queue=None, id=None): + def __init__(self, features, wires, pad_with=None, normalize=False, id=None): wires = Wires(wires) self.pad_with = pad_with self.normalize = normalize features = self._preprocess(features, wires, pad_with, normalize) - super().__init__(features, wires=wires, do_queue=do_queue, id=id) + super().__init__(features, wires=wires, id=id) @property def num_params(self): diff --git a/pennylane/templates/embeddings/angle.py b/pennylane/templates/embeddings/angle.py index 3aad0d97dee..492554d4b84 100644 --- a/pennylane/templates/embeddings/angle.py +++ b/pennylane/templates/embeddings/angle.py @@ -43,9 +43,6 @@ class AngleEmbedding(Operation): with :math:`N\leq n` wires (Any or Iterable[Any]): wires that the template acts on rotation (str): type of rotations used - do_queue (bool): indicates whether the operator should be recorded when created in - a tape context. This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str): custom label given to an operator instance, can be useful for some applications where the instance has to be identified. @@ -78,7 +75,7 @@ def circuit(feature_vector): num_wires = AnyWires grad_method = None - def __init__(self, features, wires, rotation="X", do_queue=None, id=None): + def __init__(self, features, wires, rotation="X", id=None): if rotation not in ROT: raise ValueError(f"Rotation option {rotation} not recognized.") @@ -92,7 +89,7 @@ def __init__(self, features, wires, rotation="X", do_queue=None, id=None): self._hyperparameters = {"rotation": ROT[rotation]} wires = wires[:n_features] - super().__init__(features, wires=wires, do_queue=do_queue, id=id) + super().__init__(features, wires=wires, id=id) @property def num_params(self): diff --git a/pennylane/templates/embeddings/basis.py b/pennylane/templates/embeddings/basis.py index fb933187f7e..887506ce611 100644 --- a/pennylane/templates/embeddings/basis.py +++ b/pennylane/templates/embeddings/basis.py @@ -71,7 +71,7 @@ def circuit(feature_vector): num_wires = AnyWires grad_method = None - def __init__(self, features, wires, do_queue=None, id=None): + def __init__(self, features, wires, id=None): if isinstance(features, list): features = qml.math.stack(features) @@ -104,7 +104,7 @@ def __init__(self, features, wires, do_queue=None, id=None): self._hyperparameters = {"basis_state": features} - super().__init__(wires=wires, do_queue=do_queue, id=id) + super().__init__(wires=wires, id=id) @property def num_params(self): diff --git a/pennylane/templates/embeddings/displacement.py b/pennylane/templates/embeddings/displacement.py index 53fb0a0071d..0bb8ffa9d9a 100644 --- a/pennylane/templates/embeddings/displacement.py +++ b/pennylane/templates/embeddings/displacement.py @@ -100,7 +100,7 @@ def circuit(feature_vector): num_wires = AnyWires grad_method = None - def __init__(self, features, wires, method="amplitude", c=0.1, do_queue=None, id=None): + def __init__(self, features, wires, method="amplitude", c=0.1, id=None): shape = qml.math.shape(features) constants = [c] * shape[0] constants = qml.math.convert_like(constants, features) @@ -121,7 +121,7 @@ def __init__(self, features, wires, method="amplitude", c=0.1, do_queue=None, id else: raise ValueError(f"did not recognize method {method}") - super().__init__(pars, wires=wires, do_queue=do_queue, id=id) + super().__init__(pars, wires=wires, id=id) @property def num_params(self): diff --git a/pennylane/templates/embeddings/iqp.py b/pennylane/templates/embeddings/iqp.py index 42c1a2b6434..f3ce507c624 100644 --- a/pennylane/templates/embeddings/iqp.py +++ b/pennylane/templates/embeddings/iqp.py @@ -166,7 +166,7 @@ def circuit(features, pattern): num_wires = AnyWires grad_method = None - def __init__(self, features, wires, n_repeats=1, pattern=None, do_queue=None, id=None): + def __init__(self, features, wires, n_repeats=1, pattern=None, id=None): shape = qml.math.shape(features) if len(shape) not in {1, 2}: @@ -185,7 +185,7 @@ def __init__(self, features, wires, n_repeats=1, pattern=None, do_queue=None, id self._hyperparameters = {"pattern": pattern, "n_repeats": n_repeats} - super().__init__(features, wires=wires, do_queue=do_queue, id=id) + super().__init__(features, wires=wires, id=id) @property def num_params(self): diff --git a/pennylane/templates/embeddings/qaoaembedding.py b/pennylane/templates/embeddings/qaoaembedding.py index e1de679bdcb..851224bc761 100644 --- a/pennylane/templates/embeddings/qaoaembedding.py +++ b/pennylane/templates/embeddings/qaoaembedding.py @@ -159,7 +159,7 @@ def circuit(weights, f=None): num_wires = AnyWires grad_method = None - def __init__(self, features, weights, wires, local_field="Y", do_queue=None, id=None): + def __init__(self, features, weights, wires, local_field="Y", id=None): if local_field == "Z": local_field = qml.RZ elif local_field == "X": @@ -203,7 +203,7 @@ def __init__(self, features, weights, wires, local_field="Y", do_queue=None, id= raise ValueError(f"Weights tensor must be of shape {exp_shape}; got {shape}") self._hyperparameters = {"local_field": local_field} - super().__init__(features, weights, wires=wires, do_queue=do_queue, id=id) + super().__init__(features, weights, wires=wires, id=id) @property def num_params(self): diff --git a/pennylane/templates/embeddings/squeezing.py b/pennylane/templates/embeddings/squeezing.py index 7a72175ab00..7ff22a3692c 100644 --- a/pennylane/templates/embeddings/squeezing.py +++ b/pennylane/templates/embeddings/squeezing.py @@ -102,7 +102,7 @@ def circuit(feature_vector): num_wires = AnyWires grad_method = None - def __init__(self, features, wires, method="amplitude", c=0.1, do_queue=None, id=None): + def __init__(self, features, wires, method="amplitude", c=0.1, id=None): shape = qml.math.shape(features) constants = [c] * shape[0] constants = qml.math.convert_like(constants, features) @@ -123,7 +123,7 @@ def __init__(self, features, wires, method="amplitude", c=0.1, do_queue=None, id else: raise ValueError(f"did not recognize method {method}") - super().__init__(pars, wires=wires, do_queue=do_queue, id=id) + super().__init__(pars, wires=wires, id=id) @property def num_params(self): diff --git a/pennylane/templates/layers/basic_entangler.py b/pennylane/templates/layers/basic_entangler.py index 8792ef401fb..1191cfe1365 100644 --- a/pennylane/templates/layers/basic_entangler.py +++ b/pennylane/templates/layers/basic_entangler.py @@ -125,7 +125,7 @@ def circuit(weights): num_wires = AnyWires grad_method = None - def __init__(self, weights, wires=None, rotation=None, do_queue=None, id=None): + def __init__(self, weights, wires=None, rotation=None, id=None): # convert weights to numpy array if weights is list otherwise keep unchanged interface = qml.math.get_interface(weights) weights = qml.math.asarray(weights, like=interface) @@ -144,7 +144,7 @@ def __init__(self, weights, wires=None, rotation=None, do_queue=None, id=None): ) self._hyperparameters = {"rotation": rotation or qml.RX} - super().__init__(weights, wires=wires, do_queue=do_queue, id=id) + super().__init__(weights, wires=wires, id=id) @property def num_params(self): diff --git a/pennylane/templates/layers/cv_neural_net.py b/pennylane/templates/layers/cv_neural_net.py index 0c2f7f94687..07f7d099563 100644 --- a/pennylane/templates/layers/cv_neural_net.py +++ b/pennylane/templates/layers/cv_neural_net.py @@ -98,7 +98,6 @@ def __init__( phi_a, k, wires, - do_queue=None, id=None, ): n_wires = len(wires) @@ -135,7 +134,6 @@ def __init__( phi_a, k, wires=wires, - do_queue=do_queue, id=id, ) diff --git a/pennylane/templates/layers/gate_fabric.py b/pennylane/templates/layers/gate_fabric.py index 52eb67fed5b..4ab1979e89a 100644 --- a/pennylane/templates/layers/gate_fabric.py +++ b/pennylane/templates/layers/gate_fabric.py @@ -173,7 +173,7 @@ def ansatz(weights): num_wires = AnyWires grad_method = None - def __init__(self, weights, wires, init_state, include_pi=False, do_queue=None, id=None): + def __init__(self, weights, wires, init_state, include_pi=False, id=None): if len(wires) < 4: raise ValueError( f"This template requires the number of qubits to be greater than four; got wires {wires}" @@ -204,7 +204,7 @@ def __init__(self, weights, wires, init_state, include_pi=False, do_queue=None, "include_pi": include_pi, } - super().__init__(weights, wires=wires, do_queue=do_queue, id=id) + super().__init__(weights, wires=wires, id=id) @property def num_params(self): diff --git a/pennylane/templates/layers/particle_conserving_u1.py b/pennylane/templates/layers/particle_conserving_u1.py index 1386566b6c0..24928ce0d7b 100644 --- a/pennylane/templates/layers/particle_conserving_u1.py +++ b/pennylane/templates/layers/particle_conserving_u1.py @@ -242,7 +242,7 @@ class ParticleConservingU1(Operation): num_wires = AnyWires grad_method = None - def __init__(self, weights, wires, init_state=None, do_queue=None, id=None): + def __init__(self, weights, wires, init_state=None, id=None): if len(wires) < 2: raise ValueError( f"Expected the number of qubits to be greater than one; " f"got wires {wires}" @@ -265,7 +265,7 @@ def __init__(self, weights, wires, init_state=None, do_queue=None, id=None): self._hyperparameters = {"init_state": qml.math.toarray(init_state)} - super().__init__(weights, wires=wires, do_queue=do_queue, id=id) + super().__init__(weights, wires=wires, id=id) @property def num_params(self): diff --git a/pennylane/templates/layers/particle_conserving_u2.py b/pennylane/templates/layers/particle_conserving_u2.py index 62473d32a56..d1a2b8d2ca1 100644 --- a/pennylane/templates/layers/particle_conserving_u2.py +++ b/pennylane/templates/layers/particle_conserving_u2.py @@ -152,7 +152,7 @@ class ParticleConservingU2(Operation): num_wires = AnyWires grad_method = None - def __init__(self, weights, wires, init_state=None, do_queue=None, id=None): + def __init__(self, weights, wires, init_state=None, id=None): if len(wires) < 2: raise ValueError( f"This template requires the number of qubits to be greater than one;" @@ -171,7 +171,7 @@ def __init__(self, weights, wires, init_state=None, do_queue=None, id=None): self._hyperparameters = {"init_state": qml.math.toarray(init_state)} - super().__init__(weights, wires=wires, do_queue=do_queue, id=id) + super().__init__(weights, wires=wires, id=id) @property def num_params(self): diff --git a/pennylane/templates/layers/random.py b/pennylane/templates/layers/random.py index 4e4065ad6b3..4b6cd4359fb 100644 --- a/pennylane/templates/layers/random.py +++ b/pennylane/templates/layers/random.py @@ -176,7 +176,6 @@ def __init__( imprimitive=None, rotations=None, seed=42, - do_queue=None, id=None, ): shape = qml.math.shape(weights) @@ -190,7 +189,7 @@ def __init__( "seed": seed, } - super().__init__(weights, wires=wires, do_queue=do_queue, id=id) + super().__init__(weights, wires=wires, id=id) @property def num_params(self): diff --git a/pennylane/templates/layers/simplified_two_design.py b/pennylane/templates/layers/simplified_two_design.py index aed462db4e4..895eb080cc3 100644 --- a/pennylane/templates/layers/simplified_two_design.py +++ b/pennylane/templates/layers/simplified_two_design.py @@ -101,7 +101,7 @@ def circuit(init_weights, weights): num_wires = AnyWires grad_method = None - def __init__(self, initial_layer_weights, weights, wires, do_queue=None, id=None): + def __init__(self, initial_layer_weights, weights, wires, id=None): shape = qml.math.shape(weights) if len(shape) > 1: @@ -123,7 +123,7 @@ def __init__(self, initial_layer_weights, weights, wires, do_queue=None, id=None self.n_layers = shape[0] - super().__init__(initial_layer_weights, weights, wires=wires, do_queue=do_queue, id=id) + super().__init__(initial_layer_weights, weights, wires=wires, id=id) @property def num_params(self): diff --git a/pennylane/templates/layers/strongly_entangling.py b/pennylane/templates/layers/strongly_entangling.py index d543ca4d449..5f4fd8dc825 100644 --- a/pennylane/templates/layers/strongly_entangling.py +++ b/pennylane/templates/layers/strongly_entangling.py @@ -132,7 +132,7 @@ def circuit(parameters): num_wires = AnyWires grad_method = None - def __init__(self, weights, wires, ranges=None, imprimitive=None, do_queue=None, id=None): + def __init__(self, weights, wires, ranges=None, imprimitive=None, id=None): shape = qml.math.shape(weights)[-3:] if shape[1] != len(wires): @@ -162,7 +162,7 @@ def __init__(self, weights, wires, ranges=None, imprimitive=None, do_queue=None, self._hyperparameters = {"ranges": ranges, "imprimitive": imprimitive or qml.CNOT} - super().__init__(weights, wires=wires, do_queue=do_queue, id=id) + super().__init__(weights, wires=wires, id=id) @property def num_params(self): diff --git a/pennylane/templates/state_preparations/arbitrary_state_preparation.py b/pennylane/templates/state_preparations/arbitrary_state_preparation.py index 865d21948a2..d5de64c9694 100644 --- a/pennylane/templates/state_preparations/arbitrary_state_preparation.py +++ b/pennylane/templates/state_preparations/arbitrary_state_preparation.py @@ -82,14 +82,14 @@ def vqe(weights): num_wires = AnyWires grad_method = None - def __init__(self, weights, wires, do_queue=None, id=None): + def __init__(self, weights, wires, id=None): shape = qml.math.shape(weights) if shape != (2 ** (len(wires) + 1) - 2,): raise ValueError( f"Weights tensor must be of shape {(2 ** (len(wires) + 1) - 2,)}; got {shape}." ) - super().__init__(weights, wires=wires, do_queue=do_queue, id=id) + super().__init__(weights, wires=wires, id=id) @property def num_params(self): diff --git a/pennylane/templates/state_preparations/basis.py b/pennylane/templates/state_preparations/basis.py index c5a45f49fe0..550b5c10a6e 100644 --- a/pennylane/templates/state_preparations/basis.py +++ b/pennylane/templates/state_preparations/basis.py @@ -55,7 +55,7 @@ def circuit(basis_state): num_wires = AnyWires grad_method = None - def __init__(self, basis_state, wires, do_queue=None, id=None): + def __init__(self, basis_state, wires, id=None): basis_state = qml.math.stack(basis_state) # check if the `basis_state` param is batched @@ -86,7 +86,7 @@ def __init__(self, basis_state, wires, do_queue=None, id=None): # TODO: basis_state should be a hyperparameter, not a trainable parameter. # However, this breaks a test that ensures compatibility with batch_transform. # The transform should be rewritten to support hyperparameters as well. - super().__init__(basis_state, wires=wires, do_queue=do_queue, id=id) + super().__init__(basis_state, wires=wires, id=id) @staticmethod def compute_decomposition(basis_state, wires): # pylint: disable=arguments-differ diff --git a/pennylane/templates/state_preparations/basis_qutrit.py b/pennylane/templates/state_preparations/basis_qutrit.py index bd9dfedb01d..5fa0d9fbf12 100644 --- a/pennylane/templates/state_preparations/basis_qutrit.py +++ b/pennylane/templates/state_preparations/basis_qutrit.py @@ -54,7 +54,7 @@ def circuit(basis_state, obs): num_wires = AnyWires grad_method = None - def __init__(self, basis_state, wires, do_queue=True, id=None): + def __init__(self, basis_state, wires, id=None): basis_state = qml.math.stack(basis_state) # check if the `basis_state` param is batched @@ -84,7 +84,7 @@ def __init__(self, basis_state, wires, do_queue=True, id=None): # TODO: basis_state should be a hyperparameter, not a trainable parameter. # However, this breaks a test that ensures compatibility with batch_transform. # The transform should be rewritten to support hyperparameters as well. - super().__init__(basis_state, wires=wires, do_queue=do_queue, id=id) + super().__init__(basis_state, wires=wires, id=id) @staticmethod def compute_decomposition(basis_state, wires): # pylint: disable=arguments-differ diff --git a/pennylane/templates/state_preparations/mottonen.py b/pennylane/templates/state_preparations/mottonen.py index ab512e73aa6..1818bd7bac5 100644 --- a/pennylane/templates/state_preparations/mottonen.py +++ b/pennylane/templates/state_preparations/mottonen.py @@ -287,7 +287,7 @@ def circuit(state): num_wires = AnyWires grad_method = None - def __init__(self, state_vector, wires, do_queue=None, id=None): + def __init__(self, state_vector, wires, id=None): # check if the `state_vector` param is batched batched = len(qml.math.shape(state_vector)) > 1 @@ -315,7 +315,7 @@ def __init__(self, state_vector, wires, do_queue=None, id=None): f"State vectors have to be of norm 1.0, vector {i} has norm {norm}" ) - super().__init__(state_vector, wires=wires, do_queue=do_queue, id=id) + super().__init__(state_vector, wires=wires, id=id) @property def num_params(self): diff --git a/pennylane/templates/subroutines/all_singles_doubles.py b/pennylane/templates/subroutines/all_singles_doubles.py index c2d21da82dc..cce3759ee80 100644 --- a/pennylane/templates/subroutines/all_singles_doubles.py +++ b/pennylane/templates/subroutines/all_singles_doubles.py @@ -115,9 +115,7 @@ def circuit(weights, hf_state, singles, doubles): num_wires = AnyWires grad_method = None - def __init__( - self, weights, wires, hf_state, singles=None, doubles=None, do_queue=None, id=None - ): + def __init__(self, weights, wires, hf_state, singles=None, doubles=None, id=None): if len(wires) < 2: raise ValueError( f"The number of qubits (wires) can not be less than 2; got len(wires) = {len(wires)}" @@ -151,7 +149,7 @@ def __init__( if hf_state.dtype != np.dtype("int"): raise ValueError(f"Elements of 'hf_state' must be integers; got {hf_state.dtype}") - super().__init__(weights, wires=wires, do_queue=do_queue, id=id) + super().__init__(weights, wires=wires, id=id) @property def num_params(self): diff --git a/pennylane/templates/subroutines/approx_time_evolution.py b/pennylane/templates/subroutines/approx_time_evolution.py index 6307b191e81..ec305cd1b1b 100644 --- a/pennylane/templates/subroutines/approx_time_evolution.py +++ b/pennylane/templates/subroutines/approx_time_evolution.py @@ -101,7 +101,7 @@ def circuit(time): num_wires = AnyWires grad_method = None - def __init__(self, hamiltonian, time, n, do_queue=None, id=None): + def __init__(self, hamiltonian, time, n, id=None): if not isinstance(hamiltonian, qml.Hamiltonian): raise ValueError( f"hamiltonian must be of type pennylane.Hamiltonian, got {type(hamiltonian).__name__}" @@ -114,7 +114,7 @@ def __init__(self, hamiltonian, time, n, do_queue=None, id=None): self._hyperparameters = {"hamiltonian": hamiltonian, "n": n} # trainable parameters are passed to the base init method - super().__init__(*hamiltonian.data, time, wires=wires, do_queue=do_queue, id=id) + super().__init__(*hamiltonian.data, time, wires=wires, id=id) @staticmethod def compute_decomposition( diff --git a/pennylane/templates/subroutines/arbitrary_unitary.py b/pennylane/templates/subroutines/arbitrary_unitary.py index 9b9bac6bc76..2bb50b5fe89 100644 --- a/pennylane/templates/subroutines/arbitrary_unitary.py +++ b/pennylane/templates/subroutines/arbitrary_unitary.py @@ -94,14 +94,14 @@ def arbitrary_nearest_neighbour_interaction(weights, wires): num_wires = AnyWires grad_method = None - def __init__(self, weights, wires, do_queue=None, id=None): + def __init__(self, weights, wires, id=None): shape = qml.math.shape(weights) if shape != (4 ** len(wires) - 1,): raise ValueError( f"Weights tensor must be of shape {(4 ** len(wires) - 1,)}; got {shape}." ) - super().__init__(weights, wires=wires, do_queue=do_queue, id=id) + super().__init__(weights, wires=wires, id=id) @property def num_params(self): diff --git a/pennylane/templates/subroutines/basis_rotation.py b/pennylane/templates/subroutines/basis_rotation.py index fe11735e612..fcaafe82ec6 100644 --- a/pennylane/templates/subroutines/basis_rotation.py +++ b/pennylane/templates/subroutines/basis_rotation.py @@ -99,7 +99,7 @@ class BasisRotation(Operation): num_wires = AnyWires grad_method = None - def __init__(self, wires, unitary_matrix, check=False, do_queue=None, id=None): + def __init__(self, wires, unitary_matrix, check=False, id=None): M, N = unitary_matrix.shape if M != N: raise ValueError( @@ -118,7 +118,7 @@ def __init__(self, wires, unitary_matrix, check=False, do_queue=None, id=None): "unitary_matrix": unitary_matrix, } - super().__init__(wires=wires, do_queue=do_queue, id=id) + super().__init__(wires=wires, id=id) @property def num_params(self): diff --git a/pennylane/templates/subroutines/commuting_evolution.py b/pennylane/templates/subroutines/commuting_evolution.py index 007c3f684a7..7b04b0cdb0d 100644 --- a/pennylane/templates/subroutines/commuting_evolution.py +++ b/pennylane/templates/subroutines/commuting_evolution.py @@ -106,7 +106,7 @@ def circuit(time): num_wires = AnyWires grad_method = None - def __init__(self, hamiltonian, time, frequencies=None, shifts=None, do_queue=None, id=None): + def __init__(self, hamiltonian, time, frequencies=None, shifts=None, id=None): # pylint: disable=import-outside-toplevel from pennylane.gradients.general_shift_rules import ( generate_shift_rule, @@ -129,9 +129,7 @@ def __init__(self, hamiltonian, time, frequencies=None, shifts=None, do_queue=No "shifts": shifts, } - super().__init__( - time, *hamiltonian.parameters, wires=hamiltonian.wires, do_queue=do_queue, id=id - ) + super().__init__(time, *hamiltonian.parameters, wires=hamiltonian.wires, id=id) @staticmethod def compute_decomposition( diff --git a/pennylane/templates/subroutines/fermionic_double_excitation.py b/pennylane/templates/subroutines/fermionic_double_excitation.py index 92c18394374..611658bc391 100644 --- a/pennylane/templates/subroutines/fermionic_double_excitation.py +++ b/pennylane/templates/subroutines/fermionic_double_excitation.py @@ -497,7 +497,7 @@ def circuit(weight, wires1=None, wires2=None): grad_method = "A" parameter_frequencies = [(0.5, 1.0)] - def __init__(self, weight, wires1=None, wires2=None, do_queue=None, id=None): + def __init__(self, weight, wires1=None, wires2=None, id=None): if len(wires1) < 2: raise ValueError( f"expected at least two wires representing the occupied orbitals; " @@ -522,7 +522,7 @@ def __init__(self, weight, wires1=None, wires2=None, do_queue=None, id=None): } wires = wires1 + wires2 - super().__init__(weight, wires=wires, do_queue=do_queue, id=id) + super().__init__(weight, wires=wires, id=id) @property def num_params(self): diff --git a/pennylane/templates/subroutines/fermionic_single_excitation.py b/pennylane/templates/subroutines/fermionic_single_excitation.py index ba9775d42be..01e3923fdee 100644 --- a/pennylane/templates/subroutines/fermionic_single_excitation.py +++ b/pennylane/templates/subroutines/fermionic_single_excitation.py @@ -116,7 +116,7 @@ def circuit(weight, wires=None): grad_method = "A" parameter_frequencies = [(0.5, 1.0)] - def __init__(self, weight, wires=None, do_queue=None, id=None): + def __init__(self, weight, wires=None, id=None): if len(wires) < 2: raise ValueError(f"expected at least two wires; got {len(wires)}") @@ -124,7 +124,7 @@ def __init__(self, weight, wires=None, do_queue=None, id=None): if shape != (): raise ValueError(f"Weight must be a scalar tensor {()}; got shape {shape}.") - super().__init__(weight, wires=wires, do_queue=do_queue, id=id) + super().__init__(weight, wires=wires, id=id) @property def num_params(self): diff --git a/pennylane/templates/subroutines/flip_sign.py b/pennylane/templates/subroutines/flip_sign.py index 41a18566d7f..ed1328440e1 100644 --- a/pennylane/templates/subroutines/flip_sign.py +++ b/pennylane/templates/subroutines/flip_sign.py @@ -66,7 +66,7 @@ def circuit(): num_wires = AnyWires - def __init__(self, n, wires, do_queue=None, id=None): + def __init__(self, n, wires, id=None): if not isinstance(wires, int) and len(wires) == 0: raise ValueError("expected at least one wire representing the qubit ") @@ -88,7 +88,7 @@ def __init__(self, n, wires, do_queue=None, id=None): ) self._hyperparameters = {"arr_bin": n} - super().__init__(wires=wires, do_queue=do_queue, id=id) + super().__init__(wires=wires, id=id) @staticmethod def to_list(n, n_wires): diff --git a/pennylane/templates/subroutines/grover.py b/pennylane/templates/subroutines/grover.py index 59439aac32e..9a16423c9a4 100644 --- a/pennylane/templates/subroutines/grover.py +++ b/pennylane/templates/subroutines/grover.py @@ -101,13 +101,13 @@ def GroverSearch(num_iterations=1): num_wires = AnyWires grad_method = None - def __init__(self, wires=None, work_wires=None, do_queue=None, id=None): + def __init__(self, wires=None, work_wires=None, id=None): if (not hasattr(wires, "__len__")) or (len(wires) < 2): raise ValueError("GroverOperator must have at least two wires provided.") self._hyperparameters = {"n_wires": len(wires), "work_wires": work_wires} - super().__init__(wires=wires, do_queue=do_queue, id=id) + super().__init__(wires=wires, id=id) @property def num_params(self): diff --git a/pennylane/templates/subroutines/hilbert_schmidt.py b/pennylane/templates/subroutines/hilbert_schmidt.py index 73291bf7a63..321453a1faa 100644 --- a/pennylane/templates/subroutines/hilbert_schmidt.py +++ b/pennylane/templates/subroutines/hilbert_schmidt.py @@ -96,7 +96,7 @@ def cost_hst(parameters, v_function, v_wires, u_tape): num_wires = AnyWires grad_method = None - def __init__(self, *params, v_function, v_wires, u_tape, do_queue=None, id=None): + def __init__(self, *params, v_function, v_wires, u_tape, id=None): self._num_params = len(params) if not isinstance(u_tape, qml.tape.QuantumScript): @@ -128,7 +128,7 @@ def __init__(self, *params, v_function, v_wires, u_tape, do_queue=None, id=None) wires = qml.wires.Wires(u_wires + v_wires) - super().__init__(*params, wires=wires, do_queue=do_queue, id=id) + super().__init__(*params, wires=wires, id=id) @property def num_params(self): diff --git a/pennylane/templates/subroutines/interferometer.py b/pennylane/templates/subroutines/interferometer.py index 54edfcb60f3..2c749a91e4f 100644 --- a/pennylane/templates/subroutines/interferometer.py +++ b/pennylane/templates/subroutines/interferometer.py @@ -169,7 +169,6 @@ def __init__( wires, mesh="rectangular", beamsplitter="pennylane", - do_queue=None, id=None, ): wires = Wires(wires) @@ -193,7 +192,7 @@ def __init__( "mesh": mesh, "beamsplitter": beamsplitter, } - super().__init__(theta, phi, varphi, wires=wires, do_queue=do_queue, id=id) + super().__init__(theta, phi, varphi, wires=wires, id=id) @staticmethod def compute_decomposition( diff --git a/pennylane/templates/subroutines/kupccgsd.py b/pennylane/templates/subroutines/kupccgsd.py index 2229cde5868..a3723162f3c 100644 --- a/pennylane/templates/subroutines/kupccgsd.py +++ b/pennylane/templates/subroutines/kupccgsd.py @@ -203,7 +203,7 @@ def ansatz(weights): num_wires = AnyWires grad_method = None - def __init__(self, weights, wires, k=1, delta_sz=0, init_state=None, do_queue=None, id=None): + def __init__(self, weights, wires, k=1, delta_sz=0, init_state=None, id=None): if len(wires) < 4: raise ValueError(f"Requires at least four wires; got {len(wires)} wires.") if len(wires) % 2: @@ -237,7 +237,7 @@ def __init__(self, weights, wires, k=1, delta_sz=0, init_state=None, do_queue=No "d_wires": d_wires, "k": k, } - super().__init__(weights, wires=wires, do_queue=do_queue, id=id) + super().__init__(weights, wires=wires, id=id) @property def num_params(self): diff --git a/pennylane/templates/subroutines/permute.py b/pennylane/templates/subroutines/permute.py index a25797fb773..16444affcf9 100644 --- a/pennylane/templates/subroutines/permute.py +++ b/pennylane/templates/subroutines/permute.py @@ -141,7 +141,7 @@ def circuit(): num_wires = AnyWires grad_method = None - def __init__(self, permutation, wires, do_queue=None, id=None): + def __init__(self, permutation, wires, id=None): if len(permutation) <= 1 or len(wires) <= 1: raise ValueError("Permutations must involve at least 2 qubits.") @@ -159,7 +159,7 @@ def __init__(self, permutation, wires, do_queue=None, id=None): raise ValueError(f"Cannot permute wire {label} not present in wire set.") self._hyperparameters = {"permutation": permutation} - super().__init__(wires=wires, do_queue=do_queue, id=id) + super().__init__(wires=wires, id=id) @property def num_params(self): diff --git a/pennylane/templates/subroutines/qft.py b/pennylane/templates/subroutines/qft.py index e4e16159258..155096170c8 100644 --- a/pennylane/templates/subroutines/qft.py +++ b/pennylane/templates/subroutines/qft.py @@ -66,10 +66,10 @@ def circuit_qft(basis_state): num_wires = AnyWires grad_method = None - def __init__(self, *params, wires=None, do_queue=None, id=None): + def __init__(self, *params, wires=None, id=None): wires = qml.wires.Wires(wires) self.hyperparameters["n_wires"] = len(wires) - super().__init__(*params, wires=wires, do_queue=do_queue, id=id) + super().__init__(*params, wires=wires, id=id) @property def num_params(self): diff --git a/pennylane/templates/subroutines/qmc.py b/pennylane/templates/subroutines/qmc.py index 37a263cbdc8..beaee055408 100644 --- a/pennylane/templates/subroutines/qmc.py +++ b/pennylane/templates/subroutines/qmc.py @@ -339,7 +339,7 @@ def circuit(): num_wires = AnyWires grad_method = None - def __init__(self, probs, func, target_wires, estimation_wires, do_queue=None, id=None): + def __init__(self, probs, func, target_wires, estimation_wires, id=None): if isinstance(probs, np.ndarray) and probs.ndim != 1: raise ValueError("The probability distribution must be specified as a flat array") @@ -367,7 +367,7 @@ def __init__(self, probs, func, target_wires, estimation_wires, do_queue=None, i A = probs_to_unitary(probs) R = func_to_unitary(func, dim_p) Q = make_Q(A, R) - super().__init__(A, R, Q, wires=wires, do_queue=do_queue, id=id) + super().__init__(A, R, Q, wires=wires, id=id) @property def num_params(self): diff --git a/pennylane/templates/subroutines/qpe.py b/pennylane/templates/subroutines/qpe.py index 9c87d65317f..7ea03964cd1 100644 --- a/pennylane/templates/subroutines/qpe.py +++ b/pennylane/templates/subroutines/qpe.py @@ -139,7 +139,7 @@ def circuit(): num_wires = AnyWires grad_method = None - def __init__(self, unitary, target_wires=None, estimation_wires=None, do_queue=None, id=None): + def __init__(self, unitary, target_wires=None, estimation_wires=None, id=None): if isinstance(unitary, Operator): # If the unitary is expressed in terms of operators, do not provide target wires if target_wires is not None: @@ -177,7 +177,7 @@ def __init__(self, unitary, target_wires=None, estimation_wires=None, do_queue=N "estimation_wires": estimation_wires, } - super().__init__(wires=wires, do_queue=do_queue, id=id) + super().__init__(wires=wires, id=id) @property def target_wires(self): diff --git a/pennylane/templates/subroutines/qsvt.py b/pennylane/templates/subroutines/qsvt.py index 37c55b27aa2..cad4531d172 100644 --- a/pennylane/templates/subroutines/qsvt.py +++ b/pennylane/templates/subroutines/qsvt.py @@ -263,7 +263,7 @@ class QSVT(Operation): grad_method = None """Gradient computation method.""" - def __init__(self, UA, projectors, do_queue=None, id=None): + def __init__(self, UA, projectors, id=None): if not isinstance(UA, qml.operation.Operator): raise ValueError("Input block encoding must be an Operator") @@ -276,7 +276,7 @@ def __init__(self, UA, projectors, do_queue=None, id=None): proj_wires = set.union(*(proj.wires.toset() for proj in projectors)) total_wires = ua_wires.union(proj_wires) - super().__init__(wires=total_wires, do_queue=do_queue, id=id) + super().__init__(wires=total_wires, id=id) @staticmethod def compute_decomposition( diff --git a/pennylane/templates/subroutines/uccsd.py b/pennylane/templates/subroutines/uccsd.py index f12349e06d8..6401f7e8cf3 100644 --- a/pennylane/templates/subroutines/uccsd.py +++ b/pennylane/templates/subroutines/uccsd.py @@ -167,9 +167,7 @@ def circuit(params, wires, s_wires, d_wires, hf_state): num_wires = AnyWires grad_method = None - def __init__( - self, weights, wires, s_wires=None, d_wires=None, init_state=None, do_queue=None, id=None - ): + def __init__(self, weights, wires, s_wires=None, d_wires=None, init_state=None, id=None): if (not s_wires) and (not d_wires): raise ValueError( f"s_wires and d_wires lists can not be both empty; got ph={s_wires}, pphh={d_wires}" @@ -194,7 +192,7 @@ def __init__( self._hyperparameters = {"init_state": init_state, "s_wires": s_wires, "d_wires": d_wires} - super().__init__(weights, wires=wires, do_queue=do_queue, id=id) + super().__init__(weights, wires=wires, id=id) @property def num_params(self): diff --git a/pennylane/templates/swapnetworks/ccl2.py b/pennylane/templates/swapnetworks/ccl2.py index ff404804858..e1efe7f7ef9 100644 --- a/pennylane/templates/swapnetworks/ccl2.py +++ b/pennylane/templates/swapnetworks/ccl2.py @@ -91,7 +91,6 @@ def __init__( weights=None, fermionic=True, shift=False, - do_queue=None, id=None, **kwargs, ): # pylint: disable=too-many-arguments @@ -125,9 +124,9 @@ def __init__( } if acquaintances is not None and self._weights is not None: - super().__init__(self._weights, wires=wires, do_queue=do_queue, id=id) + super().__init__(self._weights, wires=wires, id=id) else: - super().__init__(wires=wires, do_queue=do_queue, id=id) + super().__init__(wires=wires, id=id) @property def num_params(self): diff --git a/pennylane/templates/tensornetworks/mera.py b/pennylane/templates/tensornetworks/mera.py index 4930a93bdaf..3052da5d1e8 100644 --- a/pennylane/templates/tensornetworks/mera.py +++ b/pennylane/templates/tensornetworks/mera.py @@ -179,7 +179,6 @@ def __init__( block, n_params_block, template_weights=None, - do_queue=None, id=None, ): ind_gates = compute_indices(wires, n_block_wires) @@ -202,7 +201,7 @@ def __init__( self._hyperparameters = {"ind_gates": ind_gates, "block": block} - super().__init__(template_weights, wires=wires, do_queue=do_queue, id=id) + super().__init__(template_weights, wires=wires, id=id) @staticmethod def compute_decomposition( diff --git a/pennylane/templates/tensornetworks/mps.py b/pennylane/templates/tensornetworks/mps.py index 3b9288a1c24..80a25fd5f18 100644 --- a/pennylane/templates/tensornetworks/mps.py +++ b/pennylane/templates/tensornetworks/mps.py @@ -131,7 +131,6 @@ def __init__( block, n_params_block, template_weights=None, - do_queue=None, id=None, ): ind_gates = compute_indices_MPS(wires, n_block_wires) @@ -153,7 +152,7 @@ def __init__( ) self._hyperparameters = {"ind_gates": ind_gates, "block": block} - super().__init__(template_weights, wires=wires, do_queue=do_queue, id=id) + super().__init__(template_weights, wires=wires, id=id) @staticmethod def compute_decomposition( diff --git a/pennylane/templates/tensornetworks/ttn.py b/pennylane/templates/tensornetworks/ttn.py index 2697b1d9645..9882e607b0e 100644 --- a/pennylane/templates/tensornetworks/ttn.py +++ b/pennylane/templates/tensornetworks/ttn.py @@ -164,7 +164,6 @@ def __init__( block, n_params_block, template_weights=None, - do_queue=None, id=None, ): ind_gates = compute_indices(wires, n_block_wires) @@ -187,7 +186,7 @@ def __init__( self._hyperparameters = {"ind_gates": ind_gates, "block": block} - super().__init__(template_weights, wires=wires, do_queue=do_queue, id=id) + super().__init__(template_weights, wires=wires, id=id) @staticmethod def compute_decomposition( diff --git a/pennylane/transforms/condition.py b/pennylane/transforms/condition.py index 8fac95588c4..82298eea93d 100644 --- a/pennylane/transforms/condition.py +++ b/pennylane/transforms/condition.py @@ -42,10 +42,6 @@ class Conditional(Operation): Args: expr (MeasurementValue): the measurement outcome value to consider then_op (Operation): the PennyLane operation to apply conditionally - do_queue (bool): indicates whether the operator should be - recorded when created in a tape context. - This argument is deprecated, instead of setting it to ``False`` - use :meth:`~.queuing.QueuingManager.stop_recording`. id (str): custom label given to an operator instance, can be useful for some applications where the instance has to be identified """ @@ -56,12 +52,11 @@ def __init__( self, expr: MeasurementValue[bool], then_op: Type[Operation], - do_queue=None, id=None, ): self.meas_val = expr self.then_op = then_op - super().__init__(wires=then_op.wires, do_queue=do_queue, id=id) + super().__init__(wires=then_op.wires, id=id) def cond(condition, true_fn, false_fn=None): diff --git a/pennylane/transforms/qcut/qcut.py b/pennylane/transforms/qcut/qcut.py index c6ed00c9647..e32dc587295 100644 --- a/pennylane/transforms/qcut/qcut.py +++ b/pennylane/transforms/qcut/qcut.py @@ -28,10 +28,10 @@ class MeasureNode(Operation): num_wires = 1 grad_method = None - def __init__(self, *params, wires=None, do_queue=None, id=None): + def __init__(self, *params, wires=None, id=None): id = id or str(uuid.uuid4()) - super().__init__(*params, wires=wires, do_queue=do_queue, id=id) + super().__init__(*params, wires=wires, id=id) class PrepareNode(Operation): @@ -40,10 +40,10 @@ class PrepareNode(Operation): num_wires = 1 grad_method = None - def __init__(self, *params, wires=None, do_queue=None, id=None): + def __init__(self, *params, wires=None, id=None): id = id or str(uuid.uuid4()) - super().__init__(*params, wires=wires, do_queue=do_queue, id=id) + super().__init__(*params, wires=wires, id=id) def _prep_zero_state(wire): diff --git a/tests/ops/op_math/test_adjoint.py b/tests/ops/op_math/test_adjoint.py index 8618c82ebad..af377fe7b68 100644 --- a/tests/ops/op_math/test_adjoint.py +++ b/tests/ops/op_math/test_adjoint.py @@ -536,20 +536,6 @@ def test_queuing_base_defined_outside(self): assert len(q) == 1 assert q.queue[0] == op - def test_do_queue_False(self): - """Test that when `do_queue` is specified, the operation is not queued.""" - base = qml.PauliX(0) - do_queue_deprecation_warning = ( - "The do_queue keyword argument is deprecated. " - "Instead of setting it to False, use qml.queuing.QueuingManager.stop_recording()" - ) - - with qml.queuing.AnnotatedQueue() as q: - with pytest.warns(UserWarning, match=do_queue_deprecation_warning): - _ = Adjoint(base, do_queue=False) - - assert len(q) == 0 - class TestMatrix: """Test the matrix method for a variety of interfaces.""" diff --git a/tests/ops/op_math/test_composite.py b/tests/ops/op_math/test_composite.py index 623150bc5e5..b8b6031c08d 100644 --- a/tests/ops/op_math/test_composite.py +++ b/tests/ops/op_math/test_composite.py @@ -209,21 +209,6 @@ def test_build_pauli_rep(self): op = ValidOp(*self.simple_operands) assert op._build_pauli_rep() == qml.pauli.PauliSentence({}) - @pytest.mark.parametrize("do_queue", [True, False]) - def test_composite_do_queue_deprecation(self, do_queue): - """Test that CompositeOp raises a deprecation warning when do_queue is not None.""" - factors = (qml.PauliX(0), qml.PauliY(0)) - do_queue_deprecation_warning = ( - "The do_queue keyword argument is deprecated. " - "Instead of setting it to False, use qml.queuing.QueuingManager.stop_recording()" - ) - - with pytest.warns(UserWarning, match=do_queue_deprecation_warning): - qml.prod(*factors, do_queue=do_queue) - - with pytest.warns(UserWarning, match=do_queue_deprecation_warning): - qml.sum(*factors, do_queue=do_queue) - class TestMscMethods: """Test dunder and other visualizing methods.""" diff --git a/tests/ops/op_math/test_controlled.py b/tests/ops/op_math/test_controlled.py index b974767df89..8d35c193a04 100644 --- a/tests/ops/op_math/test_controlled.py +++ b/tests/ops/op_math/test_controlled.py @@ -625,20 +625,6 @@ def test_queuing_base_defined_outside(self): assert len(q) == 1 assert q.queue[0] is op - def test_do_queue_false(self): - """Test that when `do_queue=False` is specified, the controlled op is not queued.""" - base = qml.PauliX(0) - do_queue_deprecation_warning = ( - "The do_queue keyword argument is deprecated. " - "Instead of setting it to False, use qml.queuing.QueuingManager.stop_recording()" - ) - - with qml.queuing.AnnotatedQueue() as q: - with pytest.warns(UserWarning, match=do_queue_deprecation_warning): - _ = Controlled(base, 1, do_queue=False) - - assert len(q) == 0 - base_num_control_mats = [ (qml.PauliX("a"), 1, CNOT), diff --git a/tests/ops/op_math/test_pow_op.py b/tests/ops/op_math/test_pow_op.py index f2b01f4c520..92da04c4988 100644 --- a/tests/ops/op_math/test_pow_op.py +++ b/tests/ops/op_math/test_pow_op.py @@ -56,16 +56,6 @@ def test_nonlazy_no_simplification(self): assert isinstance(op, Pow) assert isinstance(op.base, TempOperator) - @pytest.mark.parametrize("do_queue", [True, False]) - def test_pow_do_queue_deprecation(self, do_queue): - """Test that a deprecation warning is given, when do_queue is not set to ``None``.""" - do_queue_deprecation_warning = ( - "The do_queue keyword argument is deprecated. " - "Instead of setting it to False, use qml.queuing.QueuingManager.stop_recording()" - ) - with pytest.warns(UserWarning, match=do_queue_deprecation_warning): - qml.pow(qml.PauliX(0), 2, lazy=False, do_queue=do_queue) - @pytest.mark.parametrize("op", (qml.PauliX(0), qml.CNOT((0, 1)))) def test_nonlazy_identity_simplification(self, op): """Test that nonlazy pow returns a single identity if the power decomposes @@ -613,20 +603,6 @@ def test_queueing_base_defined_outside(self): assert len(q) == 1 assert q.queue[0] is op - def test_do_queue_False(self): - """Test that when `do_queue` is specified, the operation is not queued.""" - base = qml.PauliX(0) - do_queue_deprecation_warning = ( - "The do_queue keyword argument is deprecated. " - "Instead of setting it to False, use qml.queuing.QueuingManager.stop_recording()" - ) - - with qml.queuing.AnnotatedQueue() as q: - with pytest.warns(UserWarning, match=do_queue_deprecation_warning): - _ = Pow(base, 4.5, do_queue=False) - - assert len(q) == 0 - class TestMatrix: """Test the matrix method for the power operator.""" diff --git a/tests/ops/op_math/test_prod.py b/tests/ops/op_math/test_prod.py index 40074b8d826..0c8141efa0b 100644 --- a/tests/ops/op_math/test_prod.py +++ b/tests/ops/op_math/test_prod.py @@ -122,7 +122,7 @@ class TestInitialization: # pylint:disable=too-many-public-methods @pytest.mark.parametrize("id", ("foo", "bar")) def test_init_prod_op(self, id): """Test the initialization of a Prod operator.""" - prod_op = prod(qml.PauliX(wires=0), qml.RZ(0.23, wires="a"), do_queue=None, id=id) + prod_op = prod(qml.PauliX(wires=0), qml.RZ(0.23, wires="a"), id=id) assert prod_op.wires == Wires((0, "a")) assert prod_op.num_wires == 2 @@ -216,7 +216,7 @@ def test_has_matrix_true_via_factors_have_matrix(self): """Test that a product of operators that have `has_matrix=True` has `has_matrix=True` as well.""" - prod_op = prod(qml.PauliX(wires=0), qml.RZ(0.23, wires="a"), do_queue=None) + prod_op = prod(qml.PauliX(wires=0), qml.RZ(0.23, wires="a")) assert prod_op.has_matrix is True def test_has_matrix_true_via_factor_has_no_matrix_but_is_hamiltonian(self): @@ -224,7 +224,7 @@ def test_has_matrix_true_via_factor_has_no_matrix_but_is_hamiltonian(self): but is a Hamiltonian has `has_matrix=True`.""" H = qml.Hamiltonian([0.5], [qml.PauliX(wires=1)]) - prod_op = prod(H, qml.RZ(0.23, wires=5), do_queue=None) + prod_op = prod(H, qml.RZ(0.23, wires=5)) assert prod_op.has_matrix is True @pytest.mark.parametrize( @@ -234,7 +234,7 @@ def test_has_matrix_false_via_factor_has_no_matrix(self, first_factor): """Test that a product of operators of which one does not have `has_matrix=True` has `has_matrix=False`.""" - prod_op = prod(first_factor, MyOp(0.23, wires="a"), do_queue=None) + prod_op = prod(first_factor, MyOp(0.23, wires="a")) assert prod_op.has_matrix is False @pytest.mark.parametrize( @@ -253,7 +253,7 @@ def test_has_adjoint_true_always(self, factors): """Test that a product of operators that have `has_matrix=True` has `has_matrix=True` as well.""" - prod_op = prod(*factors, do_queue=None) + prod_op = prod(*factors) assert prod_op.has_adjoint is True @pytest.mark.parametrize( @@ -272,7 +272,7 @@ def test_has_decomposition_true_always(self, factors): """Test that a product of operators that have `has_decomposition=True` has `has_decomposition=True` as well.""" - prod_op = prod(*factors, do_queue=None) + prod_op = prod(*factors) assert prod_op.has_decomposition is True @pytest.mark.parametrize( @@ -291,7 +291,7 @@ def test_has_diagonalizing_gates_true_via_overlapping_factors(self, factors): """Test that a product of operators that have `has_diagonalizing_gates=True` has `has_diagonalizing_gates=True` as well.""" - prod_op = prod(*factors, do_queue=None) + prod_op = prod(*factors) assert prod_op.has_diagonalizing_gates is True @pytest.mark.parametrize( @@ -306,14 +306,14 @@ def test_has_diagonalizing_gates_true_via_factors(self, factors): """Test that a product of operators that have `has_diagonalizing_gates=True` has `has_diagonalizing_gates=True` as well.""" - prod_op = prod(*factors, do_queue=None) + prod_op = prod(*factors) assert prod_op.has_diagonalizing_gates is True def test_has_diagonalizing_gates_false_via_factor(self): """Test that a product of operators of which one has `has_diagonalizing_gates=False` has `has_diagonalizing_gates=False` as well.""" - prod_op = prod(MyOp(3.1, 0), qml.PauliX(2), do_queue=None) + prod_op = prod(MyOp(3.1, 0), qml.PauliX(2)) assert prod_op.has_diagonalizing_gates is False def test_qfunc_init(self): @@ -358,7 +358,7 @@ def qfunc(x): with qml.queuing.AnnotatedQueue() as q: prod_op = prod_gen(1.1) - assert prod_op not in q # do_queue worked + assert prod_op not in q assert prod_op.id == 123987 # id was set assert qml.equal(prod_op, prod(qml.CNOT([0, 1]), qml.PauliZ(1), qml.RX(1.1, 0))) # eager diff --git a/tests/ops/op_math/test_sprod.py b/tests/ops/op_math/test_sprod.py index 00cffd9a052..d87c47dd245 100644 --- a/tests/ops/op_math/test_sprod.py +++ b/tests/ops/op_math/test_sprod.py @@ -102,7 +102,7 @@ class TestInitialization: @pytest.mark.parametrize("test_id", ("foo", "bar")) def test_init_sprod_op(self, test_id): - sprod_op = s_prod(3.14, qml.RX(0.23, wires="a"), do_queue=None, id=test_id) + sprod_op = s_prod(3.14, qml.RX(0.23, wires="a"), id=test_id) # no need to test if op.base == RX since this is covered in SymbolicOp tests assert sprod_op.scalar == 3.14 diff --git a/tests/ops/op_math/test_symbolic_op.py b/tests/ops/op_math/test_symbolic_op.py index 04ae2cddea5..ba32ea2e34b 100644 --- a/tests/ops/op_math/test_symbolic_op.py +++ b/tests/ops/op_math/test_symbolic_op.py @@ -208,20 +208,6 @@ def test_queuing_base_defined_outside(self): assert len(q) == 1 assert q.queue[0] is op - def test_do_queue_false(self): - """Test that queuing can be avoided if `do_queue=False`.""" - base = Operator("c") - do_queue_deprecation_warning = ( - "The do_queue keyword argument is deprecated. " - "Instead of setting it to False, use qml.queuing.QueuingManager.stop_recording()" - ) - - with qml.queuing.AnnotatedQueue() as q: - with pytest.warns(UserWarning, match=do_queue_deprecation_warning): - SymbolicOp(base, do_queue=False) - - assert len(q) == 0 - class TestScalarSymbolicOp: """Tests for the ScalarSymbolicOp class.""" diff --git a/tests/tape/test_tape.py b/tests/tape/test_tape.py index 11965d1acde..7b2bd75b7b5 100644 --- a/tests/tape/test_tape.py +++ b/tests/tape/test_tape.py @@ -60,16 +60,6 @@ def func(x): class TestConstruction: """Test for queuing and construction""" - @pytest.mark.parametrize("do_queue", [True, False]) - def test_tape_do_queue_deprecation(self, do_queue): - """Test that a deprecation warning is given, when do_queue is not set to ``None``.""" - do_queue_deprecation_warning = ( - "The do_queue keyword argument is deprecated. " - "Instead of setting it to False, use qml.queuing.QueuingManager.stop_recording()" - ) - with pytest.warns(UserWarning, match=do_queue_deprecation_warning): - qml.tape.QuantumTape(do_queue=do_queue) - @pytest.fixture def make_tape(self): ops = [] diff --git a/tests/templates/test_subroutines/test_grover.py b/tests/templates/test_subroutines/test_grover.py index 1afc359a92f..39696b043ef 100644 --- a/tests/templates/test_subroutines/test_grover.py +++ b/tests/templates/test_subroutines/test_grover.py @@ -44,21 +44,6 @@ def test_single_wire_error(bad_wires): op = qml.GroverOperator(wires=bad_wires) -def test_do_queue(): - """Assert do_queue=False is not queued""" - do_queue_deprecation_warning = ( - "The do_queue keyword argument is deprecated. " - "Instead of setting it to False, use qml.queuing.QueuingManager.stop_recording()" - ) - - with qml.queuing.AnnotatedQueue() as q: - with pytest.warns(UserWarning, match=do_queue_deprecation_warning): - qml.GroverOperator(wires=(0, 1), do_queue=False) - - tape = qml.tape.QuantumScript.from_queue(q) - assert len(tape.operations) == 0 - - def test_id(): """Assert id keyword works""" diff --git a/tests/test_operation.py b/tests/test_operation.py index 0ac8e962a1e..ecf5a90793d 100644 --- a/tests/test_operation.py +++ b/tests/test_operation.py @@ -59,32 +59,16 @@ class TestOperatorConstruction: """Test custom operators construction.""" def test_operation_outside_context(self): - """Test that an operation can be instantiated outside a QNode context, and that do_queue is ignored""" - do_queue_deprecation_warning = ( - "The do_queue keyword argument is deprecated. " - "Instead of setting it to False, use qml.queuing.QueuingManager.stop_recording()" - ) - with pytest.warns(UserWarning, match=do_queue_deprecation_warning): - op = qml.ops.CNOT(wires=[0, 1], do_queue=False) - assert isinstance(op, qml.operation.Operation) + """Test that an operation can be instantiated outside a QNode context""" + op = qml.ops.CNOT(wires=[0, 1]) + assert isinstance(op, qml.operation.Operation) - with pytest.warns(UserWarning, match=do_queue_deprecation_warning): - op = qml.ops.RX(0.5, wires=0, do_queue=True) - assert isinstance(op, qml.operation.Operation) + op = qml.ops.RX(0.5, wires=0) + assert isinstance(op, qml.operation.Operation) op = qml.ops.Hadamard(wires=0) assert isinstance(op, qml.operation.Operation) - @pytest.mark.parametrize("do_queue", [True, False]) - def test_do_queue_deprecation(self, do_queue): - """Test that a deprecation warning is given, when do_queue is not set to ``None``.""" - do_queue_deprecation_warning = ( - "The do_queue keyword argument is deprecated. " - "Instead of setting it to False, use qml.queuing.QueuingManager.stop_recording()" - ) - with pytest.warns(UserWarning, match=do_queue_deprecation_warning): - Operator(wires=0, do_queue=do_queue) - def test_incorrect_num_wires(self): """Test that an exception is raised if called with wrong number of wires""" @@ -2526,14 +2510,14 @@ class FlipAndRotate(qml.operation.Operation): grad_method = "A" # pylint: disable=too-many-arguments - def __init__(self, angle, wire_rot, wire_flip=None, do_flip=False, do_queue=None, id=None): + def __init__(self, angle, wire_rot, wire_flip=None, do_flip=False, id=None): if do_flip and wire_flip is None: raise ValueError("Expected a wire to flip; got None.") self._hyperparameters = {"do_flip": do_flip} all_wires = qml.wires.Wires(wire_rot) + qml.wires.Wires(wire_flip) - super().__init__(angle, wires=all_wires, do_queue=do_queue, id=id) + super().__init__(angle, wires=all_wires, id=id) @property def num_params(self):