Skip to content

Commit d5f901e

Browse files
feat: evaluate in better_varmap_to_vars
1 parent 1173ebc commit d5f901e

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/systems/problem_utils.jl

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,26 @@ function Base.showerror(io::IO, err::MissingGuessError)
328328
In order to resolve this, please provide additional numeric guesses so that the chain can be resolved to assign numeric values to each variable. """)
329329
end
330330

331+
const MISSING_VARIABLES_MESSAGE = """
332+
Initial condition underdefined. Some are missing from the variable map.
333+
Please provide a default (`u0`), initialization equation, or guess
334+
for the following variables:
335+
"""
336+
337+
struct MissingVariablesError <: Exception
338+
vars::Any
339+
end
340+
341+
function Base.showerror(io::IO, e::MissingVariablesError)
342+
println(io, MISSING_VARIABLES_MESSAGE)
343+
println(io, join(e.vars, ", "))
344+
end
345+
331346
"""
332347
$(TYPEDSIGNATURES)
333348
334349
Return an array of values where the `i`th element corresponds to the value of `vars[i]`
335-
in `varmap`. Does not perform symbolic substitution in the values of `varmap`.
350+
in `varmap`. Will mutate `varmap` by symbolically substituting it into itself.
336351
337352
Keyword arguments:
338353
- `tofloat`: Convert values to floating point numbers using `float`.
@@ -345,11 +360,13 @@ Keyword arguments:
345360
- `allow_symbolic` allows the returned array to contain symbolic values. If this is `true`,
346361
`promotetoconcrete` is set to `false`.
347362
- `is_initializeprob, guesses`: Used to determine whether the system is missing guesses.
363+
- `substitution_limit`: The maximum number of times to substitute `varmap` into itself to
364+
obtain numerical values for the variables in `vars`.
348365
"""
349366
function better_varmap_to_vars(varmap::AbstractDict, vars::Vector;
350367
tofloat = true, container_type = Array, floatT = Nothing,
351368
toterm = default_toterm, promotetoconcrete = nothing, check = true,
352-
allow_symbolic = false, is_initializeprob = false)
369+
allow_symbolic = false, is_initializeprob = false, substitution_limit = 1000)
353370
isempty(vars) && return nothing
354371

355372
varmap = recursive_unwrap(varmap)
@@ -358,6 +375,7 @@ function better_varmap_to_vars(varmap::AbstractDict, vars::Vector;
358375
missing_vars = missingvars(varmap, vars; toterm)
359376
isempty(missing_vars) || throw(MissingVariablesError(missing_vars))
360377
end
378+
evaluate_varmap!(varmap, vars; limit = substitution_limit)
361379
vals = map(x -> varmap[x], vars)
362380
if !allow_symbolic
363381
missingsyms = Any[]

0 commit comments

Comments
 (0)