Statevector Simulator

PatternSimulator samples measurement results from their exact Born probabilities by default. This is required when inputs use Y+ or Z+ initialization, because non-output measurements are not necessarily uniformly random.

For compatibility with the previous faster approximation, pass calc_prob=False. In that mode, non-output measurements are sampled 50/50; output measurements still use their exact probabilities. This approximation is only appropriate when the pattern guarantees uniformly random non-output measurements.

Module for simulating circuits and Measurement Patterns.

This module provides:

class graphqomb.simulator.SimulatorBackend[source]

Bases: Enum

Enum class for circuit simulator backend.

Available backends are: - StateVector - DensityMatrix

class graphqomb.simulator.CircuitSimulator[source]

Bases: object

Class for simulating circuits.

state

The quantum state of the simulator.

Type:

BaseFullStateSimulator

gate_instructions

The list of gate instructions to be applied.

Type:

list[Gate]

__init__(mbqc_circuit, backend)[source]
apply_gate(gate)[source]

Apply a gate to the circuit.

Parameters:

gate (Gate) – The gate to apply.

Raises:

TypeError – If the gate type is not supported.

simulate()[source]

Simulate the circuit.

class graphqomb.simulator.PatternSimulator[source]

Bases: object

Class for simulating Measurement Patterns.

state

The quantum state of the simulator.

Type:

BaseFullStateSimulator

node_indices

The list of node indices in the pattern.

Type:

list[int]

results

The measurement results for each node.

Type:

dict[int, bool]

output_results

Measurement results for output nodes, keyed by logical output index.

Type:

dict[int, bool]

calc_prob

Whether to sample every measurement from its exact Born probability. If False, non-output measurements use the legacy 50/50 assumption.

Type:

bool

__init__(pattern, backend, *, calc_prob=True)[source]
apply_cmd(cmd, *, rng)[source]
apply_cmd(cmd, *, rng)
apply_cmd(cmd, *, rng)
apply_cmd(cmd, *, rng)
apply_cmd(cmd, *, rng)

Apply a command to the state.

Parameters:
Raises:

TypeError – If the command type is not supported by the simulator.

simulate(rng=None)[source]

Simulate the pattern.

Parameters:

rng (numpy.random.Generator | None, optional) – Random number generator to use for measurement outcomes. If None, a new generator will be created using the default random source. Default is None.