-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a hint for Schrödinger solver and make hints appropriate (#386)
- Loading branch information
Showing
1 changed file
with
14 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,21 @@ | ||
function __init__() | ||
if isdefined(Base.Experimental, :register_error_hint) | ||
|
||
Base.Experimental.register_error_hint(MethodError) do io, exc, argtypes, kwargs | ||
if exc.f == timeevolution.master | ||
printstyled(io, "\nHint", color=:green) | ||
print(io, ": If your Hamiltonian is time-dependent, then you may want to use master_dynamic instead of master to solve evolution.") | ||
if (exc.f == timeevolution.master) && (length(argtypes) >= 3) | ||
# Check if the given Hamiltonian is constant. | ||
if !(QuantumOpticsBase.is_const(exc.args[3])) | ||
printstyled(io, "\nHint", color=:green) | ||
print(io, ": You are attempting to use a time-dependent Hamiltonian with a solver that assumes constant dynamics. To avoid errors, please use the _dynamic solvers instead, e.g. master_dynamic instead of master_dynamic.") | ||
end | ||
end | ||
end | ||
|
||
if (exc.f == timeevolution.schroedinger) && (length(argtypes) >= 3) | ||
# Check if the given Hamiltonian is constant. | ||
if !(QuantumOpticsBase.is_const(exc.args[3])) | ||
printstyled(io, "\nHint", color=:green) | ||
print(io, ": You are attempting to use a time-dependent Hamiltonian with a solver that assumes constant dynamics. To avoid errors, please use the _dynamic solvers instead, e.g. schroedinger_dynamic instead of schroedinger_dynamic.") | ||
end | ||
end | ||
end | ||
end | ||
end |