@@ -325,6 +325,24 @@ function Base.showerror(io::IO, err::UnexpectedSymbolicValueInVarmap)
325325 """ )
326326end
327327
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+
328346"""
329347 $(TYPEDSIGNATURES)
330348
@@ -342,10 +360,11 @@ Keyword arguments:
342360 [`missingvars`](@ref) to perform the check.
343361- `allow_symbolic` allows the returned array to contain symbolic values. If this is `true`,
344362 `promotetoconcrete` is set to `false`.
363+ - `is_initializeprob, guesses`: Used to determine whether the system is missing guesses.
345364"""
346365function better_varmap_to_vars (varmap:: AbstractDict , vars:: Vector ;
347366 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 )
349368 isempty (vars) && return nothing
350369
351370 if check
@@ -354,9 +373,17 @@ function better_varmap_to_vars(varmap::AbstractDict, vars::Vector;
354373 end
355374 vals = map (x -> varmap[x], vars)
356375 if ! allow_symbolic
376+ missingsyms = Any[]
377+ missingvals = Any[]
357378 for (sym, val) in zip (vars, vals)
358379 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 ]))
360387 end
361388 end
362389
@@ -704,7 +731,7 @@ Keyword arguments:
704731- `fully_determined`: Override whether the initialization system is fully determined.
705732- `check_initialization_units`: Enable or disable unit checks when constructing the
706733 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
708735 possibly `p`).
709736- `u0_constructor`: A function to apply to the `u0` value returned from `better_varmap_to_vars`
710737 to construct the final `u0` value.
@@ -742,7 +769,7 @@ function process_SciMLProblem(
742769 circular_dependency_max_cycles = 10 ,
743770 substitution_limit = 100 , use_scc = true ,
744771 force_initialization_time_independent = false , algebraic_only = false ,
745- allow_incomplete = false , kwargs... )
772+ allow_incomplete = false , is_initializeprob = false , kwargs... )
746773 dvs = unknowns (sys)
747774 ps = parameters (sys; initial_parameters = true )
748775 iv = has_iv (sys) ? get_iv (sys) : nothing
@@ -815,7 +842,7 @@ function process_SciMLProblem(
815842
816843 u0 = better_varmap_to_vars (
817844 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 )
819846
820847 if u0 != = nothing
821848 u0 = u0_constructor (u0)
0 commit comments