Skip to content
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

Add a generic Optimizer that makes use of GateTabulation #4059

Open
wjhuggins opened this issue Apr 28, 2021 · 8 comments
Open

Add a generic Optimizer that makes use of GateTabulation #4059

wjhuggins opened this issue Apr 28, 2021 · 8 comments
Assignees
Labels
area/google/optimizers area/transformers kind/feature-request Describes new functionality triage/accepted A consensus emerged that this bug report, feature request, or other action should be worked on

Comments

@wjhuggins
Copy link

We should write an Optimizer that can use the GateTabulation code to recompile a circuit for an arbitrary two-qubit gate.

Is your feature request related to a use case or problem? Please describe.
Yes. This would make it easy to compile a circuit to a specific device using a two-qubit gate which we don't have a full set of analytical tools for.

In the future, we could also use this kind of functionality to do better refitting based on calibration data (at the expense of generating many GateTabulation objects).

Describe the solution you'd like
We should adapt the existing infrastructure we have to provide an optimizer which uses the GateTabulation code to compile a circuit with a user specific base_gate.

[optional] Describe alternatives/workarounds you've considered
I've hacked this in to the code myself, but it isn't pretty. Analytical compilation isn't always possible and it definitely isn't always straightforward to implement, even for gates we support well.

P1 or P2 depending maybe.

@wjhuggins wjhuggins added the kind/feature-request Describes new functionality label Apr 28, 2021
@balopat balopat added area/transformers triage/discuss Needs decision / discussion, bring these up during Cirq Cynque labels Apr 29, 2021
@balopat
Copy link
Contributor

balopat commented Apr 29, 2021

Thanks for opening @wjhuggins! I'm trying to gauge the size/complexity of this do you mind sharing your not-so-pretty code in a gist as a prototype and what specific concerns you have regarding analytical compilation? That would help contributors / ourselves get started.

If I understand correctly the task would be to write an optimizer that approximates any two-qubit gates to single-qubit gates using GateTabulation, which currently only produces single qubit unitaries but not actual gates. We would have to convert these single qubit unitaries to PhasedXZPow gates? Or something else?

@wjhuggins
Copy link
Author

I'd be happy to. I'll spend a bit of time on it next week.

The main thing is that the existing infrastructure around the GateTabulation code is only useful for compiling to a Sycamore gate + single-qubit gates. But the same building blocks could be used to write an optimizer that compiles to an arbitrary two-qubit gate + single-qubit gates.

@mpharrigan
Copy link
Collaborator

Discussed in cirq cync: possible connection to gatesets cc @tanujkhattar

A generic interface for compiling to various gates should exist. It should go to analytic compilation routines if we have them, but can fall back to tabulation as well. Marking "accepted"

@mpharrigan mpharrigan added triage/accepted A consensus emerged that this bug report, feature request, or other action should be worked on and removed triage/discuss Needs decision / discussion, bring these up during Cirq Cynque labels May 19, 2021
@wjhuggins
Copy link
Author

Here's a gist that has the diff of the changes I made:

https://gist.github.com/wjhuggins/05e54da80a9e02b96c700569273f6c92

@wjhuggins
Copy link
Author

I basically did two things.

  1. Modified MergeInteractions to optionally return a circuit with two-qubit MatrixGates.
  2. Modified the code in convert_to_sycamore_gates to accept and properly use a GateTabulation built with two-qubit gates other than Sycamore gates.

A real version of the code should definitely be organized differently. I wasn't sure how to do this so I just left it alone in its hack-y state. I'm open to working on this later after I wrap up the experiment that I've been using it for and move on to producing some tutorials about it for public consumption.

@95-martin-orion
Copy link
Collaborator

Marked pre-1.0 as a component of Transformers.

@dstrain115
Copy link
Collaborator

@tanujkhattar Do we really need this before 1.0?

@tanujkhattar
Copy link
Collaborator

Nope, this should be marked after 1.0. Changed the label.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/google/optimizers area/transformers kind/feature-request Describes new functionality triage/accepted A consensus emerged that this bug report, feature request, or other action should be worked on
Projects
Status: No status
Development

No branches or pull requests

9 participants