# Simulate ModelingToolkit system with different parameters

**URL:** <https://discourse.julialang.org/t/simulate-modelingtoolkit-system-with-different-parameters/133791>\
**Category:** Modelling & Simulations\
**Tags:** modelingtoolkit\
**Created:** [November 11, 2025, 11:44am UTC](https://discourse.julialang.org/t/simulate-modelingtoolkit-system-with-different-parameters/133791 "2025-11-11T11:44:07Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![JaviJR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/javijr/32/218294_2.png) [@JaviJR](https://discourse.julialang.org/u/JaviJR)\
**Post date:** [November 11, 2025, 11:44am UTC](https://discourse.julialang.org/t/simulate-modelingtoolkit-system-with-different-parameters/133791/1 "2025-11-11T11:44:07Z")

</div>

Hi all,

In the past day, I have been reading the documentation on efficiently simulating ModelingToolkit models with different parameters. However, I find the documentation somewhat complex, especially for new users. In my case, I have a very simple system, which consists of a constant input and an integrator:

```julia-auto
using ModelingToolkit, Plots, OrdinaryDiffEq
using ModelingToolkit: t_nounits as t, D_nounits as D
using ModelingToolkitStandardLibrary.Blocks

@mtkmodel TestModel begin

	@parameters begin

		value=3
	
	end

	@components begin

		InputBlock = Constant(k=value)
		IntegratorBlock = Integrator(k=1.0,x=0.0)
	end

	@equations begin

		connect(InputBlock.output,IntegratorBlock.input)

	end

end
@mtkbuild system = TestModel()
prob = ODEProblem(system,Pair[],(0,10.0))
sol = solve(prob,Tsit5(), dt=0.001, adaptive=false) 

```

Suppose I want to re-simulate the system by changing the parameter of the constant value that serves as the input, without having to recompile the system. In this case, when I query the parameters, I get the following:

```julia-auto
prob.p

```

 ![Parameters](https://global.discourse-cdn.com/julialang/original/3X/9/0/9007b1b4a94faa6db8afa12d5b484ab9f7216e19.png)

First, I noticed that the initial value (in this case, 3) appears twice: once as a constant and once as the input value of the constant block. When trying to re-simulate the system by changing this parameter (for example, to 5), I implemented the following code. However, the solution of the system does not change at all.

```julia-auto
p_new = copy(prob.p)  
p_new[1][4] = 5
prob2 = remake(prob; p = p_new)
sol2 = solve(prob2,Tsit5(), dt=0.001, adaptive=false) 

```

For this reason, I wonder if this process is incorrect. If it is, I think it would be helpful to have a simple example to understand how `remake` works. Thanks in advance.

---

<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:** [November 11, 2025, 11:55am UTC](https://discourse.julialang.org/t/simulate-modelingtoolkit-system-with-different-parameters/133791/2 "2025-11-11T11:55:16Z")

</div>

`remake` is expecting a symbolic parameter map, so for this case you need to do…

```julia
prob2 = remake(prob; p = [system.value => 5])

```

Also, depending on what you are trying to accomplish, you may find this of interest: [Home · ModelingToolkitInputs.jl](https://bradcarman.github.io/ModelingToolkitInputs.jl/dev/). Note the example shown is for a similar system where the integrated constant is an input which can be changed as discrete input.

---

<div class="post-metadata">

**Author:** ![JaviJR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/javijr/32/218294_2.png) [@JaviJR](https://discourse.julialang.org/u/JaviJR)\
**Post date:** [November 11, 2025, 12:00pm UTC](https://discourse.julialang.org/t/simulate-modelingtoolkit-system-with-different-parameters/133791/3 "2025-11-11T12:00:50Z")

</div>

> [@Brad\_Carman](#):
>
> `prob2 = remake(prob; p = [system.value => 5])`

Oh wow, that really solved it!. Did not know about ’ [ModelingToolkitInputs.jl](https://bradcarman.github.io/ModelingToolkitInputs.jl/dev/#ModelingToolkitInputs.jl)’.

Thank you a lot!

---

<div class="post-metadata">

**Author:** ![JaviJR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/javijr/32/218294_2.png) [@JaviJR](https://discourse.julialang.org/u/JaviJR)\
**Post date:** [November 11, 2025, 12:25pm UTC](https://discourse.julialang.org/t/simulate-modelingtoolkit-system-with-different-parameters/133791/4 "2025-11-11T12:25:25Z")

</div>

Hi again,

It seems I spoke too soon. While I have been able to verify that this method works correctly, I realized that in large systems, this process can take a lot of time. Is there any way to perform this same process more efficiently? (Perhaps passing a symbolic map creates bottlenecks?).

Best regards,

---

<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:** [November 11, 2025, 12:34pm UTC](https://discourse.julialang.org/t/simulate-modelingtoolkit-system-with-different-parameters/133791/5 "2025-11-11T12:34:37Z")

</div>

> [@JaviJR](#):
>
> It seems I spoke too soon. While I have been able to verify that this method works correctly, I realized that in large systems, this process can take a lot of time. Is there any way to perform this same process more efficiently? (Perhaps passing a symbolic map creates bottlenecks?).

Using symbolic maps does symbolic operations each time. It’s more for simple and interactive use, if you want to put it in a loop then you’ll need to make sure you do something a bit more optimized. If you instead use the SymbolicIndexingInterface you can compile and cache that specialized remake. This is discussed in the docs:

> **[Optimizing through an ODE solve and re-creating MTK Problems ·...](https://docs.sciml.ai/ModelingToolkit/stable/examples/remake/)**
>
> Documentation for ModelingToolkit.jl.

---

<div class="post-metadata">

**Author:** ![JaviJR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/javijr/32/218294_2.png) [@JaviJR](https://discourse.julialang.org/u/JaviJR)\
**Post date:** [November 11, 2025, 12:57pm UTC](https://discourse.julialang.org/t/simulate-modelingtoolkit-system-with-different-parameters/133791/6 "2025-11-11T12:57:23Z")

</div>

Hello,

Indeed, after looking at that example I’ve come to the conclusion that using `replace()` can be more efficient because of not using the symbolic map. However, I’m having a hard time seeing how to use that method in a simple example like the one I mentioned earlier.

---

<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:** [November 11, 2025, 1:07pm UTC](https://discourse.julialang.org/t/simulate-modelingtoolkit-system-with-different-parameters/133791/7 "2025-11-11T13:07:23Z")

</div>

I believe the info you need is here (Getting and Setting Parameter Values): [Using the SciML Symbolic Indexing Interface · SymbolicIndexingInterface.jl](https://docs.sciml.ai/SymbolicIndexingInterface/stable/usage/#Parameter-Indexing:-Getting-and-Setting-Parameter-Values)

See the `setp` function in particular.

---

<div class="post-metadata">

**Author:** ![JaviJR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/javijr/32/218294_2.png) [@JaviJR](https://discourse.julialang.org/u/JaviJR)\
**Post date:** [November 11, 2025, 3:51pm UTC](https://discourse.julialang.org/t/simulate-modelingtoolkit-system-with-different-parameters/133791/8 "2025-11-11T15:51:08Z")

</div>

This was the solution I was looking for! Extremely efficient!

Thank you both so much.
