-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Refactor CircuitDag and use it to improve Merge* optimizers. #4494
Comments
I would like to work on this please. Could you assign it to me? |
I think I know how to go about this one, but I am confused as to why the current design exists?
So can I just go about completely removing the old structure and writing the whole thing including tests from scratch. Just get rid of the old api. Remove functions like |
@AnimeshSinha1309 If two operations commute, then they can be reordered and we don't necessarily need to have an edge between them. This property is used in |
Discussed in Cirq Sync: Related #3816
|
Another issue with Merge* optimizers: The merge happens only if all operations in a moment are act on a subset of qubits of the original operation. This is unnecessary and leads to inefficiencies. For example: >>> q = cirq.LineQubit.range(3)
>>> ops = [cirq.CX(q[0], q[1]), [cirq.H(q[0])] * 20, cirq.CX(q[1], q[2])]
>>> c1, c2 = cirq.Circuit(ops[:-1]), cirq.Circuit(ops)
>>> def opt(c):
c = c.copy()
cirq.MergeInteractions().optimize_circuit(c)
cirq.DropEmptyMoments().optimize_circuit(c)
return c
>>> print(c1, opt(c1), c2, opt(c2), sep = "\n-----\n") # H gates in c2 don' get merged because of CX(1, 2) 0: ───@───H───H───H───H───H───H───H───H───H───H───H───H───H───H───H───H───H───H───H───H───
│
1: ───X───────────────────────────────────────────────────────────────────────────────────
-----
0: ───T───X^0.5─────S────────Y^-0.5───@───S^-1───Y^0.5───Y^-0.5───Z^0.75────
│
1: ───Z───X^-0.25───Y^-0.5────────────@───S^-1───Y^0.5───Z────────X^-0.75───
-----
0: ───@───H───H───H───H───H───H───H───H───H───H───H───H───H───H───H───H───H───H───H───H───
│
1: ───X───@───────────────────────────────────────────────────────────────────────────────
│
2: ───────X───────────────────────────────────────────────────────────────────────────────
-----
0: ───Z^0.75────X^0.5────S^-1───Y^-0.5───@───S^-1───Y^0.5───Y^0.5─────Z^-0.75───H─────────H────────H──────H────────H───H──────H───────H─────────H─────────H───H───H───H───H───H───H───H───H───H───H───
│
1: ───X^-0.25───Y^-0.5───────────────────@───S^-1───Y^0.5───X^-0.25─────────────Z^0.75────X^0.5────S^-1───Y^-0.5───@───S^-1───Y^0.5───Y^0.5─────Z^-0.75───────────────────────────────────────────────
│
2: ─────────────────────────────────────────────────────────────────────────────X^-0.25───Y^-0.5───────────────────@───S^-1───Y^0.5───X^-0.25───────────────────────────────────────────────────────── |
Is your feature request related to a use case or problem? Please describe.
MergeSingleQubitGates
andMergeInteractions
are currently implemented usingPointOptimizers
. The first step of both these optimizers is to find a maximal connected component containing a particular single qubit / two qubit operation. Once the connected component is found, all operations in the connected component are merged and the resulting unitary is then decomposed into the target gateset using analytical techniques.However,
PointOptimizer
is not the right abstraction for this task because it first finds the necessary operation and then merges the operations that lie to the right of it. This results in bugs like #3144 (forMergeSingleQubitGates
) and the example given below (forMergeInteractions
).Describe the solution you'd like
Instead of using
PointOptimizer
for finding connected component to merge, we should useCircuitDag
. An example diagram, borrowed from Qiskit's compiler's presentation (link) is given below:This would have multiple sub tasks:
CircuitDag
to make it more user friendly as an IR (eg: it's currently transitive complete, which makes it very hard for visualizing even basic circuit structures like the one given above. I'm also not sure if we need it to be transitive complete for other use cases).CircuitDag
inMergeSingleQubitGates
andMergeInteractions
.What is the urgency from your perspective for this issue? Is it blocking important work?
P2 - we should do it in the next couple of quarters
Part of the roadmap item: #3239
The text was updated successfully, but these errors were encountered: