-
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
Subtypes of Basis
, their .shape
field, and infinite Hilbert spaces
#33
Comments
Hi @akirakyle, thanks for all of this work, it's greatly appreciated and will be helpful for many users! I have a few questions and comments:
So here, as you alluded to in this issue, I took advantage of the
This is what is currently implemented in my draft PR. However, perhaps a workaround to your proposed changes is that Gabs uses the abstract type
I could then define my own subtype system for symplectic bases within QuantumInterface. Similar things could be done for |
Thanks for the reply and good points that you raise @apkille!
#32 is already a significant breaking change for which I'm taking on the responsibility of fixing all dependent packages in the qojulia and QuantumSavory orgs. So I would volunteer to do the same with this change. Hopefully these changes won't be too disruptive for any end user code or packages not in these orgs. It really depends on whether they are using the higher level functions in
Thinking through a bit more about what the goals of Furthermore the generic operations in However, if there's any compelling reason to subtype, then I would suggest making |
That sounds reasonable, but not necessarily high priority. Originally all of these were part of QuantumOptics and I just moved those that I needed (for QuantumSavory) to QuantumInterface. Given that there is no-one outside of QuantumOptics that uses these bases, I am not sure that the move would be a good use of limited dev resources. But if you feel like taking care of it, please go ahead!
Organizationally this is good by me, but I do not think that is necessary. The current API is not necessarily good, but a good API in a multimethod language should not need to externally impose this constraint.
This might be at odds with how historically this happened. All of these types were created specifically for use in QuantumOptics. I contacted the devs of QuantumOptics about abstracting these things away a bit so that I do not need to create a completely separate package with these capabilities when working on QuantumSavory (and to lesser extent on QuantumClifford). As such, many of these objects probably have internal details that are focused on state-vector-specific representation capabilities. In short, I am all on board with abstracting these away, but only if that does not increase the internal complexity of QuantumOptics.
Aren't most of these consistent? Superficially, only the
I do not think we should remove the It is true that you can have different bases (including very differently structured composite/sum bases) for the same Hilbert space, but My current belief is that what you are suggesting (with potentially switching the focus from modifying Basis to inplementing a more general Space) is good elegant first-principles design, but (currently) too breaking with not enough benefit to the current code base. I can be convince otherwise though, especially if we start keeping track of issues or difficulties caused by the current design. |
This is more of a side question, but is it still "technically breaking" after the changes we discussed? I thought it greatly minimized the breakages outside of the internals of QuantumOptics and QuantumSymbolics?
Not really. The actual reason was that these packages were independent. I am slowly transitioning the package to properly subtype StateVector and AbstractOperator and to reuse the generic implementations of ptrace and tensor. If something has a Anyway, back to the big picture. After reading the rest of the comments here, I am leaning towards not changing much about Basis but potentially starting to think about more functionality on top of basis or in parallel to Basis that let's you ask questions about spaces. I think it is fine that we use I think we should not make the type system much more complicated than it currently is. I am uncertain of the benefit of introducing more layers of abstract types. But to be fair here, I am commenting without having had to deal with the low-level code for a while, while you are going through it right now. It is quite possible to convince me that the added complexity (and breakage) is much more necessary than my current gut feeling tells me. Thanks for going through all of this design process, it is incredibly valuable. I am getting on a plane right now, so I can not discuss the rest of the details in the proposal, but let's continue the conversation and maybe even start some collaborative design document. What you are suggesting has to potential for a lot of downstream improvements if we can minimize the breakage. |
Thanks @Krastanov for the background information on how these design choices have evolved! I've been playing with alternative abstract interfaces for the basis system in the past week. This has been a good exercise for myself to understand all the design tradeoffs and downstream impacts that might be incurred with changing the abstract interface. This has raised further issues with the current system which I've been documenting in new issues as I come across them (see #34 and #35 for the recent ones). Replying to a couple points you raise:
Whether we remove it or not, I think we should at least enforce some uniformity on it, since it's used all over
I've been keeping this in mind now with my prototyping of different choices to fix these issues so that they can be "future proof" for eventual closer integration. This is I think one pressing reason to seriously consider doing some breaking changes of the interface since I don't think it's currently compatible with such integration. Specifically see #35.
Changing the number of parametric types and adding type constraints requires everywhere that such types are use (which is a lot in |
Currently the docstring for the abstract type
Basis
statesBefore getting into what this
.shape
field really means, let's get an overview of all the subtypes. First here's all the subtypes defined inQuantumInterface
:Then all the subtypes defined in
QuantumOpticsBase
Finally the only other subtype of
Basis
I could find in all of the dependent packages ofQuantumInterface
wasWaveguideQED.WaveguideBasis
.One general question is whether it makes sense to try to upstream all the subtypes of
Basis
intoQuantumInterface
and discourage dependents from implementing their own subtypes? I think this would be advantageous for a few reasons. The first is simply because the the basis for a Hilbert space is independent of a given representation of the objects on that Hilbert space with respect to the given basis. Thus forQuantumInterface
to provide a common interface and help dependents interoperate, I think it should strive to contain the definitions of all bases that dependents use. Then the fields of each subtype ofBasis
could be well documented as part of the interface. Also we can ensure the fields define only what is necessary in the mathematical notion of that basis, and nothing which secretly encodes aspects that are representation-dependent. This last point brings me to the question of the.shape
field.Looking at the
Basis
docstring and what is practically stored in.shape
, it seems like it's mainly meant forCompositeBasis
. So.shape
stores the dimensions of each of the bases in the.bases
field ofCompositeBasis
, which is understood as the basis for the tensor product space. This is consistent with definingBase.length(b::Basis) = prod(b.shape)
. HoweverSumBasis
also uses.shape
to store the dimensions of each of the bases in its.bases
field and thus must implementlength(b::SumBasis) = sum(b.shape)
. MeanwhileQuantumSymbolics
usesFockBasis(Inf,0.)
in which case the.shape
field is[Inf]
. Finally another example of different meaning assigned to.shape
is in thePositionBasis
andMomentumBasis
. In.shape
they store the number of points at which the wavefunction is evenly sampled between the minimum and maximum cutoff values.I don't actually think there's a universal notion of a
.shape
property which applies to all the various possible bases for a given Hilbert space. This point is best illustrated by the case of separable (i.e. countably infinite) Hilbert space.There are an infinite number of irreducible representations of separable Hilbert space which are unitarily equivalent. The most common representations are fock, position/momentum wavefunction, and phase-space (sometimes called coherent state). Currently
QuantumSymbolics
usesFockBasis(Inf,0.)
to refer to the bases for both the fock and coherent state representations. Also given that #32 will enforce that subtypes ofAbstractOperator
carry a basis, this will break the wayGabs
repurposes those currently free types to parameterize other aspects of Gaussian operators. Since everything inGabs
is actually just working within in the coherent state basis. I think we should consider making these distinctions explicit by reworking the types intended for bases of separable Hilbert space.So concretely, my proposal is to move all subtypes of
Basis
toQuantumInterface
, remove the requirement for all of them to implement.shape
and instead maybe only require that they implementBase.length
which can be allowed to returnInf
or some other sensible representation of countable infinity. Finally, I would rework the bases on separable Hilbert space to look likeIf all this makes sense, I can work on this on top #32!
@Krastanov @apkille
The text was updated successfully, but these errors were encountered: