-
Notifications
You must be signed in to change notification settings - Fork 36
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
[RFC] Generalized unroller and equivalence library RFC. #6
[RFC] Generalized unroller and equivalence library RFC. #6
Conversation
How do you make these pretty ascii diagrams? Manually? |
|
Storing one circuit entry per gate width in the library is another option, growing the library size proportional to the number of variadic gates and their maximum widths. | ||
|
||
The `Decompose` transpile pass and corresponding `QuantumCircuit.decompose` method depend on a single unique path through `Instruction.definition`. | ||
These methods could be deprecated and removed, maintained via a decomposition search targeting `U3` and `CX`, or maintained via additional library entry labeling to support identification of one entry as the legacy `definition`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use case for decompose()
is when one builds a circuit using multiple composite gates (just because it's easier to reuse a composite gate, not because one is interested in different decompositions of that composite gate). If we don't have decompose
then you have to specify a basis to unroll to. How would I select the basis to yield the current decompose
behavior? If we can solve this then I'm fine deprecating decompose (i.e. a canonical definition for gates), and going with this more general framework.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding an optional target basis kwarg to decompose
defaulting to ['u3', 'cx']
would preserve the current behavior. Maybe better for the use case you're describing though would be to replace the current behavior with something like 'decompose only gates from outside the standard library'.
Co-Authored-By: Ali Javadi-Abhari <[email protected]>
Context: I'm Shai Machnes of OpenSuperQ, tasked with adapting the QISKIT stack to our hardware, where we have several two-qubit gates, and none of which are CX (we have CZ, sqrt(iSWAP), SWAP, etc). I'm confused regarding the timing of unrolling custom gates as depicted in the "envisioned terra diagram": In the proposed flow, the conversion to the "standard" set of gates takes place before the high-level optimization (i.e. in the top row). I believe this is too soon: When one typically codes an algorithm, one usually makes use of a fairly wide set of gates (not having a specific hardware in mind), and one usually assumes full connectivity (any two-qubit gate can act on any two qubits). So if, for example, one codes the algorithm using an XX gate, the current flow would unroll that into CX and U123 gates (which are the gates in the standard gate set), and then perform high-level optimization. But if the hardware actually supports XX at the native level, it is unlikely that subsequent transformations (specifically the secondary mapping, device unroller and device optimizations appearing on the bottom row of the diagram), will undo the unrolling performed in the first phase, returning from CX to XX in an efficient way. As a result, the final code will be sub-optimal. If one wishes to truly be architecture-agnostic, there should be no "standard gate set| - all complete (and over-complete) gate sets should have equal standing. The Backend object can specify which gates are supported by the hardware (and which gates can be executed on which qubits), and transpiler adapts accordingly. The proposed design definitely aims in the right direction, but IMHO does not go far enough, keeping one gate set (the "standard" one), in a privileged position. To the extent possible, high-level optimizations should be performed using a much wider gate-set than the standard one, and preferably without any unrolling at all. It is true that this may be tricky, but as we are free to require matrix forms from all gates, and can further require "optimization hints" to be added to all gates, I believe this should be possible. It'll also serve to define high-level optimizations in terms of gate attributes, instead of specific gates, which may lead to a better optimizer. |
Hi @shaimach , thanks for the feedback. I agree that the goal is to avoid having any preferred basis for the transpiler. There are some terms that are not fully specified by the diagram, that should help clarify its intent.
The standard/built-in gate set, at present, is not just [U{1,2,3}, CX], but all gates defined in https://github.com/Qiskit/qiskit-terra/blob/592c8987605c988c32bcc922f70071d82c134051/qiskit/extensions/standard/__init__.py (including e.g. the Fredkin gate). Something that is assumed throughout the doc (though is never explicitly stated) is that in parallel with this work will be an extension of qiskit's standard/built-in gate set to include a broader collection of logical and device gates (including e.g. iswap, ...). So CZ, SWAP, sqrt(iSWAP) would all be standard/built-in gates, not custom gates. The |
Hi @kdk, Thank you for the reply. It would extremely helpful if the RFC is updated to reflect the clarifications contained in your reply. In addition, it would be great to address the following:
I think once this RFC is implemented, QISKIT will become truly universal, which is absolutely great. |
Hi @shaimach , some answers to your questions inline. (These will be incorporated into the RFC.)
Correct that the standard equivalence library will contain entries like CX->{CZ, H}, CZ -> {CX, H},SWAP -> {CX}, SWAP -> {CZ, H}. The unroller will select the set of transformations to apply to map from the initial basis to the desired basis.
Correct, right now e.g.
If swaps are natively implemented (and reported) by the backend, they will not need to be unrolled (though a noise-aware unroller could still choose to do so, if beneficial).
Good question. The assumption has been that the standard gate set would grow to include all families of gates natively implemented by backends (and so have access to matrix definitions, equivalence relations, ...). If this is not the case, or there are cases where this is not possible, this information would need to be supplied by the backend. I do not believe a mechanism currently exists to provide this information, but we can look into this further.
The availability of the standard library as distinct from the session library will be useful so that users can easily track where a particular definition originated. The standard tooling will default to referencing the SessionLibrary, so is should be difficult to inadvertently use the StandardLibrary.
I agree. There is follow up work to generalize other transpiler passes (e.g. self-inverse cancellation, commutation analysis, ...) that will come after the implementation of this RFC. |
* Filled out the Summary, Motivation, and User Benefit sections * Filled out Alternative Approaches section * Add Tasks section * Add to Future Extensions section * Add more minor edits * Add Sections (#4) * add to Future Extensions (re Task in BasePrimitive) * Array broadcasting figure, example (#5) * Add section references (#6) * Add "BindingsArray generalizations" subsection * Add subsection titles * Add more BindingsArray examples * Wording change * Move the example up (no significant changes) * Add detail to migration plan (#7) * Light editing of first few sections. * Move all of the class ideas into Detailed Design * Edits in the detailed design subsections * Edits to migration section * Flesh out examples more * update date * update authors * switch observable array format * Small fixes here and there---nothing major. * Update authors * Address Chris` "Task" comments * Further response to Chris' "Task" comments * alphebetize and edit authors * rename ResultBundle -> TaskResult * Address Jim's comment * Rename ObservablesTask -> EstimatorTask * Update 0015-estimator-interface.md Co-authored-by: Takashi Imamichi <[email protected]> * Update 0015-estimator-interface.md Co-authored-by: Luciano Bello <[email protected]> * Update 0015-estimator-interface.md Co-authored-by: Takashi Imamichi <[email protected]> * Update 0015-estimator-interface.md Co-authored-by: Luciano Bello <[email protected]> * Update 0015-estimator-interface.md Co-authored-by: Blake Johnson <[email protected]> * fix typos in broadcasting examples * Address Blake's comment about exponential memory overhead for BaseOperator * Added Migration Examples section This is following a request to see some simpler examples of what the new interface would look like. * Update 0015-estimator-interface.md Co-authored-by: Elena Peña Tapia <[email protected]> * Update 0015-estimator-interface.md Co-authored-by: Elena Peña Tapia <[email protected]> * Fix shapes * Update 0015-estimator-interface.md Co-authored-by: Luciano Bello <[email protected]> * Removed 'Inner' from figure * Update 0015-estimator-interface.md Co-authored-by: Jim Garrison <[email protected]> * Update 0015-estimator-interface.md Co-authored-by: John Lapeyre <[email protected]> * Update 0015-estimator-interface.md Co-authored-by: Toshinari Itoko <[email protected]> * Update 0015-estimator-interface.md Co-authored-by: Toshinari Itoko <[email protected]> * Update 0015-estimator-interface.md Co-authored-by: Toshinari Itoko <[email protected]> * change migration path to versioning * clarify output type --------- Co-authored-by: Samantha Barron <[email protected]> Co-authored-by: Takashi Imamichi <[email protected]> Co-authored-by: Luciano Bello <[email protected]> Co-authored-by: Blake Johnson <[email protected]> Co-authored-by: Elena Peña Tapia <[email protected]> Co-authored-by: Jim Garrison <[email protected]> Co-authored-by: John Lapeyre <[email protected]> Co-authored-by: Toshinari Itoko <[email protected]>
No description provided.