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.Pattern object

MBQC pattern to be simulated.

backend: str, ‘statevector’ or ‘tensornetwork’

simulation backend (optional), default is ‘statevector’.

kwargs: keyword args for specified backend.

run()[source]

Perform the simulation.

Returns

the output quantum state, in the representation depending on the backend used.

Return type

state

Simulator backends

Tensor Network

class graphix.sim.tensornet.TensorNetworkBackend(pattern, graph_prep='opt', **kwargs)[source]

Tensor Network Simulator for MBQC

Executes the measurement pattern using TN expression of graph states.

__init__(pattern, graph_prep='opt', **kwargs)[source]
Parameters
  • pattern (graphix.Pattern) –

  • graph_prep (str) –

    ‘opt’(default) :

    Faster and optimal method to prepare a tensornetwork representing graph state. The expression of the given graph state can be obtained from its geometry. See https://journals.aps.org/pra/abstract/10.1103/PhysRevA.76.052315 for example. Note that the ‘N’ and ‘E’ commands in the measurement pattern are ignored.

    ’sequential’ :

    Sequentially add nodes and edges, strictly following the measuremen pattern. In this strategy, All N and E commands executed sequentially.

  • **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]

graphix.sim.tensornet.gen_str()[source]

Generate dummy string for einsum.

graphix.sim.tensornet.proj_basis(angle, vop, plane, choice)[source]

the projected statevector.

Parameters
  • angle (float) – measurement angle

  • vop (int) – CLIFFORD index

  • plane (str) – measurement plane

  • choice (int) – measurement result

Returns

projected state

Return type

numpy.ndarray

graphix.sim.tensornet.outer_product(vectors)[source]

outer product of the given vectors

Parameters

vectors (list of vector) – vectors

Returns

tensor object.

Return type

numpy.ndarray

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.Pattern object

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.

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

finalize()[source]

to be run at the end of pattern simulation.

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

qubit_dim()[source]

Returns the qubit number in the internal statevector :returns: n_qubit :rtype: int

sort_qubits()[source]

sort the qubit order in internal statevector

trace_out()[source]

trace out the qubits buffered in self.to_trace from self.state

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

flatten()[source]

returns flattened statevector

normalize()[source]

normalize the state

ptrace(qargs)[source]

partial trace

Parameters

qargs (list of ints) – qubit inices to trace over

swap(qubits)[source]

swap qubits

Parameters

qubits (tuple of ints) – (control, target) qubit indices

tensor(other)[source]

Tensor product state with other qubits. Results in self \(\otimes\) other.

Parameters

other (_type_) – graphix.sim.statevec.Statevec instance