@@ -325,6 +325,22 @@ function Base.showerror(io::IO, err::UnexpectedSymbolicValueInVarmap)
325
325
""" )
326
326
end
327
327
328
+ struct MissingGuessError <: Exception
329
+ sym:: Any
330
+ val:: Any
331
+ end
332
+
333
+ function Base. showerror (io:: IO , err:: MissingGuessError )
334
+ println (io,
335
+ """
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.
339
+
340
+ This error was thrown because symbolic value $(err. val) was found for variable $(err. sym) .
341
+ """ )
342
+ end
343
+
328
344
"""
329
345
$(TYPEDSIGNATURES)
330
346
@@ -342,10 +358,11 @@ Keyword arguments:
342
358
[`missingvars`](@ref) to perform the check.
343
359
- `allow_symbolic` allows the returned array to contain symbolic values. If this is `true`,
344
360
`promotetoconcrete` is set to `false`.
361
+ - `is_initializeprob`: Whether the parent problem is an initialization problem.
345
362
"""
346
363
function better_varmap_to_vars (varmap:: AbstractDict , vars:: Vector ;
347
364
tofloat = true , use_union = true , container_type = Array,
348
- toterm = default_toterm, promotetoconcrete = nothing , check = true , allow_symbolic = false )
365
+ toterm = default_toterm, promotetoconcrete = nothing , check = true , allow_symbolic = false , is_initializeprob = false )
349
366
isempty (vars) && return nothing
350
367
351
368
if check
@@ -356,7 +373,11 @@ function better_varmap_to_vars(varmap::AbstractDict, vars::Vector;
356
373
if ! allow_symbolic
357
374
for (sym, val) in zip (vars, vals)
358
375
symbolic_type (val) == NotSymbolic () && continue
359
- throw (UnexpectedSymbolicValueInVarmap (sym, val))
376
+ if is_initializeprob
377
+ throw (MissingGuessError (sym, val))
378
+ else
379
+ throw (UnexpectedSymbolicValueInVarmap (sym, val))
380
+ end
360
381
end
361
382
end
362
383
@@ -704,7 +725,7 @@ Keyword arguments:
704
725
- `fully_determined`: Override whether the initialization system is fully determined.
705
726
- `check_initialization_units`: Enable or disable unit checks when constructing the
706
727
initialization problem.
707
- - `tofloat`, `use_union`: Passed to [`better_varmap_to_vars`](@ref) for building `u0` (and
728
+ - `tofloat`, `use_union`, `is_initializeprob` : Passed to [`better_varmap_to_vars`](@ref) for building `u0` (and
708
729
possibly `p`).
709
730
- `u0_constructor`: A function to apply to the `u0` value returned from `better_varmap_to_vars`
710
731
to construct the final `u0` value.
@@ -742,7 +763,7 @@ function process_SciMLProblem(
742
763
circular_dependency_max_cycles = 10 ,
743
764
substitution_limit = 100 , use_scc = true ,
744
765
force_initialization_time_independent = false , algebraic_only = false ,
745
- allow_incomplete = false , kwargs... )
766
+ allow_incomplete = false , is_initializeprob = false , kwargs... )
746
767
dvs = unknowns (sys)
747
768
ps = parameters (sys; initial_parameters = true )
748
769
iv = has_iv (sys) ? get_iv (sys) : nothing
@@ -815,7 +836,7 @@ function process_SciMLProblem(
815
836
816
837
u0 = better_varmap_to_vars (
817
838
op, dvs; tofloat = true , use_union = false ,
818
- container_type = u0Type, allow_symbolic = symbolic_u0)
839
+ container_type = u0Type, allow_symbolic = symbolic_u0, is_initializeprob )
819
840
820
841
if u0 != = nothing
821
842
u0 = u0_constructor (u0)
0 commit comments