-
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
RFC: Proposal for reworked basis sytem #40
Comments
I think this looks generally sane to me. Though "QObj" is maybe a little too QuTiP/pythonesque, no? Not sure what else to use though :) I really like removing the basis type parameters from the operators and states. IIRC we rarely dispatch on them in functions that take operators/states anyway. Perhaps we distinguish composite from single-site bases in some operator/state functions, but that can still be done using a "holy traits" pattern (or even just a simple The superoperator approach also seems about right to me. That said, I'd want to be able to use the usual operator types (like LazySum and LazyTensor) for superoperators too. Is your proposal to have |
Thanks for the comments @amilsted!
Yep, happy to rename this to something better. Maybe just being verbose
It's a little confusing since there's many representations of superoperators, while To keep compatibility and since it's convenient to have an explicit type, I would make |
Could it not wrap a more generic |
I think for #27 it would already help if the mul and add checks would see a 1-element Btw, should we have an |
I'm not sure I follow? I think the point is that |
I think this might be easiest to handle by just appropriately defining
Perhaps, but it might be easier to just add support for something like that directly to |
I've opened a lot of issues and done a lot of prototyping for various ways to improve basis handling here and in dependents. Rather than commenting on each issue separately, I wanted to collect them here and outline my proposal for what a better system looks like and how to get us there. This is partly since there's a lot of subtle interdependence between the issues and fixes for them.
Let's start with the abstract type interface which has been discussed in #26. Based on the experiments in #34 indicating the performance pitfalls of compilation overhead due to combinatorial explosion in type specialization (also see relevant Julia docs), I now think we should not have any type parameters here. If they are necessary in dependent packages, they can reintroduce them easily. So we would have
For all the subtypes of
Basis
defined here, I think we should move to a method interface (see relevant Julia style guide section) which looks likeIn addition all subtypes of
Basis
will be required to implementBase.:(==)
andBase.size
where the latter must return a tuple with tensor product decomposition of the Hilbert space that the basis defines so thatBase.length(b::Basis) = prod(size(b))
gives the total dimension of the Hilbert space (this is currently the.shape
field).Since removing the basis type parameter from
AbstractQObjType
is meant to go along with moving basis compatibility checks to be entirely dynamic, I think that interface can be improved to look like:multiplicable(a::T,b::T) where {T<:AbstractQObjType}
checks that they can be multiplied andmultiplicable(a,a)
checks that an operator is square.addible(a::T,b::T) where {T<:AbstractQObjType}
checks that they can be added or that the objects can be compared for equality.check_*
versions of the above with a@compatiblebases
macro which disables them.Finally to address the issue of superoperators and operator bases such as the pauli operator basis (#35, #36). I think I've unfortunately been fairly confused myself about the best way to handle all of this for awhile, but I think I'm hopefully thinking more clearly about it now. I think it's best to view superoperators as simply operators, while the input and output operators they map between are viewed as states corresponding to the vec'd operators.
Concretely this means that the
SuperOperator
type inQuantumOpticsBase
should subtypeAbstractOperator
and we should introduce a newKetBraBasis <: Basis
here. Then we can have thatbasis_{l,r}(sop::SuperOperator) isa KetBraBasis
. More generally all the different types of superoperator representations are related by the different operator bases that they map between. So we can introduce appropriate subtypes of Basis to disambiguate left and right bases ofSuperOperator
,ChoiState
,KrausOperators
,PauliTransferMatrix
,ChiMatrix
. I think this will help a lot with code reuse between theoperators*.jl
,superoperators.jl
andpauli.jl
files since there's currently a lot of re-implemented functionality for dense and sparse representations between all those files. I think this also fits much better with Julia's type system. Some operations are the same between operators and superoperators and thus can be shared such as their basis checks. Other are different, such a multiplying two ChoiStates should probably represent the composition of their maps rather than the multiplication of their density matrices even though both are entirely valid things to do with those objects. Method specialization makes this easy to do.Thoughts @Krastanov @amilsted @apkille?
The text was updated successfully, but these errors were encountered: