Skip to content
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

feat: add analysis points #3285

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
ccc2e42
feat: add analysis points
AayushSabharwal Dec 19, 2024
2d55c45
test: test analysis points
AayushSabharwal Dec 19, 2024
eb6b8ff
refactor: format Project.toml
AayushSabharwal Dec 24, 2024
667b6ed
feat: allow accessing `AnalysisPoint` via `getproperty` syntax
AayushSabharwal Dec 29, 2024
0be1eb3
test: add tests from MTKStdlib
AayushSabharwal Dec 29, 2024
a22a32a
feat: export `AnalysisPoint`-related tools
AayushSabharwal Dec 29, 2024
3662ab0
test: add downstream analysis points tests
AayushSabharwal Dec 29, 2024
3a08c0a
feat: handle array variables as inputs/outputs of `linearization_func…
AayushSabharwal Jan 2, 2025
ee54d56
fix: fix array variable handling in `get_analysis_variable`
AayushSabharwal Jan 2, 2025
540e1a7
fix: fix naming of new variable in `ComplementarySensitivityTransform`
AayushSabharwal Jan 2, 2025
a8093fb
fix: handle `loop_openings`, `system_modifier` kwargs in `get_*` line…
AayushSabharwal Jan 2, 2025
c79f6e7
fix: fix handling of `loop_openings` in `linearization_function`
AayushSabharwal Jan 2, 2025
c420c90
test: fix analysis point tests
AayushSabharwal Jan 2, 2025
976f9ef
test: fix and port over remaining analysis point downstream tests
AayushSabharwal Jan 2, 2025
11b34d0
docs: add and update docstrings for analysis points and transformations
AayushSabharwal Jan 2, 2025
229dd3d
fixup! feat: handle array variables as inputs/outputs of `linearizati…
AayushSabharwal Jan 3, 2025
7f42ef0
refactor: use version of Stdlib which disables old `AnalysisPoint`
AayushSabharwal Jan 3, 2025
f7da682
fixup! docs: add and update docstrings for analysis points and transf…
AayushSabharwal Jan 3, 2025
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
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ MTKBifurcationKitExt = "BifurcationKit"
MTKChainRulesCoreExt = "ChainRulesCore"
MTKDeepDiffsExt = "DeepDiffs"
MTKHomotopyContinuationExt = "HomotopyContinuation"
MTKLabelledArraysExt = "LabelledArrays"
MTKInfiniteOptExt = "InfiniteOpt"
MTKLabelledArraysExt = "LabelledArrays"

[compat]
AbstractTrees = "0.3, 0.4"
Expand Down Expand Up @@ -117,6 +117,7 @@ Latexify = "0.11, 0.12, 0.13, 0.14, 0.15, 0.16"
Libdl = "1"
LinearAlgebra = "1"
MLStyle = "0.4.17"
ModelingToolkitStandardLibrary = "2.19"
NaNMath = "0.3, 1"
NonlinearSolve = "4.3"
OffsetArrays = "1"
Expand Down
8 changes: 7 additions & 1 deletion src/ModelingToolkit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ include("systems/index_cache.jl")
include("systems/parameter_buffer.jl")
include("systems/abstractsystem.jl")
include("systems/model_parsing.jl")
include("systems/analysis_points.jl")
include("systems/connectors.jl")
include("systems/imperative_affect.jl")
include("systems/callbacks.jl")
Expand Down Expand Up @@ -238,7 +239,8 @@ export SteadyStateProblem, SteadyStateProblemExpr
export JumpProblem
export NonlinearSystem, OptimizationSystem, ConstraintsSystem
export alias_elimination, flatten
export connect, domain_connect, @connector, Connection, Flow, Stream, instream
export connect, domain_connect, @connector, Connection, AnalysisPoint, Flow, Stream,
instream
export initial_state, transition, activeState, entry, ticksInState, timeInState
export @component, @mtkmodel, @mtkbuild
export isinput, isoutput, getbounds, hasbounds, getguess, hasguess, isdisturbance,
Expand Down Expand Up @@ -291,4 +293,8 @@ export MTKParameters, reorder_dimension_by_tunables!, reorder_dimension_by_tunab

export HomotopyContinuationProblem

export AnalysisPoint, Break, PerturbOutput, SampleInput, SensitivityTransform,
ComplementarySensitivityTransform, LoopTransferTransform, apply_transformation,
get_sensitivity_function, get_comp_sensitivity_function, get_looptransfer_function,
get_sensitivity, get_comp_sensitivity, get_looptransfer, open_loop
end # module
14 changes: 14 additions & 0 deletions src/systems/abstractsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,14 @@ function getvar(sys::AbstractSystem, name::Symbol; namespace = !iscomplete(sys))
end
end

if has_eqs(sys)
for eq in get_eqs(sys)
if eq.lhs isa AnalysisPoint && nameof(eq.rhs) == name
return namespace ? renamespace(sys, eq.rhs) : eq.rhs
end
end
end

throw(ArgumentError("System $(nameof(sys)): variable $name does not exist"))
end

Expand Down Expand Up @@ -2366,6 +2374,12 @@ function linearization_function(sys::AbstractSystem, inputs,
op = Dict(op)
inputs isa AbstractVector || (inputs = [inputs])
outputs isa AbstractVector || (outputs = [outputs])
inputs = mapreduce(vcat, inputs; init = []) do var
symbolic_type(var) == ArraySymbolic() ? collect(var) : [var]
end
outputs = mapreduce(vcat, outputs; init = []) do var
symbolic_type(var) == ArraySymbolic() ? collect(var) : [var]
end
ssys, diff_idxs, alge_idxs, input_idxs = io_preprocessing(sys, inputs, outputs;
simplify,
kwargs...)
Expand Down
Loading
Loading