Skip to content

Commit

Permalink
Fix operation list mutation master (#475)
Browse files Browse the repository at this point in the history
* 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 <chrissie.c.l@gmail.com>
Co-authored-by: Dev version update bot <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 18, 2023
1 parent d199188 commit dfd715e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
5 changes: 4 additions & 1 deletion .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

---

Expand Down
2 changes: 1 addition & 1 deletion pennylane_lightning/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
Version number (major.minor.patch[-label])
"""

__version__ = "0.32.0-dev4"
__version__ = "0.32.0-dev5"
4 changes: 2 additions & 2 deletions pennylane_lightning/lightning_qubit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)):
Expand Down
4 changes: 4 additions & 0 deletions tests/test_adjoint_jacobian.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
5 changes: 4 additions & 1 deletion tests/test_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit dfd715e

Please sign in to comment.