Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
e2eb777
refactor: remove deprecated items
AayushSabharwal May 21, 2025
5c3468c
refactor: remove `Substitutions`
AayushSabharwal May 21, 2025
37ebc88
docs: add docstrings for `has_observed_with_lhs`, `has_parameter_depe…
AayushSabharwal May 21, 2025
9d5529e
refactor: remove old field `get_` and `has_` functions
AayushSabharwal May 21, 2025
101097e
fix: remove jac/tgrad cache-related code
AayushSabharwal May 21, 2025
dd71755
refactor: remove outdated functions
AayushSabharwal May 21, 2025
91822bc
refactor: remove `varmap_to_vars` and related outdated infrastructure
AayushSabharwal May 21, 2025
a5080e1
refactor: use `add_toterms` instead of `varmap_with_toterm`
AayushSabharwal May 21, 2025
75b5457
feat: evaluate in `better_varmap_to_vars`, allow passing `use_union`
AayushSabharwal May 21, 2025
71361dd
refactor: rename `better_varmap_to_vars` to `varmap_to_vars`
AayushSabharwal May 21, 2025
c07372d
fix: use new `varmap_to_vars`
AayushSabharwal May 21, 2025
c5aa808
refactor: remove `get_u0_p`, modernize `get_u0` and add `get_p`
AayushSabharwal May 21, 2025
b7bb11f
test: use new `get_u0`
AayushSabharwal May 21, 2025
35a06a4
refactor: remove dead code
AayushSabharwal May 21, 2025
b70714d
docs: add docstrings for `detime_dvs` and `retime_dvs`
AayushSabharwal May 21, 2025
569a457
fix: re-add `invalidate_cache!` for use with new metadata
AayushSabharwal May 22, 2025
be8f6c2
fix: re-add `normalize_to_differential`
AayushSabharwal May 22, 2025
8757381
docs: add docstring for `reordered_matrix`
AayushSabharwal May 22, 2025
a4c5586
refactor: remove dead code in structural transformation utils
AayushSabharwal May 22, 2025
690e5c7
fix: fix construction of `lb` and `ub` in `OptimizationProblem`
AayushSabharwal May 22, 2025
e9a8dfb
test: do not test system subtype warning in `independent_variables`
AayushSabharwal May 22, 2025
f473a43
fix: fix `buffer_eltype` implementation in `varmap_to_vars`
AayushSabharwal May 26, 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
11 changes: 6 additions & 5 deletions ext/MTKBifurcationKitExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,12 @@ function BifurcationKit.BifurcationProblem(nsys::System,
J = jac ? ofun.jac : nothing

# Converts the input state guess.
u0_bif_vals = ModelingToolkit.varmap_to_vars(u0_bif,
unknowns(nsys);
defaults = ModelingToolkit.get_defaults(nsys))
p_vals = ModelingToolkit.varmap_to_vars(
ps, parameters(nsys); defaults = ModelingToolkit.get_defaults(nsys))
u0_bif = ModelingToolkit.to_varmap(u0_bif, unknowns(nsys))
u0_buf = merge(ModelingToolkit.get_defaults(nsys), u0_bif)
u0_bif_vals = ModelingToolkit.varmap_to_vars(u0_bif, unknowns(nsys))
ps = ModelingToolkit.to_varmap(ps, parameters(nsys))
ps = merge(ModelingToolkit.get_defaults(nsys), ps)
p_vals = ModelingToolkit.varmap_to_vars(ps, parameters(nsys))

# Computes bifurcation parameter and the plotting function.
bif_idx = findfirst(isequal(bif_par), parameters(nsys))
Expand Down
33 changes: 11 additions & 22 deletions src/ModelingToolkit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,6 @@ $(TYPEDEF)
TODO
"""
abstract type AbstractSystem end
abstract type AbstractTimeDependentSystem <: AbstractSystem end
abstract type AbstractTimeIndependentSystem <: AbstractSystem end
abstract type AbstractMultivariateSystem <: AbstractSystem end
abstract type AbstractOptimizationSystem <: AbstractTimeIndependentSystem end

function independent_variable end

Expand All @@ -150,7 +146,6 @@ include("independent_variables.jl")
include("constants.jl")

include("utils.jl")
include("domains.jl")

include("systems/index_cache.jl")
include("systems/parameter_buffer.jl")
Expand Down Expand Up @@ -265,25 +260,19 @@ PrecompileTools.@compile_workload begin
end
end

export AbstractTimeDependentSystem,
AbstractTimeIndependentSystem,
AbstractMultivariateSystem

export ODEFunction, ODEFunctionExpr, ODEProblemExpr, convert_system_indepvar,
export ODEFunction, convert_system_indepvar,
System, OptimizationSystem, JumpSystem, SDESystem, NonlinearSystem
export DAEFunctionExpr, DAEProblemExpr
export SDEFunction, SDEFunctionExpr, SDEProblemExpr
export SDEFunction
export SystemStructure
export DiscreteProblem, DiscreteFunction, DiscreteFunctionExpr
export ImplicitDiscreteProblem, ImplicitDiscreteFunction,
ImplicitDiscreteFunctionExpr
export DiscreteProblem, DiscreteFunction
export ImplicitDiscreteProblem, ImplicitDiscreteFunction
export ODEProblem, SDEProblem
export NonlinearFunction, NonlinearFunctionExpr
export NonlinearProblem, NonlinearProblemExpr
export IntervalNonlinearFunction, IntervalNonlinearFunctionExpr
export IntervalNonlinearProblem, IntervalNonlinearProblemExpr
export OptimizationProblem, OptimizationProblemExpr, constraints
export SteadyStateProblem, SteadyStateProblemExpr
export NonlinearFunction
export NonlinearProblem
export IntervalNonlinearFunction
export IntervalNonlinearProblem
export OptimizationProblem, constraints
export SteadyStateProblem
export JumpProblem
export alias_elimination, flatten
export connect, domain_connect, @connector, Connection, AnalysisPoint, Flow, Stream,
Expand Down Expand Up @@ -315,7 +304,7 @@ export calculate_jacobian, generate_jacobian, generate_rhs, generate_custom_func
export calculate_control_jacobian, generate_control_jacobian
export calculate_tgrad, generate_tgrad
export generate_cost, calculate_cost_gradient, generate_cost_gradient
export calculate_factorized_W, generate_factorized_W
export calculate_factorized_W
export calculate_cost_hessian, generate_cost_hessian
export calculate_massmatrix, generate_diffusion_function
export stochastic_integral_transform
Expand Down
17 changes: 0 additions & 17 deletions src/domains.jl

This file was deleted.

11 changes: 8 additions & 3 deletions src/problems/optimizationproblem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,14 @@ function SciMLBase.OptimizationProblem{iip}(
end

ps = parameters(sys)
defs = merge(defaults(sys), to_varmap(op, dvs))
lb = varmap_to_vars(dvs .=> lb, dvs; defaults = defs, tofloat = false)
ub = varmap_to_vars(dvs .=> ub, dvs; defaults = defs, tofloat = false)
defs = defaults(sys)
op = to_varmap(op, dvs)
lbmap = merge(op, AnyDict(dvs .=> lb))
_, _ = build_operating_point!(sys, lbmap, Dict(), Dict(), defs, dvs, ps)
lb = varmap_to_vars(lbmap, dvs; tofloat = false)
ubmap = merge(op, AnyDict(dvs .=> ub))
_, _ = build_operating_point!(sys, ubmap, Dict(), Dict(), defs, dvs, ps)
ub = varmap_to_vars(ubmap, dvs; tofloat = false)

if !isnothing(lb) && all(lb .== -Inf) && !isnothing(ub) && all(ub .== Inf)
lb = nothing
Expand Down
3 changes: 1 addition & 2 deletions src/structural_transformation/StructuralTransformations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ using ModelingToolkit: System, AbstractSystem, var_from_nested_derivative, Diffe
has_tearing_state, defaults, InvalidSystemException,
ExtraEquationsSystemException,
ExtraVariablesSystemException,
vars!,
vars!, invalidate_cache!,
IncrementalCycleTracker, add_edge_checked!, topological_sort,
invalidate_cache!, Substitutions, get_or_construct_tearing_state,
filter_kwargs, lower_varname_with_unit,
lower_shift_varname_with_unit, setio, SparseMatrixCLIL,
get_fullvars, has_equations, observed,
Expand Down
1 change: 0 additions & 1 deletion src/structural_transformation/symbolics_tearing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,6 @@ function update_simplified_system!(

@set! sys.eqs = neweqs
@set! sys.observed = obs
# @set! sys.substitutions = Substitutions(subeqs, deps)

# Only makes sense for time-dependent
if ModelingToolkit.has_schedule(sys)
Expand Down
27 changes: 8 additions & 19 deletions src/structural_transformation/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,14 @@ function but_ordered_incidence(ts::TearingState, varmask = highest_order_variabl
mm[[var_eq_matching[v] for v in vordering if var_eq_matching[v] isa Int], vordering], bb
end

# debugging use
function reordered_matrix(sys, torn_matching)
"""
$(TYPEDSIGNATURES)

Given a system `sys` and torn variable-equation matching `torn_matching`, return the sparse
incidence matrix of the system with SCCs grouped together, and each SCC sorted to contain
the analytically solved equations/variables before the unsolved ones.
"""
function reordered_matrix(sys::System, torn_matching)
s = TearingState(sys)
complete!(s.structure)
@unpack graph = s.structure
Expand Down Expand Up @@ -432,23 +438,6 @@ function torn_system_jacobian_sparsity(sys)
return sparse(I, J, true, neqs, neqs)
end

###
### Nonlinear equation(s) solving
###

@noinline function nlsolve_failure(rc)
error("The nonlinear solver failed with the return code $rc.")
end

function numerical_nlsolve(f, u0, p)
prob = NonlinearProblem{false}(f, u0, p)
sol = solve(prob, SimpleNewtonRaphson())
rc = sol.retcode
(rc == ReturnCode.Success) || nlsolve_failure(rc)
# TODO: robust initial guess, better debugging info, and residual check
sol.u
end

###
### Misc
###
Expand Down
Loading
Loading