Skip to content

Commit

Permalink
Add a hint for Schrödinger solver and make hints appropriate (#386)
Browse files Browse the repository at this point in the history
  • Loading branch information
a-eghrari committed May 13, 2024
1 parent 3cadecc commit 88c15ca
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/debug.jl
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

0 comments on commit 88c15ca

Please sign in to comment.