From 88c15cac25a701e27a11466760f71bf7be1fb69b Mon Sep 17 00:00:00 2001 From: Ali Date: Mon, 13 May 2024 11:15:06 +0100 Subject: [PATCH] =?UTF-8?q?Add=20a=20hint=20for=20Schr=C3=B6dinger=20solve?= =?UTF-8?q?r=20and=20make=20hints=20appropriate=20(#386)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/debug.jl | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/debug.jl b/src/debug.jl index 566e6685..a813c5a9 100644 --- a/src/debug.jl +++ b/src/debug.jl @@ -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 \ No newline at end of file