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 3 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
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 @@
uses_stateprep = True
continue
if isinstance(operation, Rot):
op_list = operation.expand().operations
op_list = operation.decomposition()

Check warning on line 407 in pennylane_lightning/core/_serialize.py

View check run for this annotation

Codecov / codecov/patch

pennylane_lightning/core/_serialize.py#L407

Added line #L407 was not covered by tests
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