ParameterBindingStage¶
- class ParameterBindingStage[source]¶
Bases:
BundleStageBind
env.param_setsinto every circuit body.Two output shapes, selected at pipeline construction via
validate():Fast path — when no downstream stage reads
meta.circuit_bodies(i.e. all subsequent stages declareconsumes_dag_bodies=False). Each body DAG is serialised once to a parametric QASM string, wrapped in aQASMTemplate, and rendered per parameter set intometa.qasm_bodieswithparameterscleared. The pipeline’s compilation pass then reads the bound strings directly.Slow path — when any downstream stage consumes body DAGs (e.g.
PauliTwirlStageorQEMStage). For each body variant and parameter set,qiskit.circuit.QuantumCircuit.assign_parameters()emits a boundDAGCircuitwritten back tometa.circuit_bodies(parameterscleared). Slower, but preserves the DAG IR so downstream stages see concrete gate angles.
A third template path (
_run_template(), when the backend implementsSupportsCircuitTemplates) renders the parametric body intometa.qasm_bodieswithout binding, leavingparametersintact so the compilation pass defers substitution to the backend. Bound vs. template is therefore decided downstream by whetherparameterssurvives, not by a dedicated field.dry_expand()skips the prepare/emit helper entirely and emits shape-correct placeholders directly — the analytic path has no per- variant state to cache, so forcing it through the shared loop would only add dispatch noise.Attributes Summary
Axis name introduced by this stage.
Whether this stage invalidates forward-pass reuse from this point.
Methods Summary
dry_expand(batch, env)Analytic forward pass for dry runs.
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¶
- stateful¶
Methods Documentation
- dry_expand(batch, env)[source]¶
Analytic forward pass for dry runs.
Must emit a batch with the same shape as
expand()(same keys, samelen(circuit_bodies), samelen(measurement_qasms)) and anintrospect-compatible token, but without generating expensive per-item content (DAG deep-copies, QASM strings, classical simulations).The default implementation falls back to
expand(), so stages that cannot skip circuit generation keep working unchanged.Shared-reference contract. Overriding implementations commonly emit the same DAG object across multiple tagged entries in
meta.circuit_bodies(true of every built-in dry path today). Consumers may read those DAGs freely, but must not mutate them in place — a mutation on one entry would leak across sibling branches.CircuitPipelineenforces this by demoting such a stage to its realexpand()whenever a downstream stage declaresconsumes_dag_bodies=Trueand has not overriddendry_expand; aDiviPerformanceWarningis emitted naming both stages. The dry-run circuit count stays correct either way — only the analytic speedup is forfeited for the affected stage.- Return type:
- expand(batch, env)[source]¶
Transform keyed MetaCircuit batch and return expansion lineage plus token.
- Return type:
- 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).