TrotterSpecStage¶
- class TrotterSpecStage(trotterization_strategy, meta_circuit_factory)[source]¶
Bases:
SpecStage[SparsePauliOp]SpecStage that turns a Hamiltonian into a batch of MetaCircuits via a TrotterizationStrategy.
Accepts a
SparsePauliOp, runs the strategy to obtain one or more SPO samples, and invokesmeta_circuit_factory(processed_spo, ham_id)for each.- Parameters:
trotterization_strategy (
TrotterizationStrategy) – Strategy for term selection/sampling (e.g.ExactTrotterization,QDrift).meta_circuit_factory (
Callable[...,MetaCircuit]) – Factory callable(TrotterizationResult, ham_id) -> MetaCircuit.
Attributes Summary
Axis name introduced by this stage.
Methods Summary
cache_key_extras(env)Invalidate the forward-pass cache per evaluation for QDrift.
dry_expand(batch, env)Analytic path: build one prototype MetaCircuit, fan it out
n_samplestimes.expand(batch, env)Transform Hamiltonian into a keyed batch of MetaCircuits (one per strategy output).
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.
Attributes Documentation
- axis_name¶
Methods Documentation
- cache_key_extras(env)[source]¶
Invalidate the forward-pass cache per evaluation for QDrift.
QDrift re-samples a fresh batch each optimizer evaluation, seeded deterministically from
env.evaluation_counter; folding the counter into the cache key reuses one sample across the cost and gradient passes of a single evaluation, then resamples on the next. Deterministic strategies (e.g.ExactTrotterization) declare no extras and stay cached for the pipeline’s lifetime.
- dry_expand(batch, env)[source]¶
Analytic path: build one prototype MetaCircuit, fan it out
n_samplestimes.For stochastic strategies (e.g. QDrift) each sample would in principle produce a slightly different DAG. Dry runs only count circuits, so a single prototype from ham_id=0 is reused — saving (n_samples - 1) expensive factory invocations. For the dominant deterministic case (
ExactTrotterizationwithn_samples=1) this reduces to the same single factory call asexpand().- Return type:
StageOutput[dict[tuple[tuple[str,Hashable],...],MetaCircuit]]
- expand(batch, env)[source]¶
Transform Hamiltonian into a keyed batch of MetaCircuits (one per strategy output).
- Return type:
StageOutput[dict[tuple[tuple[str,Hashable],...],MetaCircuit]]