Skip to content

Commit

Permalink
Merge pull request #2218 from SciML/myb/vis
Browse files Browse the repository at this point in the history
Make introspecting `dummy_derivative` easier
  • Loading branch information
YingboMa authored Aug 1, 2023
2 parents 4aa29a0 + fd58156 commit e1c34ec
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ function tear_graph_modia(structure::SystemStructure, isder::F = nothing,
var_eq_matching = complete(var_eq_matching,
max(length(var_eq_matching),
maximum(x -> x isa Int ? x : 0, var_eq_matching)))
full_var_eq_matching = copy(var_eq_matching)
var_sccs::Vector{Union{Vector{Int}, Int}} = find_var_sccs(graph, var_eq_matching)
vargraph = DiCMOBiGraph{true}(graph)
ict = IncrementalCycleTracker(vargraph; dir = :in)
Expand Down Expand Up @@ -110,6 +111,5 @@ function tear_graph_modia(structure::SystemStructure, isder::F = nothing,
empty!(ieqs)
empty!(filtered_vars)
end

return var_eq_matching
return var_eq_matching, full_var_eq_matching
end
15 changes: 10 additions & 5 deletions src/structural_transformation/partial_state_selection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,15 @@ function partial_state_selection_graph!(structure::SystemStructure, var_eq_match
end

function dummy_derivative_graph!(state::TransformationState, jac = nothing;
state_priority = nothing, kwargs...)
state_priority = nothing, log = Val(false), kwargs...)
state.structure.solvable_graph === nothing && find_solvables!(state; kwargs...)
complete!(state.structure)
var_eq_matching = complete(pantelides!(state))
dummy_derivative_graph!(state.structure, var_eq_matching, jac, state_priority)
dummy_derivative_graph!(state.structure, var_eq_matching, jac, state_priority, log)
end

function dummy_derivative_graph!(structure::SystemStructure, var_eq_matching, jac,
state_priority)
state_priority, ::Val{log} = Val(false)) where {log}
@unpack eq_to_diff, var_to_diff, graph = structure
diff_to_eq = invview(eq_to_diff)
diff_to_var = invview(var_to_diff)
Expand Down Expand Up @@ -338,7 +338,7 @@ function dummy_derivative_graph!(structure::SystemStructure, var_eq_matching, ja
end
end

var_eq_matching = tear_graph_modia(structure, isdiffed,
var_eq_matching, full_var_eq_matching = tear_graph_modia(structure, isdiffed,
Union{Unassigned, SelectedState};
varfilter = can_eliminate)
for v in eachindex(var_eq_matching)
Expand All @@ -348,5 +348,10 @@ function dummy_derivative_graph!(structure::SystemStructure, var_eq_matching, ja
var_eq_matching[v] = SelectedState()
end

return var_eq_matching
if log
candidates = can_eliminate.(1:ndsts(graph))
return var_eq_matching, full_var_eq_matching, candidates
else
return var_eq_matching
end
end
2 changes: 1 addition & 1 deletion src/structural_transformation/symbolics_tearing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ function tearing(state::TearingState; kwargs...)
@unpack graph = state.structure
algvars = BitSet(findall(v -> isalgvar(state.structure, v), 1:ndsts(graph)))
aeqs = algeqs(state.structure)
var_eq_matching′ = tear_graph_modia(state.structure;
var_eq_matching′, = tear_graph_modia(state.structure;
varfilter = var -> var in algvars,
eqfilter = eq -> eq in aeqs)
var_eq_matching = Matching{Union{Unassigned, SelectedState}}(var_eq_matching′)
Expand Down
2 changes: 1 addition & 1 deletion test/ccompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ p = rand(1)
_t = rand()
f(du, u, p, _t)
f2(du2, u, p, _t)
@test du == du2
@test du du2
2 changes: 1 addition & 1 deletion test/structural_transformation/tearing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ prob.f(du, u, pr, tt)
# test the initial guess is respected
@named sys = ODESystem(eqs, t, defaults = Dict(z => Inf))
infprob = ODAEProblem(structural_simplify(sys), [x => 1.0], (0, 1.0), [p => 0.2])
@test_throws DomainError infprob.f(du, u, pr, tt)
@test_throws Any infprob.f(du, u, pr, tt)

sol1 = solve(prob, Tsit5())
sol2 = solve(ODEProblem{false}((u, p, t) -> [-asin(u[1] - pr * t)],
Expand Down

0 comments on commit e1c34ec

Please sign in to comment.