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

Use decomposition instead of Operator.expand #846

Merged
merged 5 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
5 changes: 4 additions & 1 deletion .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
* Move `setBasisState`, `setStateVector` and `resetStateVector` from `StateVectorLQubitManaged` to `StateVectorLQubit`.
[(#841)](https://github.com/PennyLaneAI/pennylane-lightning/pull/841)

* Remove use of the deprecated `Operator.expand` in favour of `Operator.decomposition`
astralcai marked this conversation as resolved.
Show resolved Hide resolved
[(#846)](https://github.com/PennyLaneAI/pennylane-lightning/pull/846)

### Documentation

* Updated the README and added citation format for Lightning arxiv preprint.
Expand Down Expand Up @@ -105,7 +108,7 @@

This release contains contributions from (in alphabetical order):

Ali Asadi, Amintor Dusko, Vincent Michaud-Rioux, Erick Ochoa Lopez, Lee J. O'Riordan, Mudit Pandey, Shuli Shu, Paul Haochen Wang
Ali Asadi, Astral Cai, Amintor Dusko, Vincent Michaud-Rioux, Erick Ochoa Lopez, Lee J. O'Riordan, Mudit Pandey, Shuli Shu, Paul Haochen Wang

---

Expand Down
2 changes: 1 addition & 1 deletion pennylane_lightning/core/_serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ def get_wires(operation, single_op):
uses_stateprep = True
continue
if isinstance(operation, Rot):
op_list = operation.expand().operations
op_list = operation.decomposition()
maliasadi marked this conversation as resolved.
Show resolved Hide resolved
else:
op_list = [operation]

Expand Down
2 changes: 1 addition & 1 deletion pennylane_lightning/core/_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.38.0-dev28"
__version__ = "0.38.0-dev29"
23 changes: 23 additions & 0 deletions tests/test_serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,29 @@ def test_basic_circuit(self, wires_map):
)
assert s == s_expected

@pytest.mark.parametrize("wires_map", [wires_dict, None])
def test_Rot_in_circuit(self, wires_map):
"""Test expected serialization for a circuit with Rot which should be decomposed"""

with qml.queuing.AnnotatedQueue() as q:
qml.Rot(0.1, 0.2, 0.3, wires=0)

tape = qml.tape.QuantumScript.from_queue(q)
s = QuantumScriptSerializer(device_name).serialize_ops(tape, wires_map)
s_expected = (
(
["RZ", "RY", "RZ"],
[np.array([0.1]), np.array([0.2]), np.array([0.3])],
[[0], [0], [0]],
[False, False, False],
[[], [], []],
[[], [], []],
[[], [], []],
),
False,
)
assert s == s_expected

@pytest.mark.parametrize("wires_map", [wires_dict, None])
def test_basic_circuit_not_implemented_ctrl_ops(self, wires_map):
"""Test expected serialization for a simple circuit"""
Expand Down
Loading