-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cyclic circuit produced during Badger optimisation #239
Comments
The problem comes from an erroneous invalidation set definition for the rewrite composition. It's simpler to see it in this simpler (failing) circuits: OPENQASM 2.0;
include "qelib1.inc";
qreg q[4];
cx q[0],q[1]; # a
cx q[2],q[3]; # b
h q[1];
h q[3];
cx q[2],q[1]; # c
cx q[0],q[3]; # d
h q[0];
h q[1];
h q[2];
h q[3]; (hadamards added for padding, so the immediate neighbours do not overlap). In that circuit, two possible rewrites are:
On their own these are valid CNOT swaps. But if both are applied simultaneously, they create a loop in the circuit. (Notice the loop in nodes |
Just a restatement that made it clearer for me, at the risk of being obvious to everyone already. Swapping the two CX on qubit 0 gives you
And now the two CX not on qubit 0 ( |
This could be resolved by introducing the concept of "convex set of (convex) patterns". Checking that a set of patterns is convex is quite similar to how we are checking convexity at the moment, and we could (presumably) reuse the precomputed convex checker data structure that we are already using. Convex set of patterns: For every pair of patterns This checking isn't free, unfortunately:
On top of this checking not being free, there is the argument that we should only check this once it's been filtered and is actually about to be applied, instead of computing this for sets that might well be discarded later on. EDIT: this might require to precompute slightly different stuff than what we are doing now, but shouldn't be too far off. |
I'm not convinced any of what I'm saying is useful for a quick fix... Maybe we should turn this into a github discussion. |
Nice! Yes, I'm worried about the exploding complexity. Edit: #242 |
This is a short-term quick-but-incomplete fix for #239. We now check right after the composition whether we have invalidated the circuit by making a loop. We leverage that circuit hashing already does a toposort traversal, adding an error when a loop is found and catching it. Still, it is theoretically possible for an invalid chain of rewrites to end up producing a valid (but not equivalent) circuit. There is a discussion open for discussing more general solutions to this problem #242.
This is a short-term quick-but-incomplete fix for #239. We now check right after the composition whether we have invalidated the circuit by making a loop. We leverage that circuit hashing already does a toposort traversal, adding an error when a loop is found and catching it. Still, it is theoretically possible for an invalid chain of rewrites to end up producing a valid (but not equivalent) circuit. There is a discussion open for discussing more general solutions to this problem #242.
#200 is now fixed, but more bugs remain...
Edit: See Luca's clearer explanation below: #239 (comment)
Translating this qasm file into a hugr and applying the badger optimisation generates a cyclic graph. (Which causes the hashing code to panic).
The failing example is here:
https://github.com/CQCL/tket2/blob/9f752895c649d6e22f6f190efe77d1187046b7c6/tket2/examples/non_dag.rs
Checkout
debug/non-dag-example
andcargo run --features portmatching --example non_dag
.The text was updated successfully, but these errors were encountered: