-
Notifications
You must be signed in to change notification settings - Fork 104
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
Promote state and time-span in schroedinger
to the type from H(t)*psi
#356
Changes from 8 commits
dff8b1a
2e78b53
d5097bc
fe2e01a
c00785d
8932e03
73a1684
8174cb8
339da4f
4a82847
fa987dd
098ad85
b38e498
d8b629e
8e5671b
9693133
65d15cf
4f0a4e8
430c0dc
f6039d0
c346074
102218d
5e71135
3f1611f
9ae3ee9
2842f68
66c024a
cffea71
c3f9cc5
0965915
b11273b
a719bc3
dfe7b95
26aa49a
447ccd5
1ca17ec
b312938
a128c33
203846f
f3e59fc
9020a11
c9ad058
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ function schroedinger(tspan, psi0::T, H::AbstractOperator{B,B}; | |
fout::Union{Function,Nothing}=nothing, | ||
kwargs...) where {B,T<:Union{AbstractOperator{B,B},StateVector{B}}} | ||
dschroedinger_(t, psi, dpsi) = dschroedinger!(dpsi, H, psi) | ||
tspan, psi0 = _promote_time_and_state(tspan, psi0, H) # promote | ||
x0 = psi0.data | ||
state = copy(psi0) | ||
dstate = copy(psi0) | ||
|
@@ -41,6 +42,7 @@ function schroedinger_dynamic(tspan, psi0, f; | |
fout::Union{Function,Nothing}=nothing, | ||
kwargs...) | ||
dschroedinger_(t, psi, dpsi) = dschroedinger_dynamic!(dpsi, f, psi, t) | ||
tspan, psi0 = _promote_time_and_state(tspan, psi0, f) # promote | ||
x0 = psi0.data | ||
state = copy(psi0) | ||
dstate = copy(psi0) | ||
|
@@ -102,3 +104,18 @@ function check_schroedinger(psi::Bra, H) | |
check_multiplicable(psi, H) | ||
check_samebases(H) | ||
end | ||
|
||
|
||
_promote_time_and_state(tspan, psi0, f) = _promote_time_and_state(tspan, psi0, f(first(tspan), psi0)) | ||
function _promote_time_and_state(tspan, psi0, H::AbstractOperator) | ||
# general case is Ts<:Complex, Tt<:Real | ||
Ts = eltype(H) | ||
Tt = real(Ts) | ||
(isconcretetype(Ts) && isconcretetype(Tt)) || @warn "For using `ForwardDiff` on `schroedinger` the element type of `real(H(t,psi)*psi)` must be concrete !!\nGot elements of type $Tt \nTry promoting the Hamiltonian elements based on the parameters you are differentiating by." | ||
tspan = Tt.(tspan) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I imagine there are situations where no promotion is necessary. Can we shortcircuit those? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll declare type |
||
psi0 = _promote_state(Ts, psi0) | ||
return tspan, psi0 | ||
end | ||
_promote_state(Ts, psi0::Operator) = Operator(psi0.basis_l, psi0.basis_r, Ts.(psi0.data)) | ||
_promote_state(Ts, psi0::Ket) = Ket(psi0.basis, Ts.(psi0.data)) | ||
_promote_state(Ts, psi0::Bra) = Bra(psi0.basis, Ts.(psi0.data)) |
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.
In what situations would this warning message be seen? I feel it might be confusing as it will show up in front of users that have not touched
ForwardDiff
orschroedinger
.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.
I'll remove it.
This was trying to warn about something like
in the definition of
get_Ht
.But It doesn't cover all possible "bad" definitions of
get_Ht
.