Skip to content

Commit f57997b

Browse files
committed
throw error only in case of initializationproblem
1 parent ab5c680 commit f57997b

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/systems/problem_utils.jl

+8-4
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,13 @@ end
333333
function Base.showerror(io::IO, err::MissingGuessError)
334334
println(io,
335335
"""
336-
The problem cannot be initialized without providing an additional numeric \
337-
guess to serve as a starting point for solving for the initial state. Please \
338-
provide another numeric value to `guesses` in the problem constructor.
336+
Unable to resolve numeric guesses for all of the variables in the system. \
337+
This may be because your guesses are cyclic.
338+
339+
In order for the problem to be initialized, all of the variables must have \
340+
a numeric value to serve as a starting point for the nonlinear solve. \
341+
Please provide one or more additional numeric guesses to `guesses` in \
342+
the problem constructor.
339343
340344
This error was thrown because symbolic value $(err.val) was found for variable $(err.sym).
341345
""")
@@ -358,7 +362,7 @@ Keyword arguments:
358362
[`missingvars`](@ref) to perform the check.
359363
- `allow_symbolic` allows the returned array to contain symbolic values. If this is `true`,
360364
`promotetoconcrete` is set to `false`.
361-
- `is_initializeprob`: Whether the parent problem is an initialization problem.
365+
- `is_initializeprob, guesses`: Used to determine whether the system is missing guesses.
362366
"""
363367
function better_varmap_to_vars(varmap::AbstractDict, vars::Vector;
364368
tofloat = true, use_union = true, container_type = Array,

test/initial_values.jl

+13-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ end
172172
[p => 2q, q => 3p]; warn_cyclic_dependency = true)
173173
catch
174174
end
175-
@test_throws ModelingToolkit.UnexpectedSymbolicValueInVarmap ODEProblem(
175+
@test_throws ModelingToolkit.MissingGuessError ODEProblem(
176176
sys, [x => 1, y => 2], (0.0, 1.0), [p => 2q, q => 3p])
177177
end
178178

@@ -199,3 +199,15 @@ end
199199
@test SciMLBase.successful_retcode(sol)
200200
@test sol.u[1] [1.0, 1.0, 0.5, 0.5]
201201
end
202+
203+
@testset "Missing/cyclic guesses throws error" begin
204+
@parameters g
205+
@variables x(t) y(t) [state_priority = 10] λ(t)
206+
eqs = [D(D(x)) ~ λ * x
207+
D(D(y)) ~ λ * y - g
208+
x^2 + y^2 ~ 1]
209+
@mtkbuild pend = ODESystem(eqs, t)
210+
211+
@test_throws ModelingToolkit.MissingGuessError ODEProblem(pend, [x => 1], (0, 1), [g => 1], guesses = [y => λ, λ => y + 1])
212+
ODEProblem(pend, [x => 1], (0, 1), [g => 1], guesses = [y => λ, λ => 0.5])
213+
end

0 commit comments

Comments
 (0)