graphix.ops module

Quantum states and operators.

controlled(gate: NDArray[complex128]) → NDArray[complex128][source]
controlled(gate: NDArray[object_]) → NDArray[object_]

Return the controlled version of a gate.

class Ops[source]

Bases: object

Elementary quantum gates acting on 1, 2, or 3 qubits.

I: ClassVar[NDArray[complex128]] = array([[1.+0.j, 0.+0.j],        [0.+0.j, 1.+0.j]])
X: ClassVar[NDArray[complex128]] = array([[0.+0.j, 1.+0.j],        [1.+0.j, 0.+0.j]])
Y: ClassVar[NDArray[complex128]] = array([[ 0.+0.j, -0.-1.j],        [ 0.+1.j,  0.+0.j]])
Z: ClassVar[NDArray[complex128]] = array([[ 1.+0.j,  0.+0.j],        [ 0.+0.j, -1.+0.j]])
S: ClassVar[NDArray[complex128]] = array([[1.+0.j, 0.+0.j],        [0.+0.j, 0.+1.j]])
SDG: ClassVar[NDArray[complex128]] = array([[ 1.+0.j,  0.+0.j],        [ 0.+0.j, -0.-1.j]])
T: ClassVar[NDArray[complex128]] = array([[1.        +0.j        , 0.        +0.j        ],        [0.        +0.j        , 0.70710678+0.70710678j]])
TDG: ClassVar[NDArray[complex128]] = array([[1.        +0.j        , 0.        +0.j        ],        [0.        +0.j        , 0.70710678-0.70710678j]])
SX: ClassVar[NDArray[complex128]] = array([[0.5+0.5j, 0.5-0.5j],        [0.5-0.5j, 0.5+0.5j]])
SXDG: ClassVar[NDArray[complex128]] = array([[0.5-0.5j, 0.5+0.5j],        [0.5+0.5j, 0.5-0.5j]])
H: ClassVar[NDArray[complex128]] = array([[ 0.70710678+0.j,  0.70710678+0.j],        [ 0.70710678+0.j, -0.70710678+0.j]])
CY: ClassVar[NDArray[complex128]] = array([[ 1.+0.j,  0.+0.j,  0.+0.j,  0.+0.j],        [ 0.+0.j,  1.+0.j,  0.+0.j,  0.+0.j],        [ 0.+0.j,  0.+0.j,  0.+0.j, -0.-1.j],        [ 0.+0.j,  0.+0.j,  0.+1.j,  0.+0.j]])
CZ: ClassVar[NDArray[complex128]] = array([[ 1.+0.j,  0.+0.j,  0.+0.j,  0.+0.j],        [ 0.+0.j,  1.+0.j,  0.+0.j,  0.+0.j],        [ 0.+0.j,  0.+0.j,  1.+0.j,  0.+0.j],        [ 0.+0.j,  0.+0.j,  0.+0.j, -1.+0.j]])
CNOT: ClassVar[NDArray[complex128]] = array([[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],        [0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j],        [0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j],        [0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j]])
SWAP: ClassVar[NDArray[complex128]] = array([[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],        [0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j],        [0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j],        [0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j]])
CCX: ClassVar[NDArray[complex128]] = array([[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],        [0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],        [0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],        [0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],        [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],        [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j],        [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j],        [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j]])
CH: ClassVar[NDArray[complex128]] = array([[ 1.        +0.j,  0.        +0.j,  0.        +0.j,          0.        +0.j],        [ 0.        +0.j,  1.        +0.j,  0.        +0.j,          0.        +0.j],        [ 0.        +0.j,  0.        +0.j,  0.70710678+0.j,          0.70710678+0.j],        [ 0.        +0.j,  0.        +0.j,  0.70710678+0.j,         -0.70710678+0.j]])
CSWAP: ClassVar[NDArray[complex128]] = array([[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],        [0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],        [0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],        [0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],        [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],        [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j],        [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j],        [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j]])
static p(theta: Angle) → NDArray[complex128][source]
static p(theta: Expression) → NDArray[object_]

Phase gate.

We have \(P(\theta) = \mathrm e^{\theta/2} R_Z(\theta)\).

Parameters:

theta (Angle | Expression) – rotation angle in units of π

Returns:

operator

Return type:

2*2 np.asarray

static rx(theta: Angle) → NDArray[complex128][source]
static rx(theta: Expression) → NDArray[object_]

X rotation.

Parameters:

theta (Angle | Expression) – rotation angle in units of π

Returns:

operator

Return type:

2*2 np.asarray

static ry(theta: Angle) → NDArray[complex128][source]
static ry(theta: Expression) → NDArray[object_]

Y rotation.

Parameters:

theta (Angle | Expression) – rotation angle in units of π

Returns:

operator

Return type:

2*2 np.asarray

static rz(theta: Angle) → NDArray[complex128][source]
static rz(theta: Expression) → NDArray[object_]

Z rotation.

Parameters:

theta (Angle | Expression) – rotation angle in units of π

Returns:

operator

Return type:

2*2 np.asarray

static u(theta: ParameterizedAngle, phi: ParameterizedAngle, lambda_: ParameterizedAngle) → npt.NDArray[np.complex128] | npt.NDArray[np.object_][source]

Universal single-qubit gate.

Parameters:
Returns:

operator

Return type:

2*2 np.asarray

static cu(theta: ParameterizedAngle, phi: ParameterizedAngle, lambda_: ParameterizedAngle, gamma: ParameterizedAngle) → npt.NDArray[np.complex128] | npt.NDArray[np.object_][source]

Universal controlled single-qubit gate.

Parameters:
Returns:

operator

Return type:

4*4 np.asarray

static cj(theta: Angle) → NDArray[complex128][source]
static cj(theta: Expression) → NDArray[object_]

Controlled-J gate.

Parameters:

theta (Angle | Expression) – rotation angle in units of π

Returns:

operator

Return type:

4*4 np.asarray

static cp(theta: Angle) → NDArray[complex128][source]
static cp(theta: Expression) → NDArray[object_]

Controlled-phase gate.

Parameters:

theta (Angle | Expression) – rotation angle in units of π

Returns:

operator

Return type:

4*4 np.asarray

static crx(theta: Angle) → NDArray[complex128][source]
static crx(theta: Expression) → NDArray[object_]

Controlled-RX gate.

Parameters:

theta (Angle | Expression) – rotation angle in units of π

Returns:

operator

Return type:

4*4 np.asarray

static cry(theta: Angle) → NDArray[complex128][source]
static cry(theta: Expression) → NDArray[object_]

Controlled-RY gate.

Parameters:

theta (Angle | Expression) – rotation angle in units of π

Returns:

operator

Return type:

4*4 np.asarray

static crz(theta: Angle) → NDArray[complex128][source]
static crz(theta: Expression) → NDArray[object_]

Controlled-RZ gate.

Parameters:

theta (Angle | Expression) – rotation angle in units of π

Returns:

operator

Return type:

4*4 np.asarray

static j(theta: Angle) → NDArray[complex128][source]
static j(theta: Expression) → NDArray[object_]

J operation.

Parameters:

theta (Angle | Expression) – rotation angle in units of π

Returns:

operator

Return type:

2*2 np.asarray

static rzz(theta: Angle) → NDArray[complex128][source]
static rzz(theta: Expression) → NDArray[object_]

zz-rotation.

Equivalent to the sequence cnot(control, target), rz(target, angle), cnot(control, target)

Parameters:

theta (Angle | Expression) – rotation angle in units of π

Returns:

operator

Return type:

4*4 np.asarray

static build_tensor_pauli_ops(n_qubits: int) → NDArray[complex128][source]

Build all the 4^n tensor Pauli operators {I, X, Y, Z}^{otimes n}.

Parameters:

n_qubits (int) – number of copies (qubits) to consider

Returns:

the array of the 4^n operators of shape (2^n, 2^n)

Return type:

np.ndarray

static from_axis(axis: Axis) → NDArray[complex128][source]

Return the matrix representation of an AXIS.

static from_ixyz(ixyz: Literal[SingletonI.I] | Axis) → NDArray[complex128][source]

Return the matrix representation of an IXYZ.