Pattern Simulation
graphix.simulator module
- class graphix.simulator.PatternSimulator(pattern, backend='statevector', **kwargs)[source]
MBQC simulator
Executes the measurement pattern.
- __init__(pattern, backend='statevector', **kwargs)[source]
- pattern:
graphix.pattern.Patternobject MBQC pattern to be simulated.
- backend: str, ‘statevector’ or ‘tensornetwork’
simulation backend (optional), default is ‘statevector’.
kwargs: keyword args for specified backend.
- pattern:
Simulator backends
Tensor Network
- class graphix.sim.tensornet.TensorNetworkBackend(pattern, graph_prep='auto', **kwargs)[source]
Tensor Network Simulator for MBQC
Executes the measurement pattern using TN expression of graph states.
- __init__(pattern, graph_prep='auto', **kwargs)[source]
- Parameters
pattern (graphix.Pattern) –
graph_prep (str) –
- ‘parallel’ :
Faster method for preparing a graph state. The expression of a graph state can be obtained from the graph geometry. See https://journals.aps.org/pra/abstract/10.1103/PhysRevA.76.052315 for detail calculation. Note that ‘N’ and ‘E’ commands in the measurement pattern are ignored.
- ’sequential’ :
Sequentially execute N and E commands, strictly following the measurement pattern. In this strategy, All N and E commands executed sequentially.
- ’auto’(default) :
Automatically select a preparation strategy based on the max degree of a graph
**kwargs (Additional keyword args to be passed to quimb.tensor.TensorNetwork.) –
- add_nodes(nodes)[source]
Add nodes to the network
- Parameters
nodes (iterator of int) – index set of the new nodes.
- apply_clifford(cmd)[source]
Apply single-qubit Clifford gate
- Parameters
cmd (list) – clifford command. See https://arxiv.org/pdf/2212.11975.pdf for the detail.
- correct_byproduct(cmd)[source]
Perform byproduct correction.
- Parameters
cmd (list) – Byproduct command i.e. [‘X’ or ‘Z’, node, signal_domain]
- entangle_nodes(edge)[source]
Make entanglement between nodes specified by edge.
- Parameters
edge (tuple of int) – edge specifies two target nodes of the CZ gate.
- measure(cmd)[source]
Perform measurement of the node. In the context of tensornetwork, performing measurement equals to applying measurement operator to the tensor. Here, directly contracted with the projected state.
- Parameters
cmd (list) – measurement command i.e. [‘M’, node, plane angle, s_domain, t_domain]
Statevector
- class graphix.sim.statevec.StatevectorBackend(pattern, max_qubit_num=20)[source]
MBQC simulator with statevector method.
- __init__(pattern, max_qubit_num=20)[source]
- pattern:
graphix.pattern.Patternobject MBQC pattern to be simulated.
- backend: str, ‘statevector’
optional argument for simulation.
- max_qubit_numint
optional argument specifying the maximum number of qubits to be stored in the statevector at a time.
- pattern:
- add_nodes(nodes)[source]
add new qubit to internal statevector and assign the corresponding node number to list self.node_index.
- Parameters
nodes (list of node indices) –
- apply_clifford(cmd)[source]
Apply single-qubit Clifford gate, specified by vop index specified in graphix.clifford.CLIFFORD
- correct_byproduct(cmd)[source]
Byproduct correction correct for the X or Z byproduct operators, by applying the X or Z gate.
- entangle_nodes(edge)[source]
Apply CZ gate to two connected nodes
- Parameters
edge (tuple (i, j)) – a pair of node indices
- measure(cmd)[source]
Perform measurement of a node in the internal statevector and trace out the qubit :param cmd: measurement command : [‘M’, node, plane angle, s_domain, t_domain] :type cmd: list
- graphix.sim.statevec.meas_op(angle, vop=0, plane='XY', choice=0)[source]
Returns the projection operator for given measurement angle and local Clifford op (VOP).
See also
graphix.clifford- Parameters
angle (float) – original measurement angle in radian
vop (int) – index of local Clifford (vop), see graphq.clifford.CLIFFORD
plane ('XY', 'YZ' or 'ZX') – measurement plane on which angle shall be defined
choice (0 or 1) – choice of measurement outcome. measured eigenvalue would be (-1)**choice.
- Returns
op – projection operator
- Return type
numpy array
- class graphix.sim.statevec.Statevec(plus_states=True, nqubit=1)[source]
Simple statevector simulator
- CNOT(qubits)[source]
apply CNOT
- Parameters
qubits (tuple of ints) – (control, target) qubit indices
- __init__(plus_states=True, nqubit=1)[source]
Initialize statevector
- Parameters
plus_states (bool, optional) – whether or not to start all qubits in + state or 0 state. Defaults to +
nqubit (int, optional) – number of qubits. Defaults to 1.
- entangle(edge)[source]
connect graph nodes
- Parameters
edge (tuple of ints) – (control, target) qubit indices
- evolve(op, qargs)[source]
Multi-qubit operation
- Parameters
op (np.array) – 2^n*2^n matrix
qargs (list of ints) – target qubits’ indexes
- evolve_single(op, i)[source]
Single-qubit operation
- Parameters
op (np.array) – 2*2 matrix
i (int) – qubit index
- expectation_single(op, loc)[source]
Expectation value of single-qubit operator.
- Parameters
op (np.array) – 2*2 Hermite operator
loc (int) – target qubit
- Returns
expectation value.
- Return type
complex
- expectation_value(op, qargs)[source]
Expectation value of multi-qubit operator.
- Parameters
op (np.array) – 2^n*2^n operator
qargs (list of ints) – target qubit
- Returns
expectation value
- Return type
complex