Skip to content

Commit 8fe2894

Browse files
Merge pull request #3922 from DhairyaLGandhi/dg/oop_set
Copy parameter object before setting in `subset_tunables`
2 parents 712d094 + ac5ec9c commit 8fe2894

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/parameters.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ function subset_tunables(sys, new_tunables)
172172
Note that array parameters can only be set as tunable or non-tunable, not partially tunable. They should be specified in the un-scalarized form.
173173
"""))
174174
end
175-
cur_ps = get_ps(sys)
175+
cur_ps = copy(get_ps(sys))
176176
const_ps = toconstant.(diff_params)
177177

178178
for (idx, p) in enumerate(cur_ps)

test/parameter_dependencies.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ end
184184
sys = mtkcompile(pendulum_sys)
185185

186186
new_tunables = [L, b]
187+
old_tunables = copy(ModelingToolkit.tunable_parameters(sys, ModelingToolkit.parameters(sys)))
187188
sys2 = ModelingToolkit.subset_tunables(sys, new_tunables)
188189
sys2_tunables = ModelingToolkit.tunable_parameters(sys2, ModelingToolkit.parameters(sys2))
189190
@test length(sys2_tunables) == 2
@@ -198,6 +199,8 @@ end
198199
@test_throws ArgumentError ModelingToolkit.subset_tunables(sys_incomplete, new_tunables)
199200
sys_nonsplit = mtkcompile(pendulum_sys; split = false)
200201
@test_throws ArgumentError ModelingToolkit.subset_tunables(sys_nonsplit, new_tunables)
202+
203+
@test length(ModelingToolkit.tunable_parameters(sys, ModelingToolkit.parameters(sys))) == length(old_tunables)
201204
end
202205

203206
struct CallableFoo

0 commit comments

Comments
 (0)