quizx icon indicating copy to clipboard operation
quizx copied to clipboard

Implement basic circuit optimisations

Open akissinger opened this issue 7 months ago • 0 comments

PyZX does a pass of basic gate-level optimisations as a final stage in most circuit-to-circuit optimisations (see the basic_optimization function).

We should do something like this in QuiZX. The PyZX version has gotten increasingly elaborate over the years, so we might not need something this heavy weight. Just scanning forward and backwards and doing obvious commutations/cancellations should suffice for now. Ideally any fancier stuff should be done at the ZX and/or circuit extraction level.

Implementation

QuiZX uses the Circuit struct to store quantum circuits. This is essentially a Vec of Gate's.

For this task, add a new file called something like circuit_optimizer.rs and implement a function that traverses this list, possibly in multiple passes, and cancels/combines basic gates wherever possible. If it is useful to have many flags or keep some state around, then this function could be wrapped in a struct like it is in PyZX.

Optimisation should be done up-to-commutativity: if we have a sequence of gates U; V1; V2; ...; Vn; W where U commutes with all the Vi gates and U can cancel or combine with W, then we should try and find this optimisation and apply it.

There is some tradeoff between finding all such cancellations and producing a simple and efficient procedure. Here, I suggest we shoot for some middle ground.

akissinger avatar Jun 13 '25 10:06 akissinger