QDriftTrotterization¶
- class QDriftTrotterization(num_terms, *, filter_diagonal_terms=False, rng=None)¶
Bases:
GenericPass[DAGCircuit,DAGCircuit]A transpilation pass to Trotterize
Evolutiongates via the qDRIFT protocol.This pass replaces the exact evolution \(e^{-i t H}\) of each
Evolutiongate by a randomized product formula: it drawsnum_termssamples from the Hamiltonian’s terms (orgroups, if assigned), with each term sampled with a probability proportional to the magnitude of its coefficient, and emits oneEvolutiongate per sample. Every sampled gate evolves its (unit-magnitude, sign-preserving) term for the same time\[\delta = \frac{\lambda t}{\texttt{num\_terms}}, \qquad \lambda = \sum_j |c_j|,\]where the \(c_j\) are the coefficients of the sampled terms/groups. The ordered product of the sampled evolutions does not reproduce \(e^{-i t H}\) exactly; rather, its expectation over the sampling approximates the exact evolution, with an error that decreases as
num_termsgrows. Because the output depends on the random draws, it differs from run to run unless a fixedrngis supplied.See also
The qDRIFT protocol was introduced in arXiv:1811.08017.
Initializing this transpiler pass can be done with the arguments listed below.
- Parameters:
num_terms (int) – the number of terms to sample for the qDRIFT Trotterization. This equals the number of
Evolutiongates emitted per input gate; a larger value reduces the Trotterization error at the cost of a deeper circuit.filter_diagonal_terms (bool) – when set to
True, terms that are diagonal in the occupation-number basis (i.e. products of number operators) are removed from the Hamiltonian before the qDRIFT sampling. The time evolution of such terms does not affect the sampled bitstrings, so including them would only increase the sampling overhead. This automates the manual filtering otherwise required when preparing a Hamiltonian for SqDRIFT. The Hamiltonian is assumed to be normal-ordered. See alsofilter_diagonal_terms(). Because diagonal-term filtering is defined in terms of fermionic number operators, it is only supported forEvolutiongates whose operator is aFermionOperator;run()raisesTypeErrorotherwise.rng (np.random.Generator | int | None) – the random number generator (rng) to be used. When this is an
int, the internal rng will be initialized withnp.random.default_rng(seed=rng).
Attributes
- num_terms¶
The number of terms to include in the qDRIFT Trotterization.
- filter_diagonal_terms¶
Whether to filter out diagonal terms before the qDRIFT sampling.
Methods
- run(dag)¶
Runs this transpilation pass.
Each
Evolutionnode is replaced bynum_termssampled single-termEvolutiongates (see the class docstring). 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.- Returns:
The output circuit which is still acting on a fermionic register.
- Raises:
TypeError – if
filter_diagonal_termsisTruebut anEvolutiongate carries an operator that is not aFermionOperator(diagonal-term filtering is only defined for fermionic operators).- 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: