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

Introduce QobjEvo and use SciMLOperators for time evolution #266

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

albertomercurio
Copy link
Member

@albertomercurio albertomercurio commented Oct 15, 2024

Description

With this PR I remove the obsolete operators like OperatorSum and TimeDependentOperatorSum, by introducing the QobjEvo operator, like in python. This struct takes advantage of the SciMLOperators.jl ecosystem, in order to handle in a lazy way complex operators like sum of them and time-dependent ones.

The ObjEvo is and AbstractQuantumObject, with the same fields as the QuantumObject, so they share many of the methods.

The introduction of using SciMLOperators.jl would push us towards the support of automatic differentiation of sesolve, mesolve and mcsolve, allowing the possibility to make quantum optimal control very efficiently.

I made this PR to improve the performance of complex SciMLOperators like our sum of time-dependent operators. So, we have to wait for a new release of the package first.

Todo list:

  • Introduce QobjEvo operator
  • Remove tlist from the parameters, and add it directly as argument
  • Make TimeEvolutionSol type-stable
  • replace t_l with a more readable tlist
  • Update docstrings
  • Remove OperatorSum and TimeDependentOperatorSum
  • Update sesolve with the support of QobjEvo
  • Update mesolve with the support of QobjEvo
  • Update mcsolve with the support of QobjEvo
  • Add tests for all the added methods
  • Wait for merging of this PR and new release of SciMLOperators.jl
  • Add documentation

struct ProgressBar{CT,T1<:Integer,T2<:Real,T3,T4<:Real,LT}
mutable struct ProgressBar{CT,T1<:Integer,T2<:Real,T3,T4<:Real,LT}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change should be in another PR.
maybe you need to merge from main branch locally first.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have just done "merge from upstream:main", but now it seems a like a change

Comment on lines +41 to 44
if A isa QuantumObjectEvolution || B isa QuantumObjectEvolution
return QuantumObjectEvolution($(op)(A.data, B.data), A.type, A.dims)
end
return QuantumObject($(op)(A.data, B.data), A.type, A.dims)
Copy link
Member

@ytdHuang ytdHuang Oct 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can extend the basic julia function promote_type (maybe put it in the file utilities.jl ?) for this.
something like

promote_type(A::QuantumObjectEvolution, B::QuantumObjectEvolution) = get_typename_wrapper(A)
promote_type(A::QuantumObjectEvolution, B::QuantumObject) = get_typename_wrapper(A)
promote_type(A::QuantumObject, B::QuantumObjectEvolution) = get_typename_wrapper(B)
promote_type(A::QuantumObject, B::QuantumObject) = get_typename_wrapper(A)

and therefore, this kind of if-condition block can be simplified as

QType = promote_type(A, B)
QType($(op)(A.data, B.data), A.type, A.dims)

This can also be implemented in the other functions.

Compute the generalized dot product `dot(i, A*j)` between three [`QuantumObject`](@ref): ``\langle i | \hat{A} | j \rangle``
Compute the generalized dot product `dot(i, A*j)` between three [`AbstractQuantumObject`](@ref): ``\langle i | \hat{A} | j \rangle``
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe change this as

Compute the generalized dot product `dot(i, A*j)` between [`AbstractQuantumObject`](@ref) `A` and two [`QuantumObject`](@ref) (`i` and `j`), namely ``\langle i | \hat{A} | j \rangle``

@@ -6,71 +6,79 @@ export isket, isbra, isoper, isoperbra, isoperket, issuper
export isunitary
Copy link
Member

@ytdHuang ytdHuang Oct 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also add a new function isconstant in the end of first line ?
I saw that QuTiP also got this function.
But this is not necessary at this moment, can be done in future PRs

Comment on lines +196 to +199
if A isa QuantumObjectEvolution || B isa QuantumObjectEvolution
return QuantumObjectEvolution(kron(A.data, B.data), A.type, vcat(A.dims, B.dims))
end
return QuantumObject(kron(A.data, B.data), A.type, vcat(A.dims, B.dims))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can also use promote_type mentioned above

Comment on lines 386 to 387
_FType(::QuantumObject{<:AbstractArray{T}}) where {T<:Number} = _FType(T)
_CType(::QuantumObject{<:AbstractArray{T}}) where {T<:Number} = _CType(T)
Copy link
Member

@ytdHuang ytdHuang Oct 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can change these to

_FType(A::AbstractQuantumObject) = _FType(eltype(A))
_CType(A::AbstractQuantumObject) = _CType(eltype(A))

@@ -23,6 +23,7 @@ end
function LindbladJumpAffect!(integrator)
internal_params = integrator.p
c_ops = internal_params.c_ops
c_ops_herm = internal_params.c_ops_herm
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this is done by another PR, maybe you need to merge from main branch locally first.

Comment on lines +43 to +46
alg=Tsit5()
e_ops = nothing,
params=NamedTuple(),
progress_bar=Val(true),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessary but I think it would be better to add blanks on both sides of =

⎢⠀⠀⠀⠀⠀⠀⠂⡑⢄⠀⎥
⎣⠀⠀⠀⠀⠀⠀⠀⠀⠂⡑⎦
"""
struct QuantumObjectEvolution{DT<:AbstractSciMLOperator,ObjType<:QuantumObjectType,N} <:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to restrict ObjType<:Union{OperatorQuantumObject,SuperOperatorQuantumObject} here ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants