QDriftTrotterization¶
- class QDriftTrotterization(*args, **kwargs)¶
Bases:
GenericPass[DAGCircuit,DAGCircuit]A transpilation pass to Trotterize
Evolutiongates via qDRIFT, skipping trivial draws.The qDRIFT protocol itself is the synthesis method
FermionicQDrift, which is on an equal footing with the other product formulas and is used through theF2FSynthesispass. This pass adds the one thing a synthesis method cannot do, since it sees a single gate at a time: it tracks which modes are known to be occupied or unoccupied through the circuit, and rejects a drawn term unless its support couples a known-occupied mode with a known-unoccupied one, drawing a replacement in its place.The method that draws the terms of an
Evolutiongate is resolved per gate. A gate whosesynthesisis aFermionicQDrift(or a subclass of it) is drawn with that method, which is how a gate carries its ownnum_terms,weightsandrng. Any othersynthesisis not a statement about qDRIFT and is ignored. Such a gate is drawn with theqdriftmethod given to this pass instead, and when there is none, it is left in place (with aUserWarning).That exists to stop the sampling from spending one of the
num_termsslots on an excitation that cannot move a particle, and which therefore tells you nothing about the sampled bitstrings. It buys that with the protocol’s convergence guarantee. To sample without rejecting anything, useFermionicQDriftwithF2FSynthesisinstead.Warning
Filtering does not make the circuit shorter.
num_termsis fixed, so a rejected draw is replaced rather than dropped, and the cheap term it would have contributed (a diagonal rotation, say) gives way to a coupling excitation that costs more to synthesize. Expect the filtered circuit to be deeper than the unfiltered one: the budget of sampled slots is what the filtering conserves, not the depth.Rejecting a drawn term and re-drawing renormalizes the sampling distribution over the accepted terms only, so the sampled product no longer averages to \(e^{-i t H}\) for the Hamiltonian you passed in: the effective coefficient of every retained term is inflated by the reciprocal of the acceptance probability, and the rejected terms drop out. Neither \(\lambda\) nor \(\delta\) is adjusted to compensate, so the distortion does not cancel.
Use it only when the sampled bitstrings are the quantity of interest, as in the SqDRIFT workflow of Generate SqDRIFT circuits. Do not use it when the sampled circuits are used to estimate an expectation value, a time-evolved observable, or anything else that relies on the qDRIFT error bound: those results are biased by an amount the pass does not track.
Filtering requires an
InitializeModesorPrepareSlaterDeterminantgate to precede theEvolutiongates being Trotterized, to seed the initial occupied and unoccupied mode sets. If none is found, or if the sets it seeds turn out to be entirely occupied or entirely unoccupied, filtering is skipped for that gate and aUserWarningis emitted instead, and the gate is sampled asFermionicQDriftwould.The sets are updated as the circuit is traversed: a drawn term is accepted only if its support intersects both sets, and once it is, every mode in its support becomes “uncertain” and is added to both sets, making it eligible to participate in either role for subsequent draws. Any
OrbitalRotationgate does the same to every mode it acts on, since the rotation can mix it with any other mode in its support. APrepareSlaterDeterminantgate is treated as itsInitializeModesandOrbitalRotationcomponents applied back-to-back: itsoccupationfirst seeds the sets, and then every mode it acts on is marked “uncertain”.Filtering diagnostics
When the filtering actually filters a gate, the returned
FermionicDAGCircuitrecords how many draws it discarded in itsmetadata, underfilter_trivial.discardedandfilter_trivial.emitted. Both hold one entry per filteredEvolutiongate, in circuit order. Their ratio estimates the acceptance probability, and hence the factor by which the filtering inflated the coefficients of the terms it kept: an acceptance probability close to one means the filtering barely moved the distribution, while a small one means the retained terms were weighted far above their true share of the Hamiltonian.Important
Neither field is present when no gate was filtered, which covers every case in which filtering was skipped with a
UserWarning. Read them defensively, for example withqcirc.metadata.get("filter_trivial.discarded"). A discarded count of zero is different from an absent field: it says the filtering ran on that gate and accepted every draw, so it left the sampling distribution untouched.Initializing this transpiler pass can be done with the argument below.
- Parameters:
qdrift – the synthesis method that draws the terms of every
Evolutiongate that does not carry aFermionicQDriftas its ownsynthesis. Itsnum_terms,weightsandrngapply as they do outside of this pass. WhenNone, only the gates that carry their own are drawn.args (Any)
kwargs (Any)
- Return type:
Any
Attributes
- MAX_SAMPLE_RETRIES = 1000000¶
The maximum number of consecutive rejected samples tolerated before
run()gives up and raisesRuntimeError. This guards against an infinite loop when the Hamiltonian’s remaining terms cannot bridge the tracked occupied/unoccupied mode sets. That happens when both sets remain small and disjoint (few modes have been marked occupied or unoccupied, and none has yet become “uncertain”) and no remaining term’s support touches both.
- qdrift¶
The fallback synthesis method that draws the terms, or
Noneif there is none.
Methods
- run(dag)¶
Runs this transpilation pass.
Each
Evolutionnode is replaced bynum_termssampledEvolutiongates, one per accepted draw. The emitted gates are markedEvolution.atomicand carry over theEvolution.synthesismethod of the node they replace. The method that draws them is the node’s ownEvolution.synthesisif that is aFermionicQDrift, andqdriftotherwise. A node for which there is neither is copied to the output unchanged, with aUserWarning, and every mode it acts on is then treated as “uncertain” for the filtering of the nodes after it. Nodes that are notEvolutiongates are copied to the output unchanged. Since the sampling is random, the output varies between runs unless therngwas seeded.- Parameters:
dag (DAGCircuit) – the input circuit with fermion-based instructions. Only
DAGOpNodewithFermionicGateinstances as theiropare supported, plusBarrierandFermionicMeasure, which are carried through untouched (a measurement keeps the classical bit it writes into).- Returns:
The output circuit which is still acting on a fermionic register. When filtering actually ran, its
metadataalso carries thefilter_trivial.discardedandfilter_trivial.emittedcounts described in the class docstring.- Raises:
RuntimeError – if
MAX_SAMPLE_RETRIESconsecutive draws are rejected without any of them coupling the tracked occupied and unoccupied mode sets.ValueError – if
weightswas supplied and its length does not match the number of groups (or terms) of an evolved operator.
- Return type:
Inherited Methods
- execute(passmanager_ir, state, callback=None)¶
Execute optimization task for input Qiskit IR.
- Parameters:
passmanager_ir (IR) – Qiskit IR to optimize.
state (PassManagerState) – State associated with workflow execution by the pass manager itself.
callback (Callable[[Task, IR_OUT, PropertySet, float, int], None] | None) – A callback function which is called per execution of optimization task.
- Returns:
Optimized Qiskit IR and state of the workflow.
- Return type:
tuple[IR_OUT, PassManagerState]
- update_status(state, run_state)¶
Update workflow status.
- Parameters:
state (PassManagerState) – Pass manager state to update.
run_state (RunState) – Completion status of current task.
- Returns:
Updated pass manager state.
- Return type: