Pattern Manipulation¶
graphix.pattern module¶
- class graphix.pattern.Pattern(input_nodes: list[int] | None = None)[source]¶
MBQC pattern class.
Pattern holds a sequence of commands to operate the MBQC (Pattern.seq), and provide modification strategies to improve the structure and simulation efficiency of the pattern accoring to measurement calculus.
ref: V. Danos, E. Kashefi and P. Panangaden. J. ACM 54.2 8 (2007)
- list(self)¶
list of commands.
each command is a list [type, nodes, attr] which will be applied in the order of list indices.type: one of {‘N’, ‘M’, ‘E’, ‘X’, ‘Z’, ‘S’, ‘C’}nodes: int for {‘N’, ‘M’, ‘X’, ‘Z’, ‘S’, ‘C’} commands, tuple (i, j) for {‘E’} commandattr for N: noneattr for M: meas_plane, angle, s_domain, t_domainattr for X: signal_domainattr for Z: signal_domainattr for S: signal_domainattr for C: clifford_index, as defined ingraphix.clifford
- n_node¶
total number of nodes in the resource state
- Type:
int
- __init__(input_nodes: list[int] | None = None) None[source]¶
Construct a pattern.
- Parameters:
input_nodes – optional, list of input qubits
- add(cmd: N | M | E | C | X | Z | S | T) None[source]¶
Add command to the end of the pattern.
An MBQC command is an instance of
graphix.command.Command.- Parameters:
cmd (
graphix.command.Command) – MBQC command.
- extend(cmds: list[N | M | E | C | X | Z | S | T]) None[source]¶
Add a list of commands.
- Parameters:
cmds – list of commands
- replace(cmds: list[N | M | E | C | X | Z | S | T], input_nodes=None) None[source]¶
Replace pattern with a given sequence of pattern commands.
- Parameters:
cmds – list of commands
input_nodes – optional, list of input qubits (by default, keep the same input nodes as before)
- reorder_output_nodes(output_nodes: list[int])[source]¶
Arrange the order of output_nodes.
- Parameters:
output_nodes (list of int) – output nodes order determined by user. each index corresponds to that of logical qubits.
- reorder_input_nodes(input_nodes: list[int])[source]¶
Arrange the order of input_nodes.
- Parameters:
input_nodes (list of int) – input nodes order determined by user. each index corresponds to that of logical qubits.
- simulate_pattern(backend: str = 'statevector', input_state: BasicStates = graphix.states.PlanarState(Plane.XY, 0.0), **kwargs) State[source]¶
Simulate the execution of the pattern by using
graphix.simulator.PatternSimulator.Available backend: [‘statevector’, ‘densitymatrix’, ‘tensornetwork’]
- Parameters:
backend (str) – optional parameter to select simulator backend.
kwargs (keyword args for specified backend.)
- Returns:
state – quantum state representation for the selected backend.
See also
- get_max_degree()[source]¶
Get max degree of a pattern.
- Returns:
max_degree – max degree of a pattern
- Return type:
int
- get_angles()[source]¶
Get measurement angles of the pattern.
- Returns:
angles – measurement angles of the each node.
- Return type:
dict
- get_vops(conj=False, include_identity=False)[source]¶
Get local-Clifford decorations from measurement or Clifford commands.
- Parameters:
(False) (include_identity) – Apply conjugations to all local Clifford operators.
(False) – Whether or not to include identity gates in the output
- Returns:
vops
- Return type:
dict
- connected_nodes(node, prepared=None)[source]¶
Find nodes that are connected to a specified node.
These nodes must be in the statevector when the specified node is measured, to ensure correct computation. If connected nodes already exist in the statevector (prepared), then they will be ignored as they do not need to be prepared again.
- Parameters:
node (int) – node index
prepared (list) – list of node indices, which are to be ignored
- Returns:
node_list – list of nodes that are entangled with specified node
- Return type:
list
- run_pattern(backend, **kwargs)[source]¶
Run the pattern on cloud-based quantum devices and their simulators.
Available backend: [‘ibmq’]
- Parameters:
backend (str) – parameter to select executor backend.
kwargs (keyword args for specified backend.)
- Returns:
the measurement result, in the representation depending on the backend used.
- Return type:
result
- perform_pauli_measurements(leave_input: bool = False, ignore_pauli_with_deps: bool = False) None[source]¶
Perform Pauli measurements in the pattern using efficient stabilizer simulator.
- Parameters:
leave_input (bool) – Optional (False by default). If True, measurements on input nodes are preserved as-is in the pattern.
ignore_pauli_with_deps (bool) – Optional (False by default). If True, Pauli measurements with domains depending on other measures are preserved as-is in the pattern. If False, all Pauli measurements are preprocessed. Formally, measurements are swapped so that all Pauli measurements are applied first, and domains are updated accordingly.
seealso: (..) –
measure_pauli():
- print_pattern(lim=40, target: list[CommandKind] | None = None) None[source]¶
Print the pattern sequence (Pattern.seq).
- Parameters:
lim (int, optional) – maximum number of commands to show
target (list of CommandKind, optional) – show only specified commands, e.g. [CommandKind.M, CommandKind.X, CommandKind.Z]
- standardize(method='direct') None[source]¶
Execute standardization of the pattern.
‘standard’ pattern is one where commands are sorted in the order of ‘N’, ‘E’, ‘M’ and then byproduct commands (‘X’ and ‘Z’).
- Parameters:
method (str, optional) – ‘mc’ corresponds to a conventional standardization defined in original measurement calculus paper, executed on Pattern class. ‘direct’ fast standardization implemented as standardize_direct() defaults to ‘direct’
- shift_signals(method='direct') dict[int, list[int]][source]¶
Perform signal shifting procedure.
Extract the t-dependence of the measurement into ‘S’ commands and commute them to the end of the command sequence where it can be removed. This procedure simplifies the dependence structure of the pattern.
- Ref for the original ‘mc’ method:
Danos, E. Kashefi and P. Panangaden. J. ACM 54.2 8 (2007)
- Parameters:
method (str, optional) – ‘direct’ shift_signals is executed on a conventional Pattern sequence. ‘mc’ shift_signals is done using the original algorithm on the measurement calculus paper.
- Returns:
signal_dict – For each node, the signal that have been shifted.
- Return type:
dict[int, list[int]]
- is_standard()[source]¶
Determine whether the command sequence is standard.
- Returns:
is_standard – True if the pattern is standard
- Return type:
bool
- get_graph() tuple[list[int], list[tuple[int, int]]][source]¶
Return the list of nodes and edges from the command sequence, extracted from ‘N’ and ‘E’ commands.
- Returns:
node_list (list) – list of node indices.
edge_list (list) – list of tuples (i,j) specifying edges
- parallelize_pattern()[source]¶
Optimize the pattern to reduce the depth of the computation by gathering measurement commands that can be performed simultaneously.
This optimized pattern runs efficiently on GPUs and quantum hardwares with depth (e.g. coherence time) limitations.
- minimize_space() None[source]¶
Optimize the pattern to minimize the max_space property of the pattern.
The optimized pattern has significantly reduced space requirement (memory space for classical simulation, and maximum simultaneously prepared qubits for quantum hardwares).
- draw_graph(flow_from_pattern: bool = True, show_pauli_measurement: bool = True, show_local_clifford: bool = False, show_measurement_planes: bool = False, show_loop: bool = True, node_distance: tuple[int, int] = (1, 1), figsize: tuple | None = None, save: bool = False, filename: str | None = None) None[source]¶
Visualize the underlying graph of the pattern with flow or gflow structure.
- Parameters:
flow_from_pattern (bool) – If True, the command sequence of the pattern is used to derive flow or gflow structure. If False, only the underlying graph is used.
show_pauli_measurement (bool) – If True, the nodes with Pauli measurement angles are colored light blue.
show_local_clifford (bool) – If True, indexes of the local Clifford operator are displayed adjacent to the nodes.
show_measurement_planes (bool) – If True, measurement planes are displayed adjacent to the nodes.
show_loop (bool) – whether or not to show loops for graphs with gflow. defaulted to True.
node_distance (tuple) – Distance multiplication factor between nodes for x and y directions.
figsize (tuple) – Figure size of the plot.
save (bool) – If True, the plot is saved as a png file.
filename (str) – Filename of the saved plot.
- max_space() int[source]¶
Compute the maximum number of nodes that must be present in the graph (graph space) during the execution of the pattern.
For statevector simulation, this is equivalent to the maximum memory needed for classical simulation.
- Returns:
n_nodes – max number of nodes present in the graph during pattern execution.
- Return type:
int
- graphix.pattern.measure_pauli(pattern, leave_input, copy=False)[source]¶
Perform Pauli measurement of a pattern by fast graph state simulator.
Uses the decorated-graph method implemented in graphix.graphsim to perform the measurements in Pauli bases, and then sort remaining nodes back into pattern together with Clifford commands.
TODO: non-XY plane measurements in original pattern
- Parameters:
pattern (graphix.pattern.Pattern object)
leave_input (bool) – True: input nodes will not be removed False: all the nodes measured in Pauli bases will be removed
copy (bool) – True: changes will be applied to new copied object and will be returned False: changes will be applied to the supplied Pattern object
- Returns:
new_pattern – pattern with Pauli measurement removed. only returned if copy argument is True.
- Return type:
graphix.Pattern object
See also