diff --git a/src/systems/problem_utils.jl b/src/systems/problem_utils.jl index daf1c164d8..3e50cc41cc 100644 --- a/src/systems/problem_utils.jl +++ b/src/systems/problem_utils.jl @@ -301,12 +301,14 @@ end """ $(TYPEDSIGNATURES) -Performs symbolic substitution on the values in `varmap`, using `varmap` itself as the -set of substitution rules. -""" -function evaluate_varmap!(varmap::AbstractDict) - for (k, v) in varmap - varmap[k] = fixpoint_sub(v, varmap) +Performs symbolic substitution on the values in `varmap` for the keys in `vars`, using +`varmap` itself as the set of substitution rules. If an entry in `vars` is not a key +in `varmap`, it is ignored. +""" +function evaluate_varmap!(varmap::AbstractDict, vars) + for k in vars + haskey(varmap, k) || continue + varmap[k] = fixpoint_sub(varmap[k], varmap) end end @@ -499,7 +501,7 @@ function process_SciMLProblem( add_observed!(sys, op) add_parameter_dependencies!(sys, op) - evaluate_varmap!(op) + evaluate_varmap!(op, dvs) u0 = better_varmap_to_vars( op, dvs; tofloat = true, use_union = false, @@ -511,6 +513,7 @@ function process_SciMLProblem( check_eqs_u0(eqs, dvs, u0; check_length, kwargs...) + evaluate_varmap!(op, ps) if is_split(sys) p = MTKParameters(sys, op) else diff --git a/test/initial_values.jl b/test/initial_values.jl index 9911bab7f4..fc386242a6 100644 --- a/test/initial_values.jl +++ b/test/initial_values.jl @@ -136,3 +136,16 @@ end prob = @test_nowarn ODEProblem(sys, [], (0.0, 1.0)) @test prob.p isa Vector{Float64} end + +@testset "Issue#3153" begin + @variables x(t) y(t) + @parameters c1 c2 c3 + eqs = [D(x) ~ y, + y ~ ifelse(t < c1, 0.0, (-c1 + t)^(c3))] + sps = [x, y] + ps = [c1, c2, c3] + @mtkbuild osys = ODESystem(eqs, t, sps, ps) + u0map = [x => 1.0] + pmap = [c1 => 5.0, c2 => 1.0, c3 => 1.2] + oprob = ODEProblem(osys, u0map, (0.0, 10.0), pmap) +end diff --git a/test/runtests.jl b/test/runtests.jl index 5db3308540..c7edbfaaf5 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -19,48 +19,48 @@ end @time begin if GROUP == "All" || GROUP == "InterfaceI" @testset "InterfaceI" begin - # @safetestset "Linear Algebra Test" include("linalg.jl") - # @safetestset "AbstractSystem Test" include("abstractsystem.jl") - # @safetestset "Variable Scope Tests" include("variable_scope.jl") - # @safetestset "Symbolic Parameters Test" include("symbolic_parameters.jl") - # @safetestset "Parsing Test" include("variable_parsing.jl") - # @safetestset "Simplify Test" include("simplify.jl") - # @safetestset "Direct Usage Test" include("direct.jl") - # @safetestset "System Linearity Test" include("linearity.jl") - # @safetestset "Input Output Test" include("input_output_handling.jl") - # @safetestset "Clock Test" include("clock.jl") - # @safetestset "ODESystem Test" include("odesystem.jl") - # @safetestset "Dynamic Quantities Test" include("dq_units.jl") - # @safetestset "Unitful Quantities Test" include("units.jl") - # @safetestset "Mass Matrix Test" include("mass_matrix.jl") - # @safetestset "InitializationSystem Test" include("initializationsystem.jl") - # @safetestset "Guess Propagation" include("guess_propagation.jl") - # @safetestset "Hierarchical Initialization Equations" include("hierarchical_initialization_eqs.jl") - # @safetestset "Reduction Test" include("reduction.jl") - # @safetestset "Split Parameters Test" include("split_parameters.jl") - # @safetestset "StaticArrays Test" include("static_arrays.jl") - # @safetestset "Components Test" include("components.jl") - # @safetestset "Model Parsing Test" include("model_parsing.jl") - # @safetestset "Error Handling" include("error_handling.jl") - # @safetestset "StructuralTransformations" include("structural_transformation/runtests.jl") - # @safetestset "State Selection Test" include("state_selection.jl") - # @safetestset "Symbolic Event Test" include("symbolic_events.jl") - # @safetestset "Stream Connect Test" include("stream_connectors.jl") - # @safetestset "Domain Connect Test" include("domain_connectors.jl") - # @safetestset "Lowering Integration Test" include("lowering_solving.jl") - # @safetestset "Dependency Graph Test" include("dep_graphs.jl") - # @safetestset "Function Registration Test" include("function_registration.jl") - # @safetestset "Precompiled Modules Test" include("precompile_test.jl") - # @safetestset "DAE Jacobians Test" include("dae_jacobian.jl") - # @safetestset "Jacobian Sparsity" include("jacobiansparsity.jl") + @safetestset "Linear Algebra Test" include("linalg.jl") + @safetestset "AbstractSystem Test" include("abstractsystem.jl") + @safetestset "Variable Scope Tests" include("variable_scope.jl") + @safetestset "Symbolic Parameters Test" include("symbolic_parameters.jl") + @safetestset "Parsing Test" include("variable_parsing.jl") + @safetestset "Simplify Test" include("simplify.jl") + @safetestset "Direct Usage Test" include("direct.jl") + @safetestset "System Linearity Test" include("linearity.jl") + @safetestset "Input Output Test" include("input_output_handling.jl") + @safetestset "Clock Test" include("clock.jl") + @safetestset "ODESystem Test" include("odesystem.jl") + @safetestset "Dynamic Quantities Test" include("dq_units.jl") + @safetestset "Unitful Quantities Test" include("units.jl") + @safetestset "Mass Matrix Test" include("mass_matrix.jl") + @safetestset "InitializationSystem Test" include("initializationsystem.jl") + @safetestset "Guess Propagation" include("guess_propagation.jl") + @safetestset "Hierarchical Initialization Equations" include("hierarchical_initialization_eqs.jl") + @safetestset "Reduction Test" include("reduction.jl") + @safetestset "Split Parameters Test" include("split_parameters.jl") + @safetestset "StaticArrays Test" include("static_arrays.jl") + @safetestset "Components Test" include("components.jl") + @safetestset "Model Parsing Test" include("model_parsing.jl") + @safetestset "Error Handling" include("error_handling.jl") + @safetestset "StructuralTransformations" include("structural_transformation/runtests.jl") + @safetestset "State Selection Test" include("state_selection.jl") + @safetestset "Symbolic Event Test" include("symbolic_events.jl") + @safetestset "Stream Connect Test" include("stream_connectors.jl") + @safetestset "Domain Connect Test" include("domain_connectors.jl") + @safetestset "Lowering Integration Test" include("lowering_solving.jl") + @safetestset "Dependency Graph Test" include("dep_graphs.jl") + @safetestset "Function Registration Test" include("function_registration.jl") + @safetestset "Precompiled Modules Test" include("precompile_test.jl") + @safetestset "DAE Jacobians Test" include("dae_jacobian.jl") + @safetestset "Jacobian Sparsity" include("jacobiansparsity.jl") @safetestset "Modelingtoolkitize Test" include("modelingtoolkitize.jl") - # @safetestset "FuncAffect Test" include("funcaffect.jl") - # @safetestset "Constants Test" include("constants.jl") - # @safetestset "Parameter Dependency Test" include("parameter_dependencies.jl") - # @safetestset "Generate Custom Function Test" include("generate_custom_function.jl") - # @safetestset "Initial Values Test" include("initial_values.jl") - # @safetestset "Equation Type Accessors Test" include("equation_type_accessors.jl") - # @safetestset "Equations with complex values" include("complex.jl") + @safetestset "FuncAffect Test" include("funcaffect.jl") + @safetestset "Constants Test" include("constants.jl") + @safetestset "Parameter Dependency Test" include("parameter_dependencies.jl") + @safetestset "Generate Custom Function Test" include("generate_custom_function.jl") + @safetestset "Initial Values Test" include("initial_values.jl") + @safetestset "Equation Type Accessors Test" include("equation_type_accessors.jl") + @safetestset "Equations with complex values" include("complex.jl") end end