qiskit
qiskit copied to clipboard
preset passmanagers should perform gate optimization before routing
What should we add?
Consider the following circuit:
qc = QuantumCircuit(N)
for kk in range(N - 1):
qc.cx(kk, N - 1)
qc.x(N - 1)
qc.z(N - 2)
for kk in range(N - 2, -1, -1):
qc.cx(kk, N - 1)
This circuit should collapse down to a pair of X and Z gates via commutation and collapsing pairs of CX gates. However, the preset passmanagers do not catch this. Instead, collapsing requires the routing passes to find the correct mapping that allows for later clean up to be successful. Other SDKs do this, and the performance is markedly better because routing is not required.
This is very easy to do (just add the pass to the DefaultInitPassManager as needed) and I agree it makes a ton of sense. I'm thinking we should do this at optimization levels 2 and 3, as that's where we currently do commutative cancellation today. What do you think?
I think that makes sense. I do agree that this is low-hanging fruit. I think where it is added depends on what is the proposed "default" preset passmanger. Namely, other SDKs defaults will do the same, so I my thinking is we should be able to do the same "by default", and let more advance users do custom PMs
Oh, sorry my comment was more left as a hint for where to put it in the code so it gets pulled in by transpile and generate_preset_pass_manager for everyone. It's the name of the plugin class we use for the init stage by default:
https://github.com/Qiskit/qiskit/blob/d47a227d982710e7933d744dfd95f6550ff07ed2/qiskit/transpiler/preset_passmanagers/builtin_plugins.py#L68 we just need to add either CommutativeCancellation or CommutativeInverseCancellation to the pass manager construction there to do this.