@@ -325,6 +325,24 @@ function Base.showerror(io::IO, err::UnexpectedSymbolicValueInVarmap)
325
325
""" )
326
326
end
327
327
328
+ struct MissingGuessError <: Exception
329
+ syms:: Vector{Any}
330
+ vals:: Vector{Any}
331
+ end
332
+
333
+ function Base. showerror (io:: IO , err:: MissingGuessError )
334
+ println (io,
335
+ """
336
+ Cyclic guesses detected in the system. Symbolic values were found for the following variables/parameters in the map: \
337
+ """ )
338
+ for (sym, val) in zip (err. syms, err. vals)
339
+ println (io, " $sym => $val " )
340
+ end
341
+ println (io,
342
+ """
343
+ In order to resolve this, please provide additional numeric guesses so that the chain can be resolved to assign numeric values to each variable. """ )
344
+ end
345
+
328
346
"""
329
347
$(TYPEDSIGNATURES)
330
348
@@ -342,10 +360,11 @@ Keyword arguments:
342
360
[`missingvars`](@ref) to perform the check.
343
361
- `allow_symbolic` allows the returned array to contain symbolic values. If this is `true`,
344
362
`promotetoconcrete` is set to `false`.
363
+ - `is_initializeprob, guesses`: Used to determine whether the system is missing guesses.
345
364
"""
346
365
function better_varmap_to_vars (varmap:: AbstractDict , vars:: Vector ;
347
366
tofloat = true , use_union = true , container_type = Array,
348
- toterm = default_toterm, promotetoconcrete = nothing , check = true , allow_symbolic = false )
367
+ toterm = default_toterm, promotetoconcrete = nothing , check = true , allow_symbolic = false , is_initializeprob = false )
349
368
isempty (vars) && return nothing
350
369
351
370
if check
@@ -354,9 +373,17 @@ function better_varmap_to_vars(varmap::AbstractDict, vars::Vector;
354
373
end
355
374
vals = map (x -> varmap[x], vars)
356
375
if ! allow_symbolic
376
+ missingsyms = Any[]
377
+ missingvals = Any[]
357
378
for (sym, val) in zip (vars, vals)
358
379
symbolic_type (val) == NotSymbolic () && continue
359
- throw (UnexpectedSymbolicValueInVarmap (sym, val))
380
+ push! (missingsyms, sym)
381
+ push! (missingvals, val)
382
+ end
383
+
384
+ if ! isempty (missingsyms)
385
+ is_initializeprob ? throw (MissingGuessError (missingsyms, missingvals)) :
386
+ throw (UnexpectedSymbolicValueInVarmap (missingsyms[1 ], missingvals[1 ]))
360
387
end
361
388
end
362
389
@@ -704,7 +731,7 @@ Keyword arguments:
704
731
- `fully_determined`: Override whether the initialization system is fully determined.
705
732
- `check_initialization_units`: Enable or disable unit checks when constructing the
706
733
initialization problem.
707
- - `tofloat`, `use_union`: Passed to [`better_varmap_to_vars`](@ref) for building `u0` (and
734
+ - `tofloat`, `use_union`, `is_initializeprob` : Passed to [`better_varmap_to_vars`](@ref) for building `u0` (and
708
735
possibly `p`).
709
736
- `u0_constructor`: A function to apply to the `u0` value returned from `better_varmap_to_vars`
710
737
to construct the final `u0` value.
@@ -742,7 +769,7 @@ function process_SciMLProblem(
742
769
circular_dependency_max_cycles = 10 ,
743
770
substitution_limit = 100 , use_scc = true ,
744
771
force_initialization_time_independent = false , algebraic_only = false ,
745
- allow_incomplete = false , kwargs... )
772
+ allow_incomplete = false , is_initializeprob = false , kwargs... )
746
773
dvs = unknowns (sys)
747
774
ps = parameters (sys; initial_parameters = true )
748
775
iv = has_iv (sys) ? get_iv (sys) : nothing
@@ -815,7 +842,7 @@ function process_SciMLProblem(
815
842
816
843
u0 = better_varmap_to_vars (
817
844
op, dvs; tofloat = true , use_union = false ,
818
- container_type = u0Type, allow_symbolic = symbolic_u0)
845
+ container_type = u0Type, allow_symbolic = symbolic_u0, is_initializeprob )
819
846
820
847
if u0 != = nothing
821
848
u0 = u0_constructor (u0)
0 commit comments