Pattern Optimization
graphix.pattern module
- class graphix.pattern.Pattern(input_nodes=[])[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
- Nnode
total number of nodes in the resource state
- Type
int
- add(cmd)[source]
add command to the end of the pattern. an MBQC command is specified by a list of [type, node, attr], where
type : ‘N’, ‘M’, ‘E’, ‘X’, ‘Z’, ‘S’ or ‘C’ nodes : int for ‘N’, ‘M’, ‘X’, ‘Z’, ‘S’, ‘C’ commands nodes : tuple (i, j) for ‘E’ command attr for N (node preparation):
none
- attr for E (entanglement):
none
- attr for M (measurement):
meas_plane : ‘XY’,’YZ’ or ‘XZ’ angle : float, in radian / pi s_domain : list t_domain : list
- attr for X:
signal_domain : list
- attr for Z:
signal_domain : list
- attr for S:
signal_domain : list
- attr for C:
clifford_index : int
- Parameters
cmd (list) – MBQC command.
- replace(cmds, input_nodes=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)[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)[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='statevector', **kwargs)[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
dict
- Return type
vops
- 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=False, use_rustworkx=False)[source]
Perform Pauli measurements in the pattern using efficient stabilizer simulator.
See also
- print_pattern(lim=40, filter=None)[source]
print the pattern sequence (Pattern.seq).
- Parameters
lim (int, optional) – maximum number of commands to show
filter (list of str, optional) – show only specified commands, e.g. [‘M’, ‘X’, ‘Z’]
- standardize(method='local')[source]
Executes 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) – ‘global’ corresponds to a conventional standardization executed on Pattern class. ‘local’ standardization is executed on LocalPattern class. In all cases, local pattern standardization is significantly faster than conventional one. defaults to ‘local’
- shift_signals(method='local')[source]
Performs 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 ‘global’ method:
Danos, E. Kashefi and P. Panangaden. J. ACM 54.2 8 (2007)
- Ref for the ‘local’ method:
Sunami and M. Fukushima, in preparation
- Parameters
method (str, optional) – ‘global’ shift_signals is executed on a conventional Pattern sequence. ‘local’ shift_signals is done on a LocalPattern class which is faster but results in equivalent pattern. defaults to ‘local’
- is_standard()[source]
determines whether the command sequence is standard
- Returns
is_standard – True if the pattern is standard
- Return type
bool
- get_graph()[source]
returns 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()[source]
Optimize the pattern to minimize the max_space property of the pattern i.e. 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=True, show_pauli_measurement=True, show_local_clifford=False, show_measurement_planes=False, show_loop=True, node_distance=(1, 1), figsize=None, save=False, filename=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()[source]
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
- class graphix.pattern.CommandNode(node_index, seq, Mprop, Zsignal, input, output, Xsignal=[], Xsignals=[])[source]
A node decorated with a distributed command sequence.
- index
node index
- Type
int
- seq
command sequence. In this class, a command sequence follows the rules noted below.
E: pair node’s index(>=0) M: -1 X: -2 Z: -3 C: -4
- Type
list
- Mprop
attributes for a measurement command. consists of [meas_plane, angle, s_domain, t_domain, vop]
- Type
list
- result
measurement result of the node
- Type
int
- Xsignal
signal domain
- Type
list
- Xsignals
signal domain. Xsignals may contains lists. For standardization, this variable is used.
- Type
list
- Zsignal
signal domain
- Type
list
- vop
value for clifford index
- Type
int
- input
whether the node is an input or not
- Type
bool
- output
whether the node is an output or not
- Type
bool
- __init__(node_index, seq, Mprop, Zsignal, input, output, Xsignal=[], Xsignals=[])[source]
- Parameters
node_index (int) – node index
seq (list) – distributed command sequence
Mprop (list) – attributes for measurement command
Xsignal (list) – signal domain for X byproduct correction
Xsignals (list of list) – signal domains for X byproduct correction Xsignal or Xsignals must be specified
Zsignal (list) – signal domain for Z byproduct correction
input (bool) – whether the node is an input or not
output (bool) – whether the node is an output or not
- class graphix.pattern.LocalPattern(nodes={}, input_nodes=[], output_nodes=[], morder=[])[source]
MBQC Local Pattern class
Instead of storing commands as a 1D list as in Pattern class, here we distribute them to each node. This data structure is efficient for command operations such as commutation and signal propagation. This results in faster standardization and signal shifting.
- nodes
set of nodes with distributed command sequences
- Type
set
- input_nodes
list of input node indices.
- Type
list
- output_nodes
list of output node indices.
- Type
list
- morder
list of node indices in a measurement order.
- Type
list
- signal_destination
- Type
dict
- stores the set of nodes where dependent feedforward operations are performed, from the result of measurement at each node.
- stored separately for each nodes, and for each kind of signal(Ms, Mt, X, Z).
- __init__(nodes={}, input_nodes=[], output_nodes=[], morder=[])[source]
- Parameters
nodes (dict) – dict of command decorated nodes. defaults to an empty dict.
output_nodes (list, optional) – list of output node indices. defaults to [].
morder (list, optional) – list of node indices in a measurement order. defaults to [].
- standardize()[source]
Standardize pattern. In this structure, it is enough to move all byproduct corrections to the back
- graphix.pattern.measure_pauli(pattern, leave_input, copy=False, use_rustworkx=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