Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/subsystems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function ConstructionBase.setproperties(s::SubsystemParams{T}, patch::NamedTuple
set_param_prop(s, patch; allow_typechange=false)
end
function set_param_prop(s::SubsystemParams{T}, key, val; allow_typechange=false) where {T}
set_param_prop(s, NamedTuple{(key,)}(val); allow_typechange)
set_param_prop(s, NamedTuple{(key,)}((val,)); allow_typechange)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bit is to allow values to be iterators because previously it was trying to splat them and that was erroring

end
function set_param_prop(s::SubsystemParams{T}, patch; allow_typechange=false) where {T}
props = NamedTuple(s)
Expand Down
9 changes: 9 additions & 0 deletions src/symbolic_indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,15 @@ function SymbolicIndexingInterface.parameter_values(p::GraphSystemParameters, i:
p.connection_matrices[i]
end

function SymbolicIndexingInterface.set_parameter!(p::GraphSystemParameters, val, idx::ParamIndex)
(; tup_index, v_index, prop) = idx
(; params_partitioned) = p
params = params_partitioned[tup_index][v_index]
params_new = set_param_prop(params, prop, val; allow_typechange=false)
params_partitioned[tup_index][v_index] = params_new
p
end

function SymbolicIndexingInterface.parameter_symbols(g::PartitionedGraphSystem)
collect(Iterators.flatten((keys(g.param_namemap), keys(g.connection_namemap))))
end
Expand Down
18 changes: 17 additions & 1 deletion test/symbolic_indexing.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
include("particle_osc_example.jl")
using SymbolicIndexingInterface

@testset "Symbolic Indexing of Vectors" begin
@testset "Symbolic Indexing of Vectors of observables" begin
sol = solve_particle_osc(x1=1.0, x2=-1.0)

a = getsym(sol, :particle1₊a)(sol)[end]
ω = getsym(sol, :osc₊ω₀)(sol)[end]
@test getsym(sol, [:osc₊ω₀, :particle1₊a])(sol)[end] == [ω, a]
end

@testset "setp and getp" begin
prob = particle_osc_prob(; x1 = 1.0, x2 = 0.0)

# Test setp works
setp(prob, :particle1₊m)(prob, 2.0)
@test getp(prob, :particle1₊m)(prob) == 2

# Error on type-unstable change
@test_throws ErrorException setp(prob, :particle1₊m)(prob, ones(3))

# Remake
prob = remake(prob, p = [:particle1₊m => 2 + 3im, :particle2₊m => 3 + 2im])
setp(prob, :particle1₊m)(prob, 3 + 3.0im)
@test getp(prob, :particle1₊m)(prob) == 3 + 3im
end