Skip to content

Commit d9fb3a3

Browse files
astralcairingo-but-quantummaliasadi
authored andcommitted
Use decomposition instead of Operator.expand (#846)
`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]>
1 parent f99b94e commit d9fb3a3

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

.github/CHANGELOG.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@
7676
* Move `setBasisState`, `setStateVector` and `resetStateVector` from `StateVectorLQubitManaged` to `StateVectorLQubit`.
7777
[(#841)](https://github.com/PennyLaneAI/pennylane-lightning/pull/841)
7878

79+
* Remove use of the deprecated `Operator.expand` in favour of `Operator.decomposition`.
80+
[(#846)](https://github.com/PennyLaneAI/pennylane-lightning/pull/846)
81+
7982
### Documentation
8083

8184
* Updated the README and added citation format for Lightning arxiv preprint.
@@ -111,7 +114,7 @@
111114

112115
This release contains contributions from (in alphabetical order):
113116

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

116119
---
117120

pennylane_lightning/core/_serialize.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ def get_wires(operation, single_op):
404404
uses_stateprep = True
405405
continue
406406
if isinstance(operation, Rot):
407-
op_list = operation.expand().operations
407+
op_list = operation.decomposition()
408408
else:
409409
op_list = [operation]
410410

tests/test_serialize.py

+23
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,29 @@ def test_basic_circuit(self, wires_map):
740740
)
741741
assert s == s_expected
742742

743+
@pytest.mark.parametrize("wires_map", [wires_dict, None])
744+
def test_Rot_in_circuit(self, wires_map):
745+
"""Test expected serialization for a circuit with Rot which should be decomposed"""
746+
747+
with qml.queuing.AnnotatedQueue() as q:
748+
qml.Rot(0.1, 0.2, 0.3, wires=0)
749+
750+
tape = qml.tape.QuantumScript.from_queue(q)
751+
s = QuantumScriptSerializer(device_name).serialize_ops(tape, wires_map)
752+
s_expected = (
753+
(
754+
["RZ", "RY", "RZ"],
755+
[np.array([0.1]), np.array([0.2]), np.array([0.3])],
756+
[[0], [0], [0]],
757+
[False, False, False],
758+
[[], [], []],
759+
[[], [], []],
760+
[[], [], []],
761+
),
762+
False,
763+
)
764+
assert s == s_expected
765+
743766
@pytest.mark.parametrize("wires_map", [wires_dict, None])
744767
def test_basic_circuit_not_implemented_ctrl_ops(self, wires_map):
745768
"""Test expected serialization for a simple circuit"""

0 commit comments

Comments
 (0)