Skip to content

Commit 445bac1

Browse files
committed
fix jacobian (?)
1 parent cb158c9 commit 445bac1

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/core_systems/jacobian.jl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import ForwardDiff
66
jacobian(ds::CoreDynamicalSystem)
77
88
Construct the Jacobian rule for the dynamical system `ds`.
9-
If the system already has a Jacobian rule constructed via ModelingToolkit it returns this,
9+
If the system already has a Jacobian rule constructed via ModelingToolkit.jl it returns this,
1010
otherwise it constructs the Jacobian rule with automatic differentiation using module
1111
[`ForwardDiff`](https://github.com/JuliaDiff/ForwardDiff.jl).
1212
@@ -21,6 +21,17 @@ at the state `u`, parameters `p` and time `t` and save the result in `J0`.
2121
"""
2222
function jacobian(ds::CoreDynamicalSystem{IIP}) where {IIP}
2323
if ds isa ContinuousTimeDynamicalSystem
24+
# TODO: This is the correct API way to obtain the Jacobian,
25+
# however it relies on MTK dependency, so we can't do it.
26+
# if has_referrenced_model(ds)
27+
# model = referrenced_sciml_model(ds)
28+
# Joop, Jiip = generate_jacobian(model; expression = Val{false})
29+
# if IIP
30+
# jac = Jiip
31+
# else
32+
# jac = Joop
33+
# end
34+
# end
2435
prob = referrenced_sciml_prob(ds)
2536
if prob.f isa SciMLBase.AbstractDiffEqFunction && !isnothing(prob.f.jac)
2637
jac = prob.f.jac

test/jacobian.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,9 @@ end
4242
sys = structural_simplify(sys)
4343

4444
prob = ODEProblem(sys, [1.0, 1.0], (0.0, 1.0); jac=true)
45-
ode = CoupledODEs(prob)
45+
ds = CoupledODEs(prob)
4646

47-
jac = jacobian(ode)
48-
@test jac.jac_oop isa RuntimeGeneratedFunction
47+
jac = jacobian(ds)
4948
@test jac([1.0, 1.0], [], 0.0) == [3 0;0 -3]
5049

5150
@testset "CoupledSDEs" begin

0 commit comments

Comments
 (0)