pattern#

Measurement pattern

Classes

Pattern([nodes_state, state, edges, nodes, ...])

Measurement-based quantum computing (MBQC) pattern.

class Pattern(nodes_state: int | list[int] | None = None, state: Any = 'plus', edges: list | None = None, nodes: int | list[int] | None = None, name: str | None = None, reupload: bool = False)[source]#

Bases: Operation

Measurement-based quantum computing (MBQC) pattern.

A pattern represents a measurement-based quantum computation, which consists of a sequence of commands (node preparation, entanglement, measurement, and correction) applied to qubits arranged in a graph structure.

Parameters:
  • nodes_state (int | list[int] | None) – The nodes of the input state in the initial graph state. It can be an integer representing the number of nodes or a list of node indices. Default: None

  • state (Any) – The input state of the initial graph state. The string representation of state could be 'plus', 'minus', 'zero', and 'one'. Default: 'plus'

  • edges (list | None) – Additional edges connecting the nodes in the initial graph state. Default: None

  • nodes (int | list[int] | None) – Additional nodes to include in the initial graph state. Default: None

  • name (str | None) – The name of the pattern. Default: None

  • reupload (bool) – Whether to use data re-uploading. Default: False

Ref: V. Danos, E. Kashefi and P. Panangaden. J. ACM 54.2 8 (2007)

add(op: Operation, encode: bool = False) None[source]#

A method that adds an operation to the MBQC pattern.

Parameters:
  • op (Operation) – The operation to add. It is an instance of Operation class or its subclasses, such as Node, Entanglement, Measurement, or Correction.

  • encode (bool) – Whether the command is to encode data. Default: False

add_graph(nodes_state: int | list[int] | None = None, state: Any = 'plus', edges: list | None = None, nodes: int | list[int] | None = None, index: int | None = None) None[source]#

Add a subgraph state to the graph state.

Parameters:
  • nodes_state (int | list[int] | None) – The nodes of the input state in the subgraph state. It can be an integer representing the number of nodes or a list of node indices. Default: None

  • state (Any) – The input state of the subgraph state. The string representation of state could be 'plus', 'minus', 'zero', and 'one'. Default: 'plus'

  • edges (list | None) – Additional edges connecting the nodes in the subgraph state. Default: None

  • nodes (int | list[int] | None) – Additional nodes to include in the subgraph state. Default: None

  • index (int | None) – The index where to insert the subgraph state. Default: None

draw()[source]#

Draw the MBQC pattern.

e(node1: int, node2: int) None[source]#

Add an entanglement command.

encode(data: Tensor | None) None[source]#

Encode the input data into the measurement angles as parameters.

This method iterates over the encoders of the MBQC pattern and initializes their parameters with the input data. If reupload is False, the input data must be at least as long as the number of parameters in the encoders. If reupload is True, the input data can be repeated to fill up the parameters.

Parameters:

data (Tensor | None) – The input data for the encoders, could be a 1D or 2D tensor.

Raises:

AssertionError – If input data is shorter than the number of parameters in the encoders.

forward(data: Tensor | None = None, state: GraphState | None = None) GraphState[source]#

Perform a forward pass of the MBQC pattern and return the final graph state.

Parameters:
  • data (Tensor | None) – The input data for the encoders. Default: None

  • state (GraphState | None) – The initial graph state for the pattern. Default: None

Returns:

The final graph state of the pattern after applying the commands.

Return type:

GraphState

property graph: SubGraphState#

The combined graph state of the initial or final graph state.

is_standard() bool[source]#

Determine whether the command sequence is standard.

Returns:

True if the pattern follows NEMC standardization, False otherwise

Return type:

bool

m(node: int, angle: float = 0.0, plane: str = 'xy', t_domain: int | Iterable[int] | None = None, s_domain: int | Iterable[int] | None = None, encode: bool = False) None[source]#

Add a measurement command.

n(nodes: int | list[int]) None[source]#

Add a node command.

set_nodes_out_seq(nodes: list[int] | None = None) None[source]#

Set the output sequence of the nodes.

shift_signals() dict[source]#

Perform signal shifting procedure.

This allows one to dispose of dependencies induced by the Z-action, and obtain sometimes standard patterns with smaller computational depth complexity.

It handles the propagation of signal shifting commands by: 1. Extracting signals via t_domain (in XY plane cases) of measurements. 2. Moving signals to the left, through modifying other measurements and corrections.

See https://arxiv.org/pdf/0704.1263 Ch.(5.5)

Returns:

A signal dictionary including all the signal shifting commands.

Return type:

dict

standardize() None[source]#

Standardize the command sequence into NEMC form.

This function reorders operations into the standard form: - Node preparations (N) - Entanglement operations (E) - Measurement operations (M) - Correction operations (C)

It handles the propagation of correction operations by: 1. Moving X-corrections through entanglements (generating Z-corrections) 2. Moving corrections through measurements (modifying measurement signal domains) 3. Collecting remaining corrections at the end

See https://arxiv.org/pdf/0704.1263 Ch.(5.4)

x(node: int, domain: int | Iterable[int] | None = None) None[source]#

Add an X-correction command.

z(node: int, domain: int | Iterable[int] | None = None) None[source]#

Add a Z-correction command.