From b910d2c1cd7b0d941dcc041995e86bad65b0c40a Mon Sep 17 00:00:00 2001 From: DhairyaLGandhi Date: Fri, 21 Jun 2024 17:02:08 +0530 Subject: [PATCH] chore: use showerror for error messages --- src/concrete_solve.jl | 25 ++++++++++++++++--------- src/sensitivity_interface.jl | 4 +--- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/concrete_solve.jl b/src/concrete_solve.jl index 95cade075..f599c0f56 100644 --- a/src/concrete_solve.jl +++ b/src/concrete_solve.jl @@ -244,9 +244,7 @@ function DiffEqBase._concrete_solve_adjoint(prob::Union{SciMLBase.AbstractODEPro if !(p === nothing || p isa SciMLBase.NullParameters) if !isscimlstructure(p) - error("`p` is not a SciMLStructure. This is required for adjoint sensitivity analysis. For more information, - see the documentation on SciMLStructures.jl for the definition of the SciMLStructures interface. - In particular, adjoint sensitivities only applies to `Tunable`.") + throw(SciMLStructuresCompatiblityError()) end end @@ -275,9 +273,7 @@ function DiffEqBase._concrete_solve_adjoint(prob::Union{ if !(p === nothing || p isa SciMLBase.NullParameters) if !isscimlstructure(p) && !isfunctor(p) - error("`p` is not a SciMLStructure. This is required for adjoint sensitivity analysis. For more information, - see the documentation on SciMLStructures.jl for the definition of the SciMLStructures interface. - In particular, adjoint sensitivities only applies to `Tunable`.") + throw(SciMLStructuresCompatiblityError()) end end @@ -1134,9 +1130,7 @@ function DiffEqBase._concrete_solve_adjoint(prob::Union{SciMLBase.AbstractDiscre if !(p === nothing || p isa SciMLBase.NullParameters) if !isscimlstructure(p) - error("`p` is not a SciMLStructure. This is required for adjoint sensitivity analysis. For more information, - see the documentation on SciMLStructures.jl for the definition of the SciMLStructures interface. - In particular, adjoint sensitivities only applies to `Tunable`.") + throw(SciMLStructuresCompatiblityError()) end end @@ -1317,6 +1311,19 @@ function Base.showerror(io::IO, e::EnzymeTrackedRealError) println(io, ENZYME_TRACKED_REAL_ERROR_MESSAGE) end +const SCIMLSTRUCTURES_ERROR_MESSAGE = """ + `p` is not a SciMLStructure. This is required for adjoint sensitivity analysis. For more information, + see the documentation on SciMLStructures.jl for the definition of the SciMLStructures interface. + In particular, adjoint sensitivities only applies to `Tunable`. + """ + +struct SciMLStructuresCompatiblityError <: Exception +end + +function Base.showerror(io::IO, e::SciMLStructuresCompatiblityError) + println(io, SCIMLSTRUCTURES_ERROR_MESSAGE) +end + function DiffEqBase._concrete_solve_adjoint(prob::Union{SciMLBase.AbstractDiscreteProblem, SciMLBase.AbstractODEProblem, SciMLBase.AbstractDAEProblem, diff --git a/src/sensitivity_interface.jl b/src/sensitivity_interface.jl index b83c0fbfe..748529818 100644 --- a/src/sensitivity_interface.jl +++ b/src/sensitivity_interface.jl @@ -362,9 +362,7 @@ function adjoint_sensitivities(sol, args...; p = SymbolicIndexingInterface.parameter_values(sol) if !(p === nothing || p isa SciMLBase.NullParameters) if !isscimlstructure(p) && !isfunctor(p) - error("`p` is not a SciMLStructure. This is required for adjoint sensitivity analysis. For more information, - see the documentation on SciMLStructures.jl for the definition of the SciMLStructures interface. - In particular, adjoint sensitivities only applies to `Tunable`.") + throw(SciMLStructuresCompatiblityError()) end end