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
passesin 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
maxiterrounds. A pass that already ran on the current circuit is skipped until another pass changes it. The result has the same unitary ascircuit, global phase included, and the same measurements, resets and other non-unitary operations in the same order.passesis any sequence of functions fromCircuittoCircuit. The default,DEFAULT_SIMPLIFY_PASSES, isremove_identities(),cancel_inverses(),merge_rotations(),resynthesize_2q()andresynthesize_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
GateUand named gates such asGateHorGateSmay be replaced by it. Pass a subset to keep them, for examplepasses=(remove_identities, cancel_inverses, merge_rotations).resynthesize_linear()is not a default pass: add it for circuits with large CX networks.- Parameters:
- Returns:
The simplified circuit.
- Return type:
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]