-
-
Notifications
You must be signed in to change notification settings - Fork 223
fix: create and solve initialization system in linearization_function #2676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ChrisRackauckas
merged 14 commits into
SciML:master
from
AayushSabharwal:as/linearization-initialization
May 26, 2024
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
81c68fa
fix: create and solve initialization problem in linearization_function
AayushSabharwal 9a98ffa
fix: fix namespacing of array variables using `unknowns`
AayushSabharwal 97d6b27
fix: respect `u0map` in `InitializationProblem`
AayushSabharwal 4a20e32
fix: runtime dispatch in `replace!`
AayushSabharwal c162e00
test: mark mtkparameters tests as no longer broken
AayushSabharwal 2c17819
test: fix serialization test observed function expr
AayushSabharwal c48891c
feat: add utility function for obtaining defaults and guesses
AayushSabharwal 9f531c4
feat: add `SII.observed` support for `AbstractSystem`
AayushSabharwal da7c9fc
refactor: make dependent and numeric portions singletons
AayushSabharwal 6633065
fix: properly initialize initialization problem in linearization_func…
AayushSabharwal 0ec683a
fix: improve performance of linearization
AayushSabharwal 556067c
test: mark linearization dummy derivatives test as broken
AayushSabharwal d6befb7
build: upper bound SymbolicUtils to <1.6
AayushSabharwal d7fa540
test: mark some inversemodel tests as broken
AayushSabharwal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
## Test that dummy_derivatives can be set to zero | ||
# The call to Link(; m = 0.2, l = 10, I = 1, g = -9.807) hangs forever on Julia v1.6 | ||
using LinearAlgebra | ||
using ModelingToolkit | ||
using ModelingToolkitStandardLibrary | ||
using ModelingToolkitStandardLibrary.Blocks | ||
using ModelingToolkitStandardLibrary.Mechanical.MultiBody2D | ||
using ModelingToolkitStandardLibrary.Mechanical.TranslationalPosition | ||
using Test | ||
|
||
using ControlSystemsMTK | ||
using ControlSystemsMTK.ControlSystemsBase: sminreal, minreal, poles | ||
connect = ModelingToolkit.connect | ||
|
||
@parameters t | ||
D = Differential(t) | ||
|
||
@named link1 = Link(; m = 0.2, l = 10, I = 1, g = -9.807) | ||
@named cart = TranslationalPosition.Mass(; m = 1, s = 0) | ||
@named fixed = Fixed() | ||
@named force = Force(use_support = false) | ||
|
||
eqs = [connect(link1.TX1, cart.flange) | ||
connect(cart.flange, force.flange) | ||
connect(link1.TY1, fixed.flange)] | ||
|
||
@named model = ODESystem(eqs, t, [], []; systems = [link1, cart, force, fixed]) | ||
def = ModelingToolkit.defaults(model) | ||
def[cart.s] = 10 | ||
def[cart.v] = 0 | ||
def[link1.A] = -pi / 2 | ||
def[link1.dA] = 0 | ||
lin_outputs = [cart.s, cart.v, link1.A, link1.dA] | ||
lin_inputs = [force.f.u] | ||
|
||
@test_broken begin | ||
@info "named_ss" | ||
G = named_ss(model, lin_inputs, lin_outputs, allow_symbolic = true, op = def, | ||
allow_input_derivatives = true, zero_dummy_der = true) | ||
G = sminreal(G) | ||
@info "minreal" | ||
G = minreal(G) | ||
@info "poles" | ||
ps = poles(G) | ||
|
||
@test minimum(abs, ps) < 1e-6 | ||
@test minimum(abs, complex(0, 1.3777260367206716) .- ps) < 1e-10 | ||
|
||
lsys, syss = linearize(model, lin_inputs, lin_outputs, allow_symbolic = true, op = def, | ||
allow_input_derivatives = true, zero_dummy_der = true) | ||
lsyss, sysss = ModelingToolkit.linearize_symbolic(model, lin_inputs, lin_outputs; | ||
allow_input_derivatives = true) | ||
|
||
dummyder = setdiff(unknowns(sysss), unknowns(model)) | ||
def = merge(ModelingToolkit.guesses(model), def, Dict(x => 0.0 for x in dummyder)) | ||
def[link1.fy1] = -def[link1.g] * def[link1.m] | ||
|
||
@test substitute(lsyss.A, def) ≈ lsys.A | ||
# We cannot pivot symbolically, so the part where a linear solve is required | ||
# is not reliable. | ||
@test substitute(lsyss.B, def)[1:6, 1] ≈ lsys.B[1:6, 1] | ||
@test substitute(lsyss.C, def) ≈ lsys.C | ||
@test substitute(lsyss.D, def) ≈ lsys.D | ||
end |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.