SciML / SciML/ModelingToolkitStandardLibrary.jl
State space may not contain all states when there are zeros in the matrix entries
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 171
- Forks
- 49
- Avg merge
- 15h 50m
- Merged PRs (30d)
- 10
Description
In the following example, there are three inputs passed along to io_preprocessing which in turn calls structural_simplify. All three inputs are present as states in the system upon calling io_preprocessing. Before markio! is called within structural_simplify, one of the inputs, (model₊input₊u(t))[2] has been removed from fullvars, leading to the error below:
ERROR: Some specified inputs were not found in system. The following Dict indicates the found variables
Dict{Num, Bool}(
u(t) => 1,
(model₊input₊u(t))[2] => 0,
d(t) => 1
)
Stacktrace:
[1] error(::String, ::Dict{Num, Bool})
@ Base ./error.jl:44
[2] markio!(state::TearingState{ODESystem}, inputs::Vector{Num}, outputs::Vector{Any}; check::Bool)
using ModelingToolkitStandardLibrary.Blocks
A,C = [randn(2,2) for i in 1:2]
B = [1.0 0; 0 0]
@named model = Blocks.StateSpace(A,B,C)
@named integrator = Blocks.StateSpace( [-0.001;;], [1.0;;], [1.0;;], [0.0;;])
ins = collect(model.input.u)
disturbed_input = ins[1]
@named dist_integ = ModelingToolkit.DisturbanceModel(disturbed_input, integrator)
function add_input_disturbance_(sys, dist::DisturbanceModel, inputs)
t = ModelingToolkit.get_iv(sys)
@variables d(t)=0 [disturbance = true]
@variables u(t)=0 [input = true] # Potential new system input
dsys = ModelingToolkit.get_disturbance_system(dist)
all_inputs = inputs
all_inputs = Base.setindex(all_inputs, u, findfirst(isequal(dist.input), inputs)) # The input where the disturbance acts is no longer an input, the new
eqs = [dsys.input.u[1] ~ d
dist.input ~ u + dsys.output.u[1]]
augmented_sys = ODESystem(eqs, t, systems = [sys, dsys], name = gensym(:outer))
ModelingToolkit.generate_control_function(augmented_sys, all_inputs, [d])
end
add_input_disturbance_(model, dist_integ, ins)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the supplied reproduction and trace io_preprocessing into structural_simplify, especially the markio! call and the handling of fullvars. Verify that inputs corresponding to zero entries in the matrix remain available after preprocessing, and rerun the example to confirm all three inputs are found without the reported error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100