MergeEvolutions¶
- class MergeEvolutions(atol=1e-12)¶
Bases:
GenericPass[DAGCircuit,DAGCircuit]A transpilation pass merging consecutive
Evolutiongates of the same operator.Two evolutions under the same operator \(H\) satisfy
\[e^{-i t_2 H} e^{-i t_1 H} = e^{-i (t_1 + t_2) H},\]because \(H\) commutes with itself. This pass finds neighboring
Evolutiongates of the same operator and replaces them by one gate whose evolution time is the sum of theirs. The rewrite is exact, so it changes neither the simulated state nor the Trotter error of the circuit; it only removes a gate, and with it the synthesized operations that gate would have produced.Such neighbors arise wherever two sequences of factors meet on the same factor. Examples are the seams between the repetitions of
BosonicCircuit.repeat(), or between consecutive samples ofBosonicQDrift.BosonicSuzukiTrotteralready fuses the seams within its own output (seeBosonicSuzukiTrotter.merge_adjacent); this pass is the general mechanism which also acts across gate boundaries.Two gates merge only when all of the following hold:
they act on the identical wires, in the identical order, with nothing else in between;
their operators are of the same type and equal up to
atolas sums of products of ladder operators, which is stricter thanBosonOperator.equiv(), see the note below;they are either both
Evolution.atomicor both not, and in the latter case they are decomposed by the same kind ofEvolution.synthesiswith identical settings.
The merged gate keeps the operator, and thus the
groups, of the first gate of the run.Note
Two operators that are
BosonOperator.equiv()are not necessarily the same operator once they are truncated. Normal ordering is an identity of the untruncated Fock space, and a truncation does not preserve it: \(b b^\dagger\) and \(b^\dagger b + 1\) map to different matrices, which differ on the highest level. Gates whose operators are onlyequivare therefore not merged, because the merged gate would no longer equal the two it replaces.Caution
This is an early development prototype. Beware of changes to its interface without warning during the pre-release development of this package.
See also
Initializing this transpiler pass can be done with the arguments listed below.
- Parameters:
atol (float) – the absolute tolerance up to which the operators of two gates are considered equal.
Attributes
- atol¶
The absolute tolerance up to which two operators are considered equal.
Methods
- run(dag)¶
Runs this transpilation pass.
Collects every maximal run of consecutive
Evolutiongates on the same wires, splits it into stretches of mergeable gates and replaces each stretch of length two or more with a singleEvolutioncarrying the summed time. Everything else is left untouched. The input DAG is modified in place.A
Barrierinterrupts a run, so the gates on either side of one are not merged. Place a barrier between two gates to keep them apart.- Parameters:
dag (DAGCircuit) – the input circuit with boson-based instructions. Only
DAGOpNodewithBosonicGateinstances as theiropare supported, plusBarrier, which is carried through untouched.- Returns:
The output circuit which is still acting on a bosonic register.
- 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: