Skip to content

tsim.core.graph.prepare_graph

← Module overview

functionprepare_graphsource

tsim.core.graph.prepare_graph

Signature
def prepare_graph(circuit: Circuit, *, sample_detectors: bool) -> SamplingGraph

Prepare a circuit for compilation.

This function performs the graph preparation phase:

  1. Parse the stim circuit into a ZX graph
  2. Build the sampling graph (compose with adjoint, add outputs)
  3. Reduce the graph via zx.full_reduce
  4. Transform error basis via Gaussian elimination (e → f)
  5. Clear the scalar (safe before stabilizer rank decomposition)

Parameters

NameTypeDescription
circuitCircuitThe quantum circuit to prepare.
sample_detectorsboolIf True, prepare for detector sampling. If False, prepare for measurement sampling.

Returns

SamplingGraphA SamplingGraph containing the reduced graph and error transformation.

source