Description
I use two test cases to illustrate an issue.
Case 1 - cx gates
OPENQASM 2.0;
include "qelib1.inc";
qreg q[2];
h q;
cx q[0], q[1];
cx q[0], q[1];
cx q[0], q[1];
cx q[0], q[1];
After staq
with optimization:
OPENQASM 2.0;
include "qelib1.inc";
qreg q[2];
h q[0];
h q[1];
The cx gates have been cancelled nicely.
Case 2 - ccx gates
OPENQASM 2.0;
include "qelib1.inc";
qreg q[3];
h q;
ccx q[0], q[1], q[2];
ccx q[0], q[1], q[2];
ccx q[0], q[1], q[2];
ccx q[0], q[1], q[2];
After staq
with optimization:
OPENQASM 2.0;
include "qelib1.inc";
qreg q[3];
h q[0];
h q[1];
z q[2];
z q[1];
cx q[2],q[1];
rz(((pi*3)/2)+((pi*3)/2)) q[1];
s q[0];
cx q[2],q[0];
rz(((pi*3)/2)+((pi*3)/2)) q[0];
cx q[1],q[0];
sdg q[0];
cx q[2],q[0];
z q[0];
cx q[2],q[1];
cx q[2],q[0];
cx q[1],q[0];
h q[2];
s q[0];
cx q[1],q[0];
sdg q[0];
cx q[1],q[0];
The ccx gates should also cancel each other out, shouldn't they?
I read an old article, which may not be directly related to what the staq
wants to achieve. Nevertheless, the authors introduced an interesting idea of removing self-annihilating sequences. I am wondering if staq
could borrow the idea and repurpose it to optimize similar sequences for staq
applications.
In the classical world, a decent modern IDE can use static analysis to identify a lot of redundant code, dead code, suspicious code, no-op blocks, obvious stupidity, etc., before the complier is run. Do you think if staq
can introduce a pass to target those usual suspects as well, especially the self-annihilating sequences? In the long run, that may even help the IDE vendors.