Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix expand_tape_state_prep. #4564

Merged
merged 15 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@

<h3>Bug fixes 🐛</h3>

* Fix `skip_first` option in `expand_tape_state_prep`.
[(#4564)](https://github.com/PennyLaneAI/pennylane/pull/4564)

* `convert_to_numpy_parameters` now uses `qml.ops.functions.bind_new_parameters`. This reinitializes the operation and
makes sure everything references the new numpy parameters.

Expand All @@ -174,6 +177,7 @@ This release contains contributions from (in alphabetical order):

Soran Jahangiri,
Lillian M. A. Frederiksen,
Vincent Michaud-Rioux,
Romain Moyard,
Mudit Pandey,
Matthew Silverman,
Expand Down
2 changes: 1 addition & 1 deletion pennylane/tape/tape.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def expand_tape_state_prep(tape, skip_first=True):
first_op = tape.operations[0]
new_ops = (
[first_op]
if isinstance(first_op, StatePrepBase) and skip_first
if not isinstance(first_op, StatePrepBase) or skip_first
else first_op.decomposition()
)

Expand Down
5 changes: 4 additions & 1 deletion tests/tape/test_tape.py
Original file line number Diff line number Diff line change
Expand Up @@ -1014,10 +1014,12 @@ def test_depth_expansion(self):
[
qml.BasisState([1, 0], wires=[0, 1]),
qml.StatePrep([0, 1, 0, 0], wires=[0, 1]),
qml.PauliZ(0),
],
[
qml.BasisStatePreparation([1, 0], wires=[0, 1]),
qml.MottonenStatePreparation([0, 1, 0, 0], wires=[0, 1]),
qml.PauliZ(0),
],
),
)
Expand All @@ -1026,12 +1028,13 @@ def test_expansion_state_prep(self, skip_first, op, decomp):
expanding other operations in the tape.
"""
ops = [
op,
qml.PauliZ(wires=0),
qml.Rot(0.1, 0.2, 0.3, wires=0),
qml.BasisState([0], wires=1),
qml.StatePrep([0, 1], wires=0),
]
tape = QuantumTape(ops=ops, measurements=[], prep=[op])
tape = QuantumTape(ops=ops, measurements=[])
new_tape = expand_tape_state_prep(tape, skip_first=skip_first)

true_decomposition = []
Expand Down
Loading