Skip to content

Commit 19d7ce4

Browse files
chore: validate with complete and split systems
1 parent df7914f commit 19d7ce4

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/parameters.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,21 @@ Change the tunable parameters of a system to a new set of tunables.
156156
The new tunable parameters must be a subset of the current tunables as discovered by [`tunable_parameters`](@ref).
157157
The remaining parameters will be set as constants in the system.
158158
"""
159-
function change_tunables(sys, new_tunables)
159+
function subset_tunables(sys, new_tunables)
160+
if !iscomplete(sys)
161+
throw(ArgumentError("System must be `complete` before changing tunables."))
162+
end
163+
if !is_split(sys)
164+
throw(ArgumentError("Tunable parameters can only be changed for split systems."))
165+
end
166+
160167
cur_tunables = tunable_parameters(sys, parameters(sys))
161168
diff_params = setdiff(cur_tunables, new_tunables)
162169

163170
if !isempty(setdiff(new_tunables, cur_tunables))
164-
throw(ArgumentError("New tunables must be a subset of the current tunables. Found tunable parameters not in the system: $(setdiff(new_tunables, cur_tunables))"))
171+
throw(ArgumentError("""New tunable parameters must be a subset of the current tunable parameters. Found tunable parameters not in the system: $(setdiff(new_tunables, cur_tunables)).
172+
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.
173+
"""))
165174
end
166175
cur_ps = get_ps(sys)
167176
const_ps = toconstant.(diff_params)

test/parameter_dependencies.jl

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

186186
new_tunables = [L, b]
187-
sys2 = ModelingToolkit.change_tunables(sys, new_tunables)
187+
sys2 = ModelingToolkit.subset_tunables(sys, new_tunables)
188188
sys2_tunables = ModelingToolkit.tunable_parameters(sys2, ModelingToolkit.parameters(sys2))
189189
@test length(sys2_tunables) == 2
190190
@test isempty(setdiff(sys2_tunables, new_tunables))
191-
@test_throws ArgumentError ModelingToolkit.change_tunables(sys, [errp])
191+
@test_throws ArgumentError ModelingToolkit.subset_tunables(sys, [errp])
192+
@test_throws ArgumentError ModelingToolkit.subset_tunables(sys, [θ, L])
193+
sys3 = ModelingToolkit.subset_tunables(sys, [])
194+
sys3_tunables = ModelingToolkit.tunable_parameters(sys3, ModelingToolkit.parameters(sys3))
195+
@test length(sys3_tunables) == 0
196+
192197
end
193198

194199
struct CallableFoo

0 commit comments

Comments
 (0)