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

globalphase decomposes to nothing #4855

Merged
merged 8 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
* Simplified the logic for re-arranging states before returning.
[(#4817)](https://github.com/PennyLaneAI/pennylane/pull/4817)

* `GlobalPhase` now decomposes to nothing, in case devices do not support global phases.
[(#4855)](https://github.com/PennyLaneAI/pennylane/pull/4855)

<h3>Breaking changes 💔</h3>

* The `prep` keyword argument has been removed from `QuantumScript` and `QuantumTape`.
Expand Down
23 changes: 23 additions & 0 deletions pennylane/ops/identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,29 @@ def compute_diagonalizing_gates(
"""
return []

@staticmethod
def compute_decomposition(phi, wires=None): # pylint:disable=arguments-differ,unused-argument
r"""Representation of the operator as a product of other operators (static method).
timmysilv marked this conversation as resolved.
Show resolved Hide resolved

.. math:: O = O_1 O_2 \dots O_n.

.. seealso:: :meth:`~.Identity.decomposition`.
timmysilv marked this conversation as resolved.
Show resolved Hide resolved

Args:
phi (TensorLike): the global phase
wires (Any, Wires): A single wire that the operator acts on.

Returns:
list[Operator]: decomposition into lower level operations

**Example:**

>>> qml.GlobalPhase.compute_decomposition(wires=0)
[]

"""
return []
timmysilv marked this conversation as resolved.
Show resolved Hide resolved

def matrix(self, wire_order=None):
n_wires = len(wire_order) if wire_order else len(self.wires)
return self.compute_matrix(self.data[0], n_wires=n_wires)
Expand Down
7 changes: 7 additions & 0 deletions tests/ops/qubit/test_parametric_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -4522,6 +4522,13 @@ def test_global_phase_compute_sparse_matrix(phi, n_wires):
assert np.allclose(sparse_matrix.todense(), expected.todense())


def test_decomposition():
"""Test the decomposition of the GlobalPhase operation."""

assert qml.GlobalPhase.compute_decomposition(1.23) == []
assert qml.GlobalPhase(1.23).decomposition() == []


control_data = [
(qml.Rot(1, 2, 3, wires=0), Wires([])),
(qml.RX(1.23, wires=0), Wires([])),
Expand Down
Loading