Skip to content

Commit

Permalink
Use FiniteHorizonGramians.jl (#268)
Browse files Browse the repository at this point in the history
* Use FiniteHorizonGramians.jl

* Working version with FiniteHorizonGramians.jl

* Fix tests

* Fix a typo that I introdced in my last committ

* Ran Hodgkin-Huxley benchmarks

* Add compat for FillArrays

* Make the quadrature-based discretize slower but more robust

* JuliaFormatter.jl

* Run Hodgkin-Huxley once more

* Remove order 5 from the HH benchmark as it breaks

* Add tstops to make HH benchmark better

* HH again

* Fix some things and improve tests

* Add a test for `_discretize_sqrt_with_quadraturetrick` even though it's unused

* Actually test the quadraturetrick
  • Loading branch information
nathanaelbosch authored Jan 4, 2024
1 parent ee6cc36 commit 32bb627
Show file tree
Hide file tree
Showing 22 changed files with 1,973 additions and 2,094 deletions.
4 changes: 4 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ DiffEqDevTools = "f3b72e0c-5b89-59e1-b016-84e28bfd966d"
ExponentialUtilities = "d4d017d3-3776-5f7e-afef-a10c40355c18"
FastBroadcast = "7034ab61-46d4-4ed7-9d0f-46aef9175898"
FastGaussQuadrature = "442a2c76-b920-505d-bb47-c5924d526838"
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
FiniteHorizonGramians = "b59a298d-d283-4a37-9369-85a9f9a111a5"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
FunctionWrappersWrappers = "77dc65aa-8811-40c2-897b-53d922fa7daf"
GaussianDistributions = "43dcc890-d446-5863-8d1a-14597580bb8d"
Expand Down Expand Up @@ -45,6 +47,8 @@ DiffEqDevTools = "2"
ExponentialUtilities = "1"
FastBroadcast = "0.2"
FastGaussQuadrature = "0.5, 1"
FillArrays = "1.9"
FiniteHorizonGramians = "0.1"
ForwardDiff = "0.10"
FunctionWrappersWrappers = "0.1.3"
GaussianDistributions = "0.5"
Expand Down
17 changes: 10 additions & 7 deletions benchmarks/hodgkinhuxley.jmd
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ Plots.theme(
αh(V, VT) = 0.128 * exp(-(V - VT - 17) / 18)
βh(V, VT) = 4 / (1 + exp(-(V - VT - 40) / 5))

Inj(t) = (5 <= t <= 40) ? 500one(t) : zero(t)
const current_tspan = (5, 40)
Inj(t) = (current_tspan[1] <= t <= current_tspan[2]) ? 500one(t) : zero(t)

function f(du, u, p, t)
@unpack gNa, gK, ENa, EK, area, C, Eleak, VT, gleak = p
Expand Down Expand Up @@ -88,14 +89,13 @@ _setups = [
"EK0(3)" => Dict(:alg=>EK0(order=3, smooth=DENSE))
"EK1(2)" => Dict(:alg=>EK1(order=2, smooth=DENSE))
"EK1(3)" => Dict(:alg=>EK1(order=3, smooth=DENSE))
"EK1(5)" => Dict(:alg=>EK1(order=5, smooth=DENSE))
"RosenbrockExpEK1(2)" => Dict(:alg=>RosenbrockExpEK(order=2, smooth=DENSE))
"RosenbrockExpEK1(3)" => Dict(:alg=>RosenbrockExpEK(order=3, smooth=DENSE))
"RosenbrockExpEK1(5)" => Dict(:alg=>RosenbrockExpEK(order=5, smooth=DENSE))
]

labels = first.(_setups)
setups = last.(_setups)
colors = [1 1 2 2 2 3 3]
colors = [1 1 2 2 3 3]

abstols = 1.0 ./ 10.0 .^ (6:10)
reltols = 1.0 ./ 10.0 .^ (3:7)
Expand All @@ -108,6 +108,7 @@ wp = WorkPrecisionSet(
save_everystep = SAVE_EVERYSTEP,
maxiters = Int(1e7),
numruns = 5,
tstops = current_tspan,
)

plot(wp, title="Adaptive steps - no smoothing", color=colors)
Expand All @@ -127,6 +128,7 @@ ref_wp_final = WorkPrecisionSet(
dense = false,
save_everystep = false,
maxiters = Int(1e7),
tstops = current_tspan,
)
ref_wp_dense = WorkPrecisionSet(
prob, abstols ./ 1000, reltols ./ 1000, ref_setups;
Expand All @@ -135,6 +137,7 @@ ref_wp_dense = WorkPrecisionSet(
dense = true,
save_everystep = true,
maxiters = Int(1e7),
tstops = current_tspan,
)

plot!(ref_wp_final, x=:final, color=:gray, alpha=0.7, linestyle=:dash)
Expand All @@ -150,14 +153,13 @@ _setups = [
"EK0(3)" => Dict(:alg=>EK0(order=3, smooth=DENSE))
"EK1(2)" => Dict(:alg=>EK1(order=2, smooth=DENSE))
"EK1(3)" => Dict(:alg=>EK1(order=3, smooth=DENSE))
"EK1(5)" => Dict(:alg=>EK1(order=5, smooth=DENSE))
"RosenbrockExpEK1(2)" => Dict(:alg=>RosenbrockExpEK(order=2, smooth=DENSE))
"RosenbrockExpEK1(3)" => Dict(:alg=>RosenbrockExpEK(order=3, smooth=DENSE))
"RosenbrockExpEK1(5)" => Dict(:alg=>RosenbrockExpEK(order=5, smooth=DENSE))
]

labels = first.(_setups)
setups = last.(_setups)
colors = [1 1 2 2 2 3 3]
colors = [1 1 2 2 3 3]

abstols = 1.0 ./ 10.0 .^ (6:10)
reltols = 1.0 ./ 10.0 .^ (3:7)
Expand All @@ -170,6 +172,7 @@ wp = WorkPrecisionSet(
save_everystep = SAVE_EVERYSTEP,
maxiters = Int(1e7),
numruns = 5,
tstops = current_tspan,
)

plot(wp, title="Adaptive steps - with smoothing", color=colors)
Expand Down
834 changes: 417 additions & 417 deletions docs/src/benchmarks/figures/hodgkinhuxley_2_1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
452 changes: 220 additions & 232 deletions docs/src/benchmarks/figures/hodgkinhuxley_3_1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
454 changes: 222 additions & 232 deletions docs/src/benchmarks/figures/hodgkinhuxley_4_1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
654 changes: 236 additions & 418 deletions docs/src/benchmarks/figures/hodgkinhuxley_5_1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
482 changes: 231 additions & 251 deletions docs/src/benchmarks/figures/hodgkinhuxley_6_1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
318 changes: 158 additions & 160 deletions docs/src/benchmarks/figures/hodgkinhuxley_7_1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
300 changes: 150 additions & 150 deletions docs/src/benchmarks/figures/hodgkinhuxley_8_1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 32bb627

Please sign in to comment.