Pattern data structure

graphix.command module

This module defines standard data structure for pattern commands.

Data validator command classes.

class graphix.command.CommandKind(value)[source]

Tag for command kind.

class graphix.command.N(node: int, state: ~graphix.states.State = <factory>)[source]

Preparation command.

Parameters:
  • node (int) – Index of the qubit to prepare.

  • state (State, optional) – Initial state, defaults to PLUS.

class graphix.command.M(node: int, plane: ~graphix.fundamentals.Plane = Plane.XY, angle: ~graphix.parameter.Expression | float = 0.0, s_domain: set[int] = <factory>, t_domain: set[int] = <factory>)[source]

Measurement command.

Parameters:
  • node (int) – Node index of the measured qubit.

  • plane (Plane, optional) – Measurement plane, defaults to XY.

  • angle (ExpressionOrFloat, optional) – Rotation angle divided by \(\pi\).

  • s_domain (set[int], optional) – Domain for the X byproduct operator.

  • t_domain (set[int], optional) – Domain for the Z byproduct operator.

class graphix.command.E(nodes: tuple[int, int])[source]

Entanglement command between two qubits.

Parameters:

nodes (tuple[int, int]) – Pair of nodes to entangle.

class graphix.command.C(node: int, clifford: Clifford)[source]

Local Clifford gate command.

Parameters:
  • node (int) – Node index on which to apply the gate.

  • clifford (Clifford) – Clifford operator to apply.

class graphix.command.X(node: int, domain: set[int] = <factory>)[source]

X correction command.

Parameters:
  • node (int) – Node to correct.

  • domain (set[int], optional) – Domain for the byproduct operator.

class graphix.command.Z(node: int, domain: set[int] = <factory>)[source]

Z correction command.

Parameters:
  • node (int) – Node to correct.

  • domain (set[int], optional) – Domain for the byproduct operator.

class graphix.command.MeasureUpdate(new_plane: Plane, coeff: int, add_term: float)[source]

Describe how a measure is changed by signals and a vertex operator.

Parameters:
  • new_plane (Plane) – Updated measurement plane after commuting gates.

  • coeff (int) – Coefficient by which the angle is multiplied.

  • add_term (float) – Additional term to add to the measurement angle.

graphix.fundamentals module

This module defines standard data structure for Pauli operators.

Fundamental components related to quantum mechanics.

class graphix.fundamentals.Axis(value)[source]

Axis: X, Y or Z.

property matrix: npt.NDArray[np.complex128]

Return the matrix representation.

to_plane_or_axis() Axis[source]

Return the plane or axis of a measurement object.

Return type:

Plane | Axis

class graphix.fundamentals.ComplexUnit(value)[source]

Complex unit: 1, -1, j, -j.

Complex units can be multiplied with other complex units, with Python constants 1, -1, 1j, -1j, and can be negated.

static from_properties(*, sign: Sign = Sign.PLUS, is_imag: bool = False) ComplexUnit[source]

Construct ComplexUnit from its properties.

property is_imag: bool

Return True if j or -j.

property sign: Sign

Return the sign.

static try_from(value: ComplexUnit | SupportsComplex | SupportsFloat | SupportsIndex | complex) ComplexUnit | None[source]

Return the ComplexUnit instance if the value is compatible, None otherwise.

class graphix.fundamentals.Sign(value)[source]

Sign, plus or minus.

static minus_if(b: bool) Sign[source]

Return - if b is True, + otherwise.

static plus_if(b: bool) Sign[source]

Return + if b is True, - otherwise.

class graphix.fundamentals.IXYZ(value)[source]

I, X, Y or Z.

property matrix: npt.NDArray[np.complex128]

Return the matrix representation.

class graphix.fundamentals.Plane(value)[source]

Plane: XY, YZ or XZ.

property axes: tuple[Axis, Axis]

Return the pair of axes that carry the plane.

property cos: Axis

Return the axis of the plane that conventionally carries the cos.

static from_axes(a: Axis, b: Axis) Plane[source]

Return the plane carried by the given axes.

property orth: Axis

Return the axis orthogonal to the plane.

polar(angle: float) tuple[float, float, float][source]
polar(angle: Expression) tuple[Expression, Expression, Expression]

Return the Cartesian coordinates of the point of module 1 at the given angle, following the conventional orientation for cos and sin.

property sin: Axis

Return the axis of the plane that conventionally carries the sin.

to_plane() Plane[source]

Return the plane.

Return type:

Plane

to_plane_or_axis() Plane[source]

Return the plane.

Return type:

Plane

graphix.pauli module

This module defines standard data structure for Pauli operators.

Pauli gates ± {1,j} × {I, X, Y, Z}.

class graphix.pauli.Pauli(symbol: IXYZ = IXYZ.I, unit: ComplexUnit = ComplexUnit.ONE)[source]

Pauli gate: u * {I, X, Y, Z} where u is a complex unit.

Pauli gates can be multiplied with other Pauli gates (with @), with complex units and unit constants (with *), and can be negated.

graphix.measurements module

This module defines data structures for single-qubit measurements in MBQC.

Data structure for single-qubit measurements in MBQC.

class graphix.measurements.Measurement(angle: Expression | float, plane: Plane)[source]

An MBQC measurement.

angle

The angle of the measurement in units of \(\pi\). Should be between [0, 2).

Type:

Expressionor Float

plane

The measurement plane.

Type:

graphix.fundamentals.Plane

__init__(angle: Expression | float, plane: Plane) None
isclose(other: Measurement, rel_tol: float = 1e-09, abs_tol: float = 0.0) bool[source]

Compare if two measurements have the same plane and their angles are close.

Example

>>> from graphix.measurements import Measurement
>>> from graphix.fundamentals import Plane
>>> Measurement(0.0, Plane.XY).isclose(Measurement(0.0, Plane.XY))
True
>>> Measurement(0.0, Plane.XY).isclose(Measurement(0.0, Plane.YZ))
False
>>> Measurement(0.1, Plane.XY).isclose(Measurement(0.0, Plane.XY))
False
to_plane() Plane[source]

Return the measurement’s plane.

Return type:

Plane

to_plane_or_axis() Plane | Axis[source]

Return the measurements’s plane or axis.

Return type:

Plane | Axis

Notes

Measurements with Pauli angles (i.e., self.angle == n/2 with n an integer) are interpreted as Axis instances.

graphix.instruction module

This module defines standard data structure for gate seqence (circuit model) used for graphix.transpiler.Circuit.

Instruction classes.

class graphix.instruction.InstructionKind(value)[source]

Tag for instruction kind.

class graphix.instruction.RX(target: int, angle: Expression | float, meas_index: int | None = None)[source]

X rotation circuit instruction.

class graphix.instruction.RZ(target: int, angle: Expression | float, meas_index: int | None = None)[source]

Z rotation circuit instruction.

class graphix.instruction.RY(target: int, angle: Expression | float, meas_index: int | None = None)[source]

Y rotation circuit instruction.

class graphix.instruction.M(target: int, plane: Plane, angle: Expression | float)[source]

M circuit instruction.

class graphix.instruction.X(target: int)[source]

X circuit instruction.

class graphix.instruction.Y(target: int)[source]

Y circuit instruction.

class graphix.instruction.Z(target: int)[source]

Z circuit instruction.

class graphix.instruction.S(target: int)[source]

S circuit instruction.

class graphix.instruction.H(target: int)[source]

H circuit instruction.

class graphix.instruction.SWAP(targets: tuple[int, int])[source]

SWAP circuit instruction.

class graphix.instruction.CNOT(target: int, control: int)[source]

CNOT circuit instruction.

graphix.parameter module

This module defines parameter objects and parameterized expressions. Parameterized expressions can appear in measurement angles in patterns and rotation angles in circuits, and they can be substituted with actual values.

The module provides generic interfaces for parameters and expressions, as well as a simple Placeholder class that can be used in affine expressions (AffineExpression). Affine expressions are sufficient for transpiling and pattern optimizations (such as standardization, minimization, signal shifting, and Pauli preprocessing), but they do not support simulation.

Parameter objects that support symbolic simulation with sympy are available in a separate package: https://github.com/TeamGraphix/graphix-symbolic.

class graphix.parameter.Expression[source]

Expression with parameters.

class graphix.parameter.Parameter[source]

Abstract class for substituable parameter.

class graphix.parameter.AffineExpression(a: float, x: Parameter, b: float)[source]

Affine expression.

An affine expression is of the form a*x+b where a and b are numbers and x is a parameter.

class graphix.parameter.Placeholder(name: str)[source]

Placeholder for measurement angles.

These placeholder may appear in affine expressions. Placeholders and affine expressions may be used as angles in rotation gates of Circuit class or for the measurement angle of the measurement commands. Pattern optimizations such that standardization, signal shifting and Pauli preprocessing can be applied to patterns with placeholders.

These placeholders and affine expressions do not support arbitrary computation and are not suitable for simulation. You may use Circuit.subs() or Pattern.subs() with an actual value before the computation.

graphix.states module

Quantum states and operators.

class graphix.states.State[source]

Abstract base class for single qubit states objects.

Only requirement for concrete classes is to have a get_statevector() method that returns the statevector representation of the state