Skip to content

Commit dfd715e

Browse files
vincentmralbi3rogithub-actions[bot]
authored
Fix operation list mutation master (#475)
* stop mutating input to apply * changelog * Auto update version * Trigger CI. * Fix dtype in TestAdjointJacobianQNode. * Fix dtype in jax tests. * Change jax config if float64. * Reformat. --------- Co-authored-by: albi3ro <[email protected]> Co-authored-by: Dev version update bot <github-actions[bot]@users.noreply.github.com>
1 parent d199188 commit dfd715e

File tree

5 files changed

+15
-5
lines changed

5 files changed

+15
-5
lines changed

.github/CHANGELOG.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@
1616

1717
### Bug fixes
1818

19+
* `apply` no longer mutates the inputted list of operations.
20+
[(#475)](https://github.com/PennyLaneAI/pennylane-lightning/pull/475)
21+
1922
### Contributors
2023

2124
This release contains contributions from (in alphabetical order):
2225

23-
Vincent Michaud-Rioux
26+
Amintor Dusko, Christina Lee, Vincent Michaud-Rioux, Lee J. O'Riordan
2427

2528
---
2629

pennylane_lightning/_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
Version number (major.minor.patch[-label])
1717
"""
1818

19-
__version__ = "0.32.0-dev4"
19+
__version__ = "0.32.0-dev5"

pennylane_lightning/lightning_qubit.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -419,10 +419,10 @@ def apply(self, operations, rotations=None, **kwargs):
419419
if operations: # make sure operations[0] exists
420420
if isinstance(operations[0], QubitStateVector):
421421
self._apply_state_vector(operations[0].parameters[0].copy(), operations[0].wires)
422-
del operations[0]
422+
operations = operations[1:]
423423
elif isinstance(operations[0], BasisState):
424424
self._apply_basis_state(operations[0].parameters[0], operations[0].wires)
425-
del operations[0]
425+
operations = operations[1:]
426426

427427
for operation in operations:
428428
if isinstance(operation, (QubitStateVector, BasisState)):

tests/test_adjoint_jacobian.py

+4
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,10 @@ def test_interface_jax(self, dev):
789789
jax interface"""
790790

791791
jax = pytest.importorskip("jax")
792+
if dev.R_DTYPE == np.float64:
793+
from jax.config import config
794+
795+
config.update("jax_enable_x64", True)
792796

793797
def f(params1, params2):
794798
qml.RX(0.4, wires=[0])

tests/test_apply.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,10 @@ def test_apply_operation_state_preparation(
203203
par = np.array(par)
204204
dev = qubit_device(wires=2)
205205
dev.reset()
206-
dev.apply([operation(par, wires=[0, 1])])
206+
ops = [operation(par, wires=[0, 1])]
207+
208+
dev.apply(ops)
209+
assert len(ops) == 1 # input not mutated
207210

208211
assert np.allclose(dev.state, np.array(expected_output), atol=tol, rtol=0)
209212

0 commit comments

Comments
 (0)