-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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 "layout" to the SparsePauliOp
(and related operators)
#11891
Comments
I think it is important for any solution to this problem to be elegantly composable. One should be able to create an operator in some succinct way with a Pauli Z on the 13th qubit (as you have done), stored sparsely. But one should also be able to compose that with a layout (e.g. a |
Sorry this didn't have much of a response. To link to other threads of work that we have going on, we're going to be implementing #12282 as part of our six-month performance push, which heavily touches on the same kinds of concerns as this, as I understand it. Let me preface this with: having sparse-per-qubit operators, as mooted by this issue, is absolutely something I agree is a good idea and super useful. Beyond that, though, I'm not certain that putting it onto
Point one I think is relatively self-explanatory - there's ways to mitigate it, but it'll always be tricky given then extant body of code that already relies on To explain my worries around point two more: this makes it such that now most operations on From this, then, the way I'm looking at the problem of "we need an operator that's efficient to manipulate where the terms are sparse over qubits" is more in favour of a new operator that builds in the sparsity structure to individual summands, and that that's something that would be cleaner and more performant to build into a solution to #12282 than to put on the top of If we wanted to move ahead with the general principles laid out in this issue, I think something to consider is whether it would be better to make a wrapper around |
Fwiw, at the ~100-qubit scale, I think the memory savings of a fully qubit-sparse operator vs a bitpacked full symplectic representation of the Pauli terms (i.e. just |
With the merging of Given the above discussion, I'll close this now with the ideas being that Feel free to open more if there's more to discuss here (and to point out stuff that's missing in |
What should we add?
The Pitch (or TL;DR)
For certain applications and operations I keep myself wishing for a builtin "layout" inside the
SparsePauliOp
. Note, that I am using "layout" due to the lack for a better word (sinceqargs
is already taken).Example
I think my particular application is best described with an example:
Consider I have a 127-qubit
QuantumCircuit
and would like to define a single-qubitZ
observable on qubit index 13. While there are many means to construct aSparsePauliOp
to represent this, in the end, the resulting object will always contain 126 identities.Not only is it pretty hard to tell on which index the
Z
lies, but any subsequent mathematical operations with this object will also be "expensive".For example. consider I want to compose this operator with an
XX
on qubits 12 and 13. This would "perform unneeded math" on all the identities surrounding the very local observables.Granted, for many arithmetic operations, one can set the
qargs
to perform local arithmetics. However, keeping track of theqargs
alongside the operators can become cumbersome and cluttering.Simple proposal
Thus, I propose some sort of "layout" or "qargs" (but this is already used) attribute that is internal to the
SparsePauliOp
(and likelyPauliList
and maybeBasePauli
by extension).Basically, here is a proposed idea:
This defines a
SparsePauliOp
with a builtin layout. This object has an internalPauliList
of length 1 but understands that it acts on a qubit index 13 out of 127 (hence the "layout" name suggestion).Later, one can also define the
XX
similarly and do math as follows:which will result in:
The key takeaways are, that even though we performed arithmetic operations, the operator remained small and, thus, avoids unnecessary computations.
I would also expect this to work on an
XX
with a layout[7, 13]
which should still output a 2-qubit overall sized object:Naive PoC
SparsePauliOp.apply_layout
already makes an implementation of this fairly straight forward. Here is a naive insertion that I added toSparsePauliOp.compose
to make the example above actually functional:This is, of course, by no means a production quality solution, but it shows the basic idea and it shows, that with the addition of
apply_layout
we have already taken a step into this direction.Open Question
OpShape
?layout
andglobal_num_qubits
better be placed onPauliList
and leaveSparsePauliOp
mostly untouched? I think this should be possible to a large degree. The same could probably be said for theapply_layout
method (see also Addapply_layout
to other operators #11824)layout
andglobal_num_qubits
into a single object of some sort?Use cases
SparsePauliOp
" (caveat being that all terms inside aSparsePauliOp
are constrained to the same sparse qubit indices; so this is not quite fully sparse yet)I am happy to work on a PR to implement this. @caleb-johnson had also expressed interest in helping out with this.
The text was updated successfully, but these errors were encountered: