diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index d0044f1fa9..b78bd12af2 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -16,11 +16,14 @@ ### Bug fixes +* `apply` no longer mutates the inputted list of operations. + [(#475)](https://github.com/PennyLaneAI/pennylane-lightning/pull/475) + ### Contributors This release contains contributions from (in alphabetical order): -Vincent Michaud-Rioux +Amintor Dusko, Christina Lee, Vincent Michaud-Rioux, Lee J. O'Riordan --- diff --git a/pennylane_lightning/_version.py b/pennylane_lightning/_version.py index 9442c0362a..7e05d3ddb5 100644 --- a/pennylane_lightning/_version.py +++ b/pennylane_lightning/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.32.0-dev4" +__version__ = "0.32.0-dev5" diff --git a/pennylane_lightning/lightning_qubit.py b/pennylane_lightning/lightning_qubit.py index 3ef6e91a53..eb0991b675 100644 --- a/pennylane_lightning/lightning_qubit.py +++ b/pennylane_lightning/lightning_qubit.py @@ -419,10 +419,10 @@ def apply(self, operations, rotations=None, **kwargs): if operations: # make sure operations[0] exists if isinstance(operations[0], QubitStateVector): self._apply_state_vector(operations[0].parameters[0].copy(), operations[0].wires) - del operations[0] + operations = operations[1:] elif isinstance(operations[0], BasisState): self._apply_basis_state(operations[0].parameters[0], operations[0].wires) - del operations[0] + operations = operations[1:] for operation in operations: if isinstance(operation, (QubitStateVector, BasisState)): diff --git a/tests/test_adjoint_jacobian.py b/tests/test_adjoint_jacobian.py index a52fba0731..0030fb8a42 100644 --- a/tests/test_adjoint_jacobian.py +++ b/tests/test_adjoint_jacobian.py @@ -789,6 +789,10 @@ def test_interface_jax(self, dev): jax interface""" jax = pytest.importorskip("jax") + if dev.R_DTYPE == np.float64: + from jax.config import config + + config.update("jax_enable_x64", True) def f(params1, params2): qml.RX(0.4, wires=[0]) diff --git a/tests/test_apply.py b/tests/test_apply.py index 75c27a2060..ab5fc1b0a7 100644 --- a/tests/test_apply.py +++ b/tests/test_apply.py @@ -203,7 +203,10 @@ def test_apply_operation_state_preparation( par = np.array(par) dev = qubit_device(wires=2) dev.reset() - dev.apply([operation(par, wires=[0, 1])]) + ops = [operation(par, wires=[0, 1])] + + dev.apply(ops) + assert len(ops) == 1 # input not mutated assert np.allclose(dev.state, np.array(expected_output), atol=tol, rtol=0)