Skip to content

Commit

Permalink
Merge branch 'master' into custom_lattice_function
Browse files Browse the repository at this point in the history
  • Loading branch information
soranjh authored Sep 20, 2024
2 parents 4b39e33 + 6d98c51 commit ac7e49f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
2 changes: 0 additions & 2 deletions doc/development/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ This page contains the release notes for PennyLane.

.. mdinclude:: ../releases/changelog-dev.md

.. mdinclude:: ../releases/changelog-0.38.1.md

.. mdinclude:: ../releases/changelog-0.38.0.md

.. mdinclude:: ../releases/changelog-0.37.0.md
Expand Down
14 changes: 0 additions & 14 deletions doc/releases/changelog-0.38.1.md

This file was deleted.

4 changes: 4 additions & 0 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@

<h3>Bug fixes 🐛</h3>

* Fix float-to-complex casting in various places across PennyLane.
[(#6260)](https://github.com/PennyLaneAI/pennylane/pull/6260)
[(#6268)](https://github.com/PennyLaneAI/pennylane/pull/6268)

* Fix a bug where zero-valued JVPs were calculated wrongly in the presence of shot vectors.
[(#6219)](https://github.com/PennyLaneAI/pennylane/pull/6219)

Expand Down
17 changes: 15 additions & 2 deletions pennylane/devices/qubit/apply_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,13 @@ def apply_operation_einsum(op: qml.operation.Operator, state, is_state_batched:
Returns:
array[complex]: output_state
"""
mat = qml.math.cast_like(op.matrix(), 1j)
# We use this implicit casting strategy as autograd raises ComplexWarnings
# when backpropagating if casting explicitly. Some type of casting is needed
# to prevent ComplexWarnings with backpropagation with other interfaces
if qml.math.get_interface(state) == "tensorflow":
mat = qml.math.cast_like(op.matrix(), state)
else:
mat = op.matrix() + 0j

total_indices = len(state.shape) - is_state_batched
num_indices = len(op.wires)
Expand Down Expand Up @@ -114,7 +120,14 @@ def apply_operation_tensordot(op: qml.operation.Operator, state, is_state_batche
Returns:
array[complex]: output_state
"""
mat = qml.math.cast_like(op.matrix(), 1j)
# We use this implicit casting strategy as autograd raises ComplexWarnings
# when backpropagating if casting explicitly. Some type of casting is needed
# to prevent ComplexWarnings with backpropagation with other interfaces
if qml.math.get_interface(state) == "tensorflow":
mat = qml.math.cast_like(op.matrix(), state)
else:
mat = op.matrix() + 0j

total_indices = len(state.shape) - is_state_batched
num_indices = len(op.wires)

Expand Down

0 comments on commit ac7e49f

Please sign in to comment.