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], plane: str = 'xy', angle: Any = 0.0, 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.
plane (str, optional) – The measurement plane (
'xy'
,'yz'
or'zx'
). Default:'xy'
angle (Any, optional) – The measurement angle in radians. Default: 0.
s_domain (Union[int, Iterable[int], None], optional) – The indices of the nodes that contribute to signal domain s. Default:
None
t_domain (Union[int, Iterable[int], 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
orbuffer
. Default:False
(which meansbuffer
)
- 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)#
基类:
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) – The nodes of the input state in the subgraph. It can be an integer representing the number of nodes or a list of node indices. Default:
None
.state (Any, optional) – The initial state of the subgraph. Default:
'plus'
.edges (List or None, optional) – Additional edges connecting the nodes in the subgraph. Default:
None
.nodes (int, List[int] or None, optional) – Additional nodes to include in the subgraph. Default:
None
.name (str or None, optional) – The name of the pattern. Default:
None
Ref: V. Danos, E. Kashefi and P. Panangaden. J. ACM 54.2 8 (2007)
- forward(data: Tensor | None = None, state: GraphState | None = None) Tensor #
Perform a forward pass of the MBQC pattern and return the final graph state.
- 参数:
data (torch.Tensor or None, optional) – The input angle data for the
encoders
. Default:None
state (GraphState or None, optional) – The initial state for the pattern. Default:
None
- 返回:
The final graph state of the pattern after applying the
commands
.- 返回类型:
- 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 to the graph state.
- 参数:
nodes_state (int, List[int] or None) – The nodes of the input state in the subgraph. It can be an integer representing the number of nodes or a list of node indices. Default:
None
.state (Any, optional) – The initial state of the subgraph. Default:
'plus'
.edges (List or None, optional) – Additional edges connecting the nodes in the subgraph. Default:
None
.nodes (int, List[int] or None, optional) – Additional nodes to include in the subgraph. Default:
None
.measure_dict (Dict, optional) – A dictionary to record measurement results. Default:
None
.index (int or None, optional) – The index where to insert the subgraph. Default:
None
.
- get_graph()#
- 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 asNode
, orMeasurement
.encode (bool) – Whether the command encodes data. Default:
False
- encode(data: Tensor | None) None #
Encode the input data into measurement angle as parameters.
This method iterates over the
encoders
of the pattern(encode=True
measurements) and initializes their parameters with the input data. The input data must be at least as long as the number of parameters in theencoders
.- 参数:
data (torch.Tensor or None) – The input data for the
encoders
, must be a 1D tensor.- 抛出:
AssertionError – If input data is shorter than the number of parameters in the
encoders
.
- n(node: int | List[int])#
Add a new node to the pattern.
- 参数:
node (int or List[int]) – Index or list of indices for the new node.
- e(node: List[int])#
Add an entanglement operators on two nodes in the pattern.
- 参数:
node (List[int]) – A list of two integers specifying the nodes to entangle. Must reference existing nodes in the pattern.
- m(node: int, plane: str | None = 'xy', angle: float = 0.0, t_domain: int | Iterable[int] | None = None, s_domain: int | Iterable[int] | None = None, encode: bool = False)#
Add a measurement operation to the pattern.
- 参数:
node (int) – The node to measure.
plane (str, optional) – Measurement plane (‘xy’, ‘yz’, or ‘xz’). Defaults to ‘xy’.
angle (float) – Measurement angle in radians. Defaults to 0.
t_domain (int, Iterable[int] or None], optional) – List of nodes that contribute to the Z correction. Default: None
s_domain (int, Iterable[int] or None], optional) – List of nodes that contribute to the X correction. Default: None
encode (bool) – Whether to encode angle. Default:
False
.
- c_x(node: int, domain: int | Iterable[int] | None = None)#
Add an X correction operation to the pattern.
- 参数:
node (int) – The node to apply the X correction.
domain (int, Iterable[int] or None], optional) – List of nodes on which the signal depends. Default: None
- c_z(node: int, domain: int | Iterable[int] | None = None)#
Add a Z correction operation to the pattern.
- 参数:
node (int) – The node to apply the Z correction.
domain (int, Iterable[int] or None], optional) – List of nodes on which the signal depends. Default: None
- draw(width: int = 4)#
Draw the MBQC pattern.
- is_standard() bool #
Determine whether the command sequence is standard.
- 返回:
A bool value, True if the pattern follows NEMC standardization, False otherwise
- standardize()#
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.
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. It can be an integer representing the number of nodes or a list of node indices. Default:
None
.state (Any, optional) – The initial state of the subgraph. Default:
'plus'
.edges (List or None, optional) – Additional edges connecting the nodes in the subgraph. Default:
None
.nodes (int, List[int] or None, optional) – Additional nodes to include in the subgraph. 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.
- 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 quantum state of the subgraph.
- add_nodes(nodes: int | List[int]) None #
Add nodes to the subgraph.
- add_edges(edges: List) None #
Add edges to the subgraph.
- 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.
- 返回类型:
- 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 subgraph. It can be an integer representing the number of nodes or a list of node indices. Default:
None
.state (Any, optional) – The initial state of the subgraph. Default:
'plus'
.edges (List or None, optional) – Additional edges connecting the nodes in the subgraph. Default:
None
.nodes (int, List[int] or None, optional) – Additional nodes to include in the subgraph. 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 to the graph state.
- 参数:
nodes_state (int, List[int] or None, optional) – The nodes of the input state in the subgraph. It can be an integer representing the number of nodes or a list of node indices. Default:
None
.state (Any, optional) – The initial state of the subgraph. Default:
'plus'
.edges (List or None, optional) – Additional edges connecting the nodes in the subgraph. Default:
None
.nodes (int, List[int] or None, optional) – Additional nodes to include in the subgraph. Default:
None
.measure_dict (Dict or None, optional) – A dictionary to record measurement results. Default:
None
.index (int or None, optional) – The index where to insert the subgraph. Default:
None
.
- property graph: SubGraphState#
The combined graph of all subgraphs.
- property measure_dict: Dict#
A dictionary containing all measurement results for the graph state.
Module contents#
MBQC Module