Skip to content

Commit

Permalink
Use decomposition instead of Operator.expand (#846)
Browse files Browse the repository at this point in the history
`Operator.expand` is deprecated
(PennyLaneAI/pennylane#5994).
`Operator.decomposition` should be used instead.

---------

Co-authored-by: ringo-but-quantum <[email protected]>
Co-authored-by: Ali Asadi <[email protected]>
  • Loading branch information
3 people authored Aug 12, 2024
1 parent 27813be commit d6f681d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
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`.
[(#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()
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

0 comments on commit d6f681d

Please sign in to comment.