MergeEvolutions

class MergeEvolutions(atol=1e-12)

Bases: GenericPass[DAGCircuit, DAGCircuit]

A transpilation pass merging consecutive Evolution gates 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 Evolution gates of equivalent operators 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 FermionicCircuit.repeat(), between consecutive UCC or UCJ layers, or between consecutive samples of QDriftTrotterization. FermionicSuzukiTrotter already fuses the seams within its own output (see FermionicSuzukiTrotter.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 equivalent up to atol;

  • they are either both Evolution.atomic or both not, and in the latter case they are decomposed by the same kind of Evolution.synthesis with identical settings.

The merged gate keeps the operator, and thus the groups, of the first gate of the run.

Caution

This is an early development prototype. Beware of changes to its interface without warning during the pre-release development of this package.

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 equivalent.

Attributes

atol

The absolute tolerance up to which two operators are considered equivalent.

Methods

run(dag)

Runs this transpilation pass.

Collects every maximal run of consecutive Evolution gates on the same wires, splits it into stretches of mergeable gates and replaces each stretch of length two or more with a single Evolution carrying the summed time. Everything else is left untouched. The input DAG is modified in place.

A Barrier interrupts 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 fermion-based instructions. Only DAGOpNode with FermionicGate instances as their op are supported, plus Barrier and FermionicMeasure, 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.

Return type:

DAGCircuit

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]

name()

Name of the pass.

Return type:

str

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:

PassManagerState