graphix.command module

Data validator command classes.

class CommandKind(*values)[source]

Bases: Enum

Tag for command kind.

N = 1
M = 2
E = 3
C = 4
X = 5
Z = 6
S = 7
T = 8
ApplyNoise = 9
class BaseCommand[source]

Bases: ABC, DataclassReprMixin

Base class for pattern command.

abstractmethod reindex(f: Callable[[Node], Node]) → Self[source]

Return a command whose nodes have been reindexed using f.

class BaseN(node: int)[source]

Bases: BaseCommand

Base preparation command.

Represent a preparation of a node. In graphix package, a preparation is an instance of class N, with an initial state (defaults to PLUS). The base class BaseN allows users to define new class of preparation commands with different abstractions. For example, in the context of blind computations, the server only knows which node is prepared, and the initial state are given by the graphix.simulator.PrepareMethod provided by the client.

Parameters:

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

node: int
kind: ClassVar[Literal[CommandKind.N]] = 1
reindex(f: Callable[[Node], Node]) → Self[source]

Return a command whose nodes have been reindexed using f.

__init__(node: int) → None
class N(node: int, state: State = <factory>)[source]

Bases: BaseN, _KindChecker

Preparation command.

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

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

state: State
kind: ClassVar[Literal[CommandKind.N]] = 1
__init__(node: int, state: State = <factory>) → None
class BaseM(node: int)[source]

Bases: BaseCommand

Base measurement command.

Represent a measurement of a node. In graphix package, a measurement is an instance of class M, with given plane, angles, and domains. The base class BaseM allows users to define new class of measurements with different abstractions. For example, in the context of blind computations, the server only knows which node is measured, and the parameters are given by the graphix.simulator.MeasureMethod provided by the client.

node: int
kind: ClassVar[Literal[CommandKind.M]] = 2
reindex(f: Callable[[Node], Node]) → BaseM[source]

Return a command whose nodes have been reindexed using f.

__init__(node: int) → None
class M(node: int, measurement: Measurement = Measurement.X, s_domain: set[int] = <factory>, t_domain: set[int] = <factory>)[source]

Bases: BaseM, _KindChecker

Measurement command.

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

  • measurement (Measurement) – Measurement description.

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

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

measurement: Measurement = Measurement.X
s_domain: set[int]
t_domain: set[int]
kind: ClassVar[Literal[CommandKind.M]] = 2
clifford(clifford_gate: Clifford) → M[source]

Return a new measurement command with a Clifford applied.

Parameters:

clifford_gate (Clifford) – Clifford gate to apply before the measurement.

Returns:

Equivalent command representing the pattern MC.

Return type:

M

map(f: Callable[[Measurement], Measurement]) → M[source]

Return a measurement command where the function f has been applied to the measurement.

Parameters:

f (Callable[[Measurement], Measurement]) – Function applied to the measurement.

Returns:

The resulting command.

Return type:

M

reindex(f: Callable[[Node], Node]) → M[source]

Return a command whose nodes have been reindexed using f.

__init__(node: int, measurement: Measurement = Measurement.X, s_domain: set[int] = <factory>, t_domain: set[int] = <factory>) → None
class E(nodes: tuple[int, int])[source]

Bases: _KindChecker, BaseCommand

Entanglement command between two qubits.

Parameters:

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

nodes: tuple[int, int]
kind: ClassVar[Literal[CommandKind.E]] = 3
reindex(f: Callable[[Node], Node]) → E[source]

Return a command whose nodes have been reindexed using f.

__init__(nodes: tuple[int, int]) → None
class C(node: int, clifford: Clifford)[source]

Bases: _KindChecker, BaseCommand

Local Clifford gate command.

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

  • clifford (Clifford) – Clifford operator to apply.

node: int
clifford: Clifford
kind: ClassVar[Literal[CommandKind.C]] = 4
reindex(f: Callable[[Node], Node]) → C[source]

Return a command whose nodes have been reindexed using f.

__init__(node: int, clifford: Clifford) → None
class X(node: int, domain: set[int] = <factory>)[source]

Bases: _KindChecker, BaseCommand

X correction command.

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

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

node: int
domain: set[int]
kind: ClassVar[Literal[CommandKind.X]] = 5
reindex(f: Callable[[Node], Node]) → X[source]

Return a command whose nodes have been reindexed using f.

__init__(node: int, domain: set[int] = <factory>) → None
class Z(node: int, domain: set[int] = <factory>)[source]

Bases: _KindChecker, BaseCommand

Z correction command.

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

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

node: int
domain: set[int]
kind: ClassVar[Literal[CommandKind.Z]] = 6
reindex(f: Callable[[Node], Node]) → Z[source]

Return a command whose nodes have been reindexed using f.

__init__(node: int, domain: set[int] = <factory>) → None
class S(node: int, domain: set[int] = <factory>)[source]

Bases: _KindChecker, BaseCommand

S command.

Parameters:
  • node (int) – Node for the byproduct operator.

  • domain (set[int], optional) – Domain on which to apply the operator.

node: int
domain: set[int]
kind: ClassVar[Literal[CommandKind.S]] = 7
reindex(f: Callable[[Node], Node]) → S[source]

Return a command whose nodes have been reindexed using f.

__init__(node: int, domain: set[int] = <factory>) → None
class T[source]

Bases: _KindChecker, BaseCommand

T command.

Parameters:

None – The T command acts globally without parameters.

kind: ClassVar[Literal[CommandKind.T]] = 8
reindex(f: Callable[[Node], Node]) → T[source]

Return a command whose nodes have been reindexed using f.

__init__() → None
class Command[source]

Bases: object

Grouping of all commands for namespace exposure.

Notes

This class is not meant to be instantiated, but rather serves as a namespace for all command types. The type alias for “any command” is CommandKind.

class N(node: int, state: State = <factory>)

Bases: BaseN, _KindChecker

Preparation command.

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

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

__init__(node: int, state: State = <factory>) → None
kind: ClassVar[Literal[CommandKind.N]] = 1
state: State
class M(node: int, measurement: Measurement = Measurement.X, s_domain: set[int] = <factory>, t_domain: set[int] = <factory>)

Bases: BaseM, _KindChecker

Measurement command.

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

  • measurement (Measurement) – Measurement description.

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

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

__init__(node: int, measurement: Measurement = Measurement.X, s_domain: set[int] = <factory>, t_domain: set[int] = <factory>) → None
clifford(clifford_gate: Clifford) → M

Return a new measurement command with a Clifford applied.

Parameters:

clifford_gate (Clifford) – Clifford gate to apply before the measurement.

Returns:

Equivalent command representing the pattern MC.

Return type:

M

kind: ClassVar[Literal[CommandKind.M]] = 2
map(f: Callable[[Measurement], Measurement]) → M

Return a measurement command where the function f has been applied to the measurement.

Parameters:

f (Callable[[Measurement], Measurement]) – Function applied to the measurement.

Returns:

The resulting command.

Return type:

M

measurement: Measurement = Measurement.X
reindex(f: Callable[[Node], Node]) → M

Return a command whose nodes have been reindexed using f.

s_domain: set[int]
t_domain: set[int]
class E(nodes: tuple[int, int])

Bases: _KindChecker, BaseCommand

Entanglement command between two qubits.

Parameters:

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

__init__(nodes: tuple[int, int]) → None
kind: ClassVar[Literal[CommandKind.E]] = 3
reindex(f: Callable[[Node], Node]) → E

Return a command whose nodes have been reindexed using f.

nodes: tuple[int, int]
class C(node: int, clifford: Clifford)

Bases: _KindChecker, BaseCommand

Local Clifford gate command.

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

  • clifford (Clifford) – Clifford operator to apply.

__init__(node: int, clifford: Clifford) → None
kind: ClassVar[Literal[CommandKind.C]] = 4
reindex(f: Callable[[Node], Node]) → C

Return a command whose nodes have been reindexed using f.

node: int
clifford: Clifford
class X(node: int, domain: set[int] = <factory>)

Bases: _KindChecker, BaseCommand

X correction command.

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

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

__init__(node: int, domain: set[int] = <factory>) → None
kind: ClassVar[Literal[CommandKind.X]] = 5
reindex(f: Callable[[Node], Node]) → X

Return a command whose nodes have been reindexed using f.

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

Bases: _KindChecker, BaseCommand

Z correction command.

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

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

__init__(node: int, domain: set[int] = <factory>) → None
kind: ClassVar[Literal[CommandKind.Z]] = 6
reindex(f: Callable[[Node], Node]) → Z

Return a command whose nodes have been reindexed using f.

node: int
domain: set[int]
class S(node: int, domain: set[int] = <factory>)

Bases: _KindChecker, BaseCommand

S command.

Parameters:
  • node (int) – Node for the byproduct operator.

  • domain (set[int], optional) – Domain on which to apply the operator.

__init__(node: int, domain: set[int] = <factory>) → None
kind: ClassVar[Literal[CommandKind.S]] = 7
reindex(f: Callable[[Node], Node]) → S

Return a command whose nodes have been reindexed using f.

node: int
domain: set[int]
class T

Bases: _KindChecker, BaseCommand

T command.

Parameters:

None – The T command acts globally without parameters.

__init__() → None
kind: ClassVar[Literal[CommandKind.T]] = 8
reindex(f: Callable[[Node], Node]) → T

Return a command whose nodes have been reindexed using f.

__init__() → None[source]
CommandType: TypeAlias
Correction: TypeAlias