deepquantum.mbqc package#

Submodules#

deepquantum.mbqc.command module#

MBQC commands

class deepquantum.mbqc.command.Node(nodes: int | List[int])#

基类:Command

Node (qubit) preparation command.

参数:

nodes (int or List[int]) – The indices of the nodes to prepare.

forward(x: GraphState) GraphState#

Perform a forward pass by adding SubGraphState in the GraphState.

class deepquantum.mbqc.command.Entanglement(node1: int, node2: int)#

基类:Command

Entanglement command.

参数:
  • node1 (int) – The first node index.

  • node2 (int) – The second node index.

forward(x: GraphState) GraphState#

Perform a forward pass by adding an edge in the GraphState.

class deepquantum.mbqc.command.Measurement(nodes: int | List[int], angle: Any = 0.0, plane: str = 'xy', s_domain: int | Iterable[int] | None = None, t_domain: int | Iterable[int] | None = None, requires_grad: bool = False)#

基类:Command

Measurement command.

参数:
  • nodes (int or List[int]) – The indices of the nodes to measure.

  • angle (Any, optional) – The measurement angle in radians. Default: 0.

  • plane (str, optional) – The measurement plane ('xy', 'yz' or 'zx'). Default: 'xy'

  • s_domain (int, Iterable[int] or None, optional) – The indices of the nodes that contribute to signal domain s. Default: None

  • t_domain (int, Iterable[int] or None, optional) – The indices of the nodes that contribute to signal domain t. Default: None

  • requires_grad (bool, optional) – Whether the parameter is nn.Parameter or buffer. Default: False (which means buffer)

inputs_to_tensor(inputs: Any | None = None) Tensor#

Convert inputs to torch.Tensor.

forward(x: GraphState) GraphState#

Perform a forward pass by measuring the GraphState.

init_para(angle: Any | None = None) None#

Initialize the parameters.

class deepquantum.mbqc.command.Correction(nodes: int | List[int], basis: str = 'x', domain: int | Iterable[int] | None = None)#

基类:Command

Correction command.

参数:
  • nodes (int or List[int]) – The indices of the nodes to correct.

  • basis (str, optional) – The type of correction ('x' or 'z'). Default: 'x'

  • domain (Union[int, Iterable[int], None], optional) – The indices of the nodes that contribute to signal domain s. Default: None

forward(x: GraphState) GraphState#

Perform a forward pass by correcting the GraphState.

deepquantum.mbqc.operation module#

Base classes

class deepquantum.mbqc.operation.Operation(name: str | None = None, nodes: int | List[int] | None = None)#

基类:Module

A base class for quantum operations.

参数:
  • name (str or None, optional) – The name of the quantum operation. Default: None

  • nodes (int, List[int] or None, optional) – The indices of the nodes that the quantum operation acts on. Default: None

class deepquantum.mbqc.operation.Command(name: str, nodes: int | List[int])#

基类:Operation

A base class for MBQC commands.

参数:
  • name (str) – The name of the command.

  • nodes (int or List[int]) – The indices of the nodes that the command acts on.

forward(x: GraphState) GraphState#

Perform a forward pass.

deepquantum.mbqc.pattern module#

Measurement pattern

class deepquantum.mbqc.pattern.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)#

基类: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.

参数:
  • nodes_state (int, List[int] or None, optional) – 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, optional) – The input state of the initial graph state. The string representation of state could be 'plus', 'minus', 'zero', and 'one'. Default: 'plus'

  • edges (List or None, optional) – Additional edges connecting the nodes in the initial graph state. Default: None

  • nodes (int, List[int] or None, optional) – Additional nodes to include in the initial graph state. Default: None

  • name (str or None, optional) – The name of the pattern. Default: None

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

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

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

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

参数:
  • data (torch.Tensor or None, optional) – The input data for the encoders. Default: None

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

返回:

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

返回类型:

GraphState

encode(data: Tensor | None) None#

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.

参数:

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

抛出:

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

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#

Add a subgraph state to the graph state.

参数:
  • nodes_state (int, List[int] or None, optional) – 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, optional) – The input state of the subgraph state. The string representation of state could be 'plus', 'minus', 'zero', and 'one'. Default: 'plus'

  • edges (List or None, optional) – Additional edges connecting the nodes in the subgraph state. Default: None

  • nodes (int, List[int] or None, optional) – Additional nodes to include in the subgraph state. Default: None

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

property graph: SubGraphState#

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

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

Set the output sequence of the nodes.

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

A method that adds an operation to the MBQC pattern.

参数:
  • 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

n(nodes: int | List[int]) None#

Add a node command.

e(node1: int, node2: int) None#

Add an entanglement command.

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#

Add a measurement command.

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

Add an X-correction command.

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

Add a Z-correction command.

draw()#

Draw the MBQC pattern.

is_standard() bool#

Determine whether the command sequence is standard.

返回:

True if the pattern follows NEMC standardization, False otherwise

返回类型:

bool

standardize() None#

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)

shift_signals() Dict#

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.

返回:

A signal dictionary including all the signal shifting commands.

返回类型:

Dict

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

deepquantum.mbqc.state module#

Quantum states

class deepquantum.mbqc.state.SubGraphState(nodes_state: int | List[int] | None = None, state: Any = 'plus', edges: List | None = None, nodes: int | List[int] | None = None)#

基类:Module

A subgraph state of a quantum state.

参数:
  • nodes_state (int, List[int] or None, optional) – 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, optional) – The input state of the subgraph state. The string representation of state could be 'plus', 'minus', 'zero', and 'one'. Default: 'plus'

  • edges (List or None, optional) – Additional edges connecting the nodes in the subgraph state. Default: None

  • nodes (int, List[int] or None, optional) – Additional nodes to include in the subgraph state. Default: None

property nodes#

Nodes of the graph.

property edges#

Edges of the graph.

property full_state: Tensor#

Compute and return the full quantum state of the subgraph state.

set_graph(nodes_state: int | List[int] | None = None, edges: List | None = None, nodes: int | List[int] | None = None) None#

Set the graph structure for the subgraph state.

set_state(state: Any = 'plus') None#

Set the input state of the subgraph state.

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

Set the output sequence of the nodes.

add_nodes(nodes: int | List[int]) None#

Add nodes to the subgraph state.

add_edges(edges: List) None#

Add edges to the subgraph state.

shift_labels(n: int) None#

Shift the labels of the nodes in the graph by a given integer.

compose(other: SubGraphState, relabel: bool = True) SubGraphState#

Compose this subgraph state with another subgraph state.

参数:
  • other (SubGraphState) – The other subgraph state to compose with.

  • relabel (bool, optional) – Whether to relabel nodes to avoid conflicts. Default: True

返回:

A new subgraph state that is the composition of the two.

返回类型:

SubGraphState

update_node2wire_dict() Dict#

Update the mapping from nodes to wire indices.

返回:

A dictionary mapping nodes to their corresponding wire indices.

返回类型:

Dict

draw(**kwargs)#

Draw the graph using NetworkX.

class deepquantum.mbqc.state.GraphState(nodes_state: int | List[int] | None = None, state: Any = 'plus', edges: List | None = None, nodes: int | List[int] | None = None)#

基类:Module

A graph state composed by several SubGraphStates.

参数:
  • nodes_state (int, List[int] or None, optional) – 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, optional) – The input state of the initial graph state. The string representation of state could be 'plus', 'minus', 'zero', and 'one'. Default: 'plus'

  • edges (List or None, optional) – Additional edges connecting the nodes in the initial graph state. Default: None

  • nodes (int, List[int] or None, optional) – Additional nodes to include in the initial graph state. Default: None

add_subgraph(nodes_state: int | List[int] | None = None, state: Any = 'plus', edges: List | None = None, nodes: int | List[int] | None = None, measure_dict: Dict | None = None, index: int | None = None) None#

Add a subgraph state to the graph state.

参数:
  • nodes_state (int, List[int] or None, optional) – 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, optional) – The input state of the subgraph state. The string representation of state could be 'plus', 'minus', 'zero', and 'one'. Default: 'plus'

  • edges (List or None, optional) – Additional edges connecting the nodes in the subgraph state. Default: None

  • nodes (int, List[int] or None, optional) – Additional nodes to include in the subgraph state. Default: None

  • measure_dict (Dict or None, optional) – A dictionary containing all measurement results. Default: None

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

property graph: SubGraphState#

The combined graph state of all subgraph states.

property full_state: Tensor#

Compute and return the full quantum state of the graph state.

property measure_dict: Dict#

A dictionary containing all measurement results for the graph state.

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

Set the output sequence of the nodes.

Module contents#

MBQC Module