mimiqcircuits.simplify

simplify(circuit, passes=(<function remove_identities>, <function cancel_inverses>, <function merge_rotations>, <function resynthesize_2q>, <function resynthesize_1q>), maxiter=10)[source]

Simplify a circuit by running passes in order, repeatedly.

Rounds stop when one no longer lowers the number of two-qubit gates or, failing that, the total number of instructions, or after maxiter rounds. A pass that already ran on the current circuit is skipped until another pass changes it. The result has the same unitary as circuit, global phase included, and the same measurements, resets and other non-unitary operations in the same order.

passes is any sequence of functions from Circuit to Circuit. The default, DEFAULT_SIMPLIFY_PASSES, is remove_identities(), cancel_inverses(), merge_rotations(), resynthesize_2q() and resynthesize_1q(). When every pass is one of this module’s, the whole loop runs natively.

Gates are rewritten numerically, so single-qubit runs come out as GateU and named gates such as GateH or GateS may be replaced by it. Pass a subset to keep them, for example passes=(remove_identities, cancel_inverses, merge_rotations). resynthesize_linear() is not a default pass: add it for circuits with large CX networks.

Parameters:
  • circuit (Circuit) – The circuit to simplify. It is not changed.

  • passes – The passes to run in each round, in order.

  • maxiter (int) – The largest number of rounds. Defaults to 10.

Returns:

The simplified circuit.

Return type:

Circuit

Examples

>>> import mimiqcircuits as mc
>>> c = mc.Circuit()
>>> _ = c.push(mc.GateCX(), 0, 1)
>>> _ = c.push(mc.GateRZ(0.2), 0)  # RZ commutes with the CX control...
>>> _ = c.push(mc.GateCX(), 0, 1)  # ...so the two CX gates cancel
>>> _ = c.push(mc.GateRZ(0.3), 0)  # and the rotations merge
>>> mc.simplify(c)
1-qubit circuit with 1 instruction:
└── RZ(0.5) @ q[0]