# In MTK, how can I change a system's parameter's default values?

**URL:** https://discourse.julialang.org/t/in-mtk-how-can-i-change-a-systems-parameters-default-values/135092
**Category:** Modelling & Simulations
**Tags:** modelingtoolkit
**Created:** [January 16, 2026, 7:41am UTC](https://discourse.julialang.org/t/in-mtk-how-can-i-change-a-systems-parameters-default-values/135092 "2026-01-16T07:41:04Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![cstjean](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cstjean/32/1444_2.png) [@cstjean](https://discourse.julialang.org/u/cstjean)
#### Post date: [January 16, 2026, 7:41am UTC](https://discourse.julialang.org/t/in-mtk-how-can-i-change-a-systems-parameters-default-values/135092/1 "2026-01-16T07:41:04Z")

</div>

I have a `sys::System`, and I’d like to build a `sys2` that is like `sys`, but `sys2.some_param`’s default is `20`. Right now I use

```julia
"""
``jldoctest
julia> @named sys = MySystem();

julia> param = sys.some_param;

julia> initial_conditions(assign_parameters(sys, [param=>14]))[vol]
14
``
"""
assign_parameters(sys::System, new_params::AbstractDict) =
    MTK.@set sys.initial_conditions = merge(initial_conditions(sys), new_params)

```

to achieve that, but this is ugly code that uses MTK internals. It also does not work if the Dict contains `some_param[2] => new_value`; I have to pass `some_param => new_array`.

I’m aware that “Don’t do this; pass the new parameters as the `ps` parameter” might be the official answer, but it’s not very satisfying. Given that `sys` has parameters, it feels natural that we could change them. `remake` does not seem defined for it.

For context, I want to have `sys2 = fit_parameters(sys, my_data)`. I could of course have it return the new parameters, but I’d prefer to return the new system.

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [January 16, 2026, 8:29am UTC](https://discourse.julialang.org/t/in-mtk-how-can-i-change-a-systems-parameters-default-values/135092/2 "2026-01-16T08:29:57Z")

</div>

Probably better as an issue to discuss adding such a function.

---

<div class="post-metadata">

### Author: ![Brad\_Carman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brad_carman/32/17631_2.png) [@Brad\_Carman](https://discourse.julialang.org/u/Brad_Carman)
#### Post date: [January 16, 2026, 3:59pm UTC](https://discourse.julialang.org/t/in-mtk-how-can-i-change-a-systems-parameters-default-values/135092/3 "2026-01-16T15:59:14Z")

</div>

I have a package I’m working on that can solve this problem: [bradcarman/ModelingToolkitParameters.jl: Parameter Management utility for ModelingToolkit models](https://github.com/bradcarman/ModelingToolkitParameters.jl/tree/main). You can see the initial docs here: [docs](https://github.com/bradcarman/ModelingToolkitParameters.jl/blob/main/docs/src/index.md) that explain the full concept.

For your example, the solutions would look like this…

```julia
# standard defaults
@named sys = MySystem()

# special defaults
motor_params = MotorParams(r=20)
@named sys2 = MySystem(; motor_params)

```

The full MWE…

```julia
using ModelingToolkit
using ModelingToolkit: D_nounits as D, t_nounits as t
using ModelingToolkitParameters

@kwdef mutable struct MotorParams <: Params
    k::Float64 = 0.1
    r::Float64 = 0.01
    l::Float64 = 1e-3
end

@component function Motor(; name)
  pars = @parameters begin
    k 
    r
    l
  end
  vars = @variables begin
    v(t)
    dphi(t) = 0
    i(t) = 0
    di(t)
  end
  eqs = Equation[
    D(i) ~ di
    v ~ i * r + l * di + dphi * k
    D(dphi) ~ k * i
    v ~ sin(t)
  ]

  return ODESystem(eqs, t, vars, pars; name)
end

@component function MySystem(; name, motor_params = MotorParams())
    systems = @named begin
        motor = Motor()
    end
    defaults = motor => motor_params
    return System(Equation[], t, [], []; name, defaults, systems)
end

# standard defaults
@named sys = MySystem()

# special defaults
motor_params = MotorParams(r=20)
@named sys2 = MySystem(; motor_params)

```
