Skip to content

Global Phase Gates API Reference

This page documents the global phase gates available in the skq.gates.global_phase module.

GlobalPhase

Global phase gates apply a phase shift to the entire quantum state.

Matrix Representation:

\[ \text{GlobalPhase}(\phi) = e^{i\phi} \cdot I \]

Where \(I\) is the identity matrix of appropriate dimension.

skq.gates.global_phase.GlobalPhase

Bases: BaseGate

Class representing a Global Phase :param phase: Global phase angle in radians

Source code in src/skq/gates/global_phase.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
class GlobalPhase(BaseGate):
    """
    Class representing a Global Phase
    :param phase: Global phase angle in radians
    """

    def __new__(cls, phase: float) -> "GlobalPhase":
        input_array = np.array([[np.exp(1j * phase)]], dtype=complex)
        obj = super().__new__(cls, input_array)
        assert obj.is_1x1(), "Quscalar must be a 1x1 matrix"
        return obj

    @property
    def scalar(self) -> complex:
        """Get the scalar value of the gate."""
        return self[0, 0]

    @property
    def phase(self) -> float:
        """Get the global phase."""
        return np.angle(self.scalar)

    def is_1x1(self) -> bool:
        """Check if the gate is a 1x1 matrix."""
        return self.shape == (1, 1)

    def inverse(self) -> "GlobalPhase":
        inverse_phase = -self.phase
        return GlobalPhase(inverse_phase)

    def combine(self, other: "GlobalPhase") -> "GlobalPhase":
        assert isinstance(other, GlobalPhase), "Can only combine with another QuScalarGate."
        combined_phase = self.phase + other.phase
        return GlobalPhase(combined_phase)

    def multiply(self, other: "GlobalPhase") -> "GlobalPhase":
        assert isinstance(other, GlobalPhase), "Can only multiply with another QuScalarGate."
        multiplied_phase = np.angle(self.scalar * other.scalar)
        return GlobalPhase(multiplied_phase)

    def to_qiskit(self) -> qiskit.circuit.library.GlobalPhaseGate:
        """Convert QuScalar to a Qiskit GlobalPhaseGate object."""
        return qiskit.circuit.library.GlobalPhaseGate(self.phase)

    @staticmethod
    def from_qiskit(qiskit_gate: qiskit.circuit.library.GlobalPhaseGate) -> "GlobalPhase":
        """
        Convert a Qiskit GlobalPhaseGate to a QuScalar object.
        :param qiskit_gate: Qiskit GlobalPhaseGate object
        :return: A QuScalar object
        """
        if not isinstance(qiskit_gate, qiskit.circuit.library.GlobalPhaseGate):
            raise ValueError(f"Expected GlobalPhaseGate, got {type(qiskit_gate)}.")
        phase = qiskit_gate.params[0]
        return GlobalPhase(phase)

    def to_pennylane(self) -> qml.GlobalPhase:
        """Convert QuScalar to a PennyLane GlobalPhase."""
        return qml.GlobalPhase(self.phase)

    @staticmethod
    def from_pennylane(pennylane_gate: qml.operation.Operation) -> "GlobalPhase":
        """
        Convert a PennyLane GlobalPhase to a QuScalar object.
        :param pennylane_gate: PennyLane GlobalPhase object
        :return: A QuScalar object
        """
        if not isinstance(pennylane_gate, qml.GlobalPhase):
            raise ValueError(f"Expected GlobalPhase, got {type(pennylane_gate)}.")
        phase = pennylane_gate.parameters[0]
        return GlobalPhase(phase)

phase property

Get the global phase.

scalar property

Get the scalar value of the gate.

from_pennylane(pennylane_gate) staticmethod

Convert a PennyLane GlobalPhase to a QuScalar object. :param pennylane_gate: PennyLane GlobalPhase object :return: A QuScalar object

Source code in src/skq/gates/global_phase.py
68
69
70
71
72
73
74
75
76
77
78
@staticmethod
def from_pennylane(pennylane_gate: qml.operation.Operation) -> "GlobalPhase":
    """
    Convert a PennyLane GlobalPhase to a QuScalar object.
    :param pennylane_gate: PennyLane GlobalPhase object
    :return: A QuScalar object
    """
    if not isinstance(pennylane_gate, qml.GlobalPhase):
        raise ValueError(f"Expected GlobalPhase, got {type(pennylane_gate)}.")
    phase = pennylane_gate.parameters[0]
    return GlobalPhase(phase)

from_qiskit(qiskit_gate) staticmethod

Convert a Qiskit GlobalPhaseGate to a QuScalar object. :param qiskit_gate: Qiskit GlobalPhaseGate object :return: A QuScalar object

Source code in src/skq/gates/global_phase.py
52
53
54
55
56
57
58
59
60
61
62
@staticmethod
def from_qiskit(qiskit_gate: qiskit.circuit.library.GlobalPhaseGate) -> "GlobalPhase":
    """
    Convert a Qiskit GlobalPhaseGate to a QuScalar object.
    :param qiskit_gate: Qiskit GlobalPhaseGate object
    :return: A QuScalar object
    """
    if not isinstance(qiskit_gate, qiskit.circuit.library.GlobalPhaseGate):
        raise ValueError(f"Expected GlobalPhaseGate, got {type(qiskit_gate)}.")
    phase = qiskit_gate.params[0]
    return GlobalPhase(phase)

is_1x1()

Check if the gate is a 1x1 matrix.

Source code in src/skq/gates/global_phase.py
30
31
32
def is_1x1(self) -> bool:
    """Check if the gate is a 1x1 matrix."""
    return self.shape == (1, 1)

to_pennylane()

Convert QuScalar to a PennyLane GlobalPhase.

Source code in src/skq/gates/global_phase.py
64
65
66
def to_pennylane(self) -> qml.GlobalPhase:
    """Convert QuScalar to a PennyLane GlobalPhase."""
    return qml.GlobalPhase(self.phase)

to_qiskit()

Convert QuScalar to a Qiskit GlobalPhaseGate object.

Source code in src/skq/gates/global_phase.py
48
49
50
def to_qiskit(self) -> qiskit.circuit.library.GlobalPhaseGate:
    """Convert QuScalar to a Qiskit GlobalPhaseGate object."""
    return qiskit.circuit.library.GlobalPhaseGate(self.phase)

Predefined Phase Gates

SKQ provides several predefined global phase gates:

Identity (No Phase Shift)

Matrix Representation:

\[ \text{Identity} = e^{i \cdot 0} \cdot I = I \]

skq.gates.global_phase.Identity

Bases: GlobalPhase

No phase shift.

Source code in src/skq/gates/global_phase.py
81
82
83
84
85
class Identity(GlobalPhase):
    """No phase shift."""

    def __new__(cls) -> "Identity":
        return super().__new__(cls, 0.0)

QuarterPhase (π/2)

Matrix Representation:

\[ \text{QuarterPhase} = e^{i\pi/2} \cdot I = i \cdot I \]

skq.gates.global_phase.QuarterPhase

Bases: GlobalPhase

Quarter phase shift (π/2)

Source code in src/skq/gates/global_phase.py
88
89
90
91
92
class QuarterPhase(GlobalPhase):
    """Quarter phase shift (π/2)"""

    def __new__(cls) -> "QuarterPhase":
        return super().__new__(cls, np.pi / 2)

HalfPhase (π)

Matrix Representation:

\[ \text{HalfPhase} = e^{i\pi} \cdot I = -1 \cdot I \]

skq.gates.global_phase.HalfPhase

Bases: GlobalPhase

Half phase shift (π)

Source code in src/skq/gates/global_phase.py
95
96
97
98
99
class HalfPhase(GlobalPhase):
    """Half phase shift (π)"""

    def __new__(cls) -> "HalfPhase":
        return super().__new__(cls, np.pi)

ThreeQuarterPhase (3π/2)

Matrix Representation:

\[ \text{ThreeQuarterPhase} = e^{i3\pi/2} \cdot I = -i \cdot I \]

skq.gates.global_phase.ThreeQuarterPhase

Bases: GlobalPhase

Three quarters phase shift (3π/2)

Source code in src/skq/gates/global_phase.py
102
103
104
105
106
class ThreeQuarterPhase(GlobalPhase):
    """Three quarters phase shift (3π/2)"""

    def __new__(cls) -> "ThreeQuarterPhase":
        return super().__new__(cls, 3 * np.pi / 2)

FullPhase (2π)

Matrix Representation:

\[ \text{FullPhase} = e^{i2\pi} \cdot I = I \]

skq.gates.global_phase.FullPhase

Bases: GlobalPhase

Full phase shift (2π)

Source code in src/skq/gates/global_phase.py
109
110
111
112
113
class FullPhase(GlobalPhase):
    """Full phase shift (2π)"""

    def __new__(cls) -> "FullPhase":
        return super().__new__(cls, 2 * np.pi)