PauliTwirlStage¶
- class PauliTwirlStage(n_twirls=100, seed=None)[source]¶
Bases:
BundleStageFan out each DAG body into Pauli-twirled copies and average on reduce.
- Parameters:
Attributes Summary
Axis name introduced by this stage.
Whether this stage's output must be recomputed on every forward pass (rather than reused from cache), invalidating reuse from this point on.
Methods Summary
dry_expand(batch, env)Analytic path: emit
n_bodies × n_twirlsshape-correct placeholders.expand(batch, env)Transform keyed MetaCircuit batch and return expansion lineage plus token.
introspect(batch, env, token)Return stage-specific metadata for dry-run reporting.
reduce(results, env, token)Identity by default; override if this stage reduces results.
validate(before, after)Check this stage's position in the pipeline.
Attributes Documentation
- axis_name¶
- volatile¶
Methods Documentation
- dry_expand(batch, env)[source]¶
Analytic path: emit
n_bodies × n_twirlsshape-correct placeholders.Skips label sampling, topology grouping, deep-copying, and QASM rendering entirely — twirling is a purely multiplicative fan-out, so the circuit count is exact from
n_twirlsalone. Matches the output slot (qasm_bodiesvscircuit_bodies) of the real path so downstream dry stages and_compile_batch-aware counters see the right shape.- Return type:
StageOutput[dict[tuple[tuple[str,Hashable],...],MetaCircuit]]
- expand(batch, env)[source]¶
Transform keyed MetaCircuit batch and return expansion lineage plus token.
- Return type:
StageOutput[dict[tuple[tuple[str,Hashable],...],MetaCircuit]]
- introspect(batch, env, token)[source]¶
Return stage-specific metadata for dry-run reporting.
Override in subclasses to provide richer introspection data. Called by the dry-run tool after
expandwith the post-expand batch, the pipeline env, and the stage’s token.
- validate(before, after)[source]¶
Check this stage’s position in the pipeline.
Called by
CircuitPipelineat construction time after structural validation. Override to inspect neighboring stages and either:raise
ContractViolationif preconditions are not met, oremit
DiviPerformanceWarningfor legal-but-slow configurations (e.g. expensive internal options, known-bad neighboring stages). Suppressed at the pipeline level viaCircuitPipeline(..., suppress_performance_warnings=True).