Pattern Optimization
graphix.pattern module
- class graphix.pattern.Pattern(width=0, input_nodes=None, output_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)
- width
number of output qubits
- Type
int
- seq
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- Type
list
- Nnode
total number of nodes in the resource state
- Type
int
- __init__(width=0, input_nodes=None, output_nodes=[])[source]
- Parameters
width – number of input/output qubits
- simulate_pattern(backend='statevector', **kwargs)[source]
Simulate the execution of the pattern by using
graphix.simulator.PatternSimulator.Available backend: [‘statevector’, ‘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
- 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)[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(figsize=None, pauli_indicator=True, local_clifford_indicator=False, save=False, filename=None)[source]
Visualize the underlying graph of the pattern with flow or gflow structure.
- Parameters
figsize (tuple) – Figure size of the plot.
pauli_indicator (bool) – If True, the nodes are colored according to the measurement angles.
local_clifford_indicator (bool) – If True, indexes of the local Clifford operator are displayed adjacent to the nodes.
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
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).
- Type
dict
- __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)[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