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

Try to enable SI on 1.11 #1169

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
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
4 changes: 4 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@ GraphMakie = "1ecd5474-83a3-4783-bb4f-06765db800d2"
HomotopyContinuation = "f213a82b-91d6-5c5d-acf7-10f1c761b327"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
NetworkLayout = "46757867-2c16-5918-afeb-47bfcb05e46a"
StructuralIdentifiability = "220ca800-aa68-49bb-acd8-6037fa93a544"


[extensions]
CatalystBifurcationKitExtension = "BifurcationKit"
CatalystCairoMakieExtension = "CairoMakie"
CatalystGraphMakieExtension = ["GraphMakie", "NetworkLayout", "Makie"]
CatalystHomotopyContinuationExtension = "HomotopyContinuation"
CatalystStructuralIdentifiabilityExtension = "StructuralIdentifiability"

[compat]
BifurcationKit = "0.4.4"
Expand All @@ -66,6 +69,7 @@ Requires = "1.0"
RuntimeGeneratedFunctions = "0.5.12"
SciMLBase = "2.57.2"
Setfield = "1"
StructuralIdentifiability = "0.5.11"
SymbolicUtils = "3.8.1"
Symbolics = "6.22"
Unitful = "1.12.4"
Expand Down
2 changes: 2 additions & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
SteadyStateDiffEq = "9672c7b4-1e72-59bd-8a11-6ac3964bc41f"
StochasticDiffEq = "789caeaf-c7a9-5a7d-9973-96adeb23e2a0"
StructuralIdentifiability = "220ca800-aa68-49bb-acd8-6037fa93a544"
Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7"

[compat]
Expand Down Expand Up @@ -87,4 +88,5 @@ SpecialFunctions = "2.4"
StaticArrays = "1.9"
SteadyStateDiffEq = "2.2"
StochasticDiffEq = "6.65"
StructuralIdentifiability = "0.5.11"
Symbolics = "6.22"
2 changes: 1 addition & 1 deletion docs/pages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pages = Any[
"inverse_problems/petab_ode_param_fitting.md",
"inverse_problems/optimization_ode_param_fitting.md",
"inverse_problems/behaviour_optimisation.md",
# "inverse_problems/structural_identifiability.md",
"inverse_problems/structural_identifiability.md",
"inverse_problems/global_sensitivity_analysis.md",
"Examples" => Any[
"inverse_problems/examples/ode_fitting_oscillation.md"
Expand Down
4 changes: 4 additions & 0 deletions ext/CatalystStructuralIdentifiabilityExtension.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ using Catalyst
import DataStructures.OrderedDict
import StructuralIdentifiability as SI

@static if VERSION < v"1.11.3"
@warn "CatalystStructuralIdentifiabilityExtension.jl is only tested with Julia v1.11.2 or later due to https://github.com/SciML/StructuralIdentifiability.jl/issues/360. Its use is not recommended on earlier Julia versions."
end

# Creates and exports make_si_ode function.
include("CatalystStructuralIdentifiabilityExtension/structural_identifiability_extension.jl")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function SI.assess_identifiability(rs::ReactionSystem, args...;
funcs_to_check = make_ftc(funcs_to_check, conseqs, vars)

# Computes identifiability and converts it to a easy to read form.
out = SI.assess_identifiability(osys, args...; measured_quantities,
out = SI.assess_identifiability(osys::ODESystem, args...; measured_quantities,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the bit that solves it. What actually goes on is a royal mystery, but there is some discussion here: https://discourse.julialang.org/t/how-to-debug-an-error-in-type-inference/126122/8 and here: SciML/StructuralIdentifiability.jl#360

funcs_to_check, kwargs...)
return make_output(out, funcs_to_check, consconsts)
end
Expand Down
2 changes: 1 addition & 1 deletion test/extensions/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
OrdinaryDiffEqDefault = "50262376-6c5a-4cf5-baba-aaf4f84d72d7"
OrdinaryDiffEqTsit5 = "b1df2697-797e-41e3-8120-5422d3b24e4a"
SteadyStateDiffEq = "9672c7b4-1e72-59bd-8a11-6ac3964bc41f"
# StructuralIdentifiability = "220ca800-aa68-49bb-acd8-6037fa93a544"
StructuralIdentifiability = "220ca800-aa68-49bb-acd8-6037fa93a544"
24 changes: 12 additions & 12 deletions test/reactionsystem_core/custom_crn_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ let
ps = rnd_ps(custom_function_network_1, rng; factor)
t = rand(rng)
@test f_eval(custom_function_network_1, u0, ps, t) ≈ f_eval(custom_function_network_2, u0, ps, t)
@test jac_eval(custom_function_network_1, u0, ps, t) ≈ jac_eval(custom_function_network_2, u0, ps, t)
@test_broken jac_eval(custom_function_network_1, u0, ps, t) ≈ jac_eval(custom_function_network_2, u0, ps, t) # Weird error dur to some SciML update. Reported in https://github.com/SciML/ModelingToolkit.jl/issues/3447.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is actually done in #1192 (but this PR is based off that one).

@test g_eval(custom_function_network_1, u0, ps, t) ≈ g_eval(custom_function_network_2, u0, ps, t)
end
end
Expand Down Expand Up @@ -101,20 +101,20 @@ end
# Tests `ReactionSystem`s.
let
@species x(t) y(t)
@parameters k v n
@parameters k v n
rs1 = @reaction_network rs begin
mm(x, v, k), 0 --> x
mmr(x, v, k), 0 --> x
hill(x, v, k, n), 0 --> x
hillr(x, v, k, n), 0 --> x
hillar(x, y, v, k, n), 0 --> x
hillar(x, y, v, k, n), 0 --> x
end
rs2 = @reaction_network rs begin
v * x / (x + k), 0 --> x
v * k / (x + k), 0 --> x
v * (x^n) / (x^n + k^n), 0 --> x
v * (k^n) / (x^n + k^n), 0 --> x
v * (x^n) / (x^n + y^n + k^n), 0 --> x
v * (x^n) / (x^n + y^n + k^n), 0 --> x
end

@test Catalyst.expand_registered_functions(rs1) == rs2
Expand All @@ -123,14 +123,14 @@ end
# Tests `Reaction`s.
let
@species x(t) y(t)
@parameters k v n
@parameters k v n

r1 = @reaction mm(x, v, k), 0 --> x
r2 = @reaction mmr(x, v, k), 0 --> x
r3 = @reaction hill(x, v, k, n), 0 --> x
r4 = @reaction hillr(x, v, k, n), 0 --> x
r5 = @reaction hillar(x, y, v, k, n), 0 --> x + y

@test isequal(Catalyst.expand_registered_functions(r1).rate, v * x / (x + k))
@test isequal(Catalyst.expand_registered_functions(r2).rate, v * k / (x + k))
@test isequal(Catalyst.expand_registered_functions(r3).rate, v * (x^n) / (x^n + k^n))
Expand All @@ -143,14 +143,14 @@ end
let
@parameters T
@variables X(T) Y(T)
@parameters K V N
@parameters K V N

eq1 = 0 ~ mm(X, V, K)
eq2 = 0 ~ mmr(X, V, K)
eq3 = 0 ~ hill(X, V, K, N)
eq4 = 0 ~ hillr(X, V, K, N)
eq5 = 0 ~ hillar(X, Y, V, K, N)

@test isequal(Catalyst.expand_registered_functions(eq1), 0 ~ V * X / (X + K))
@test isequal(Catalyst.expand_registered_functions(eq2), 0 ~ V * K / (X + K))
@test isequal(Catalyst.expand_registered_functions(eq3), 0 ~ V * (X^N) / (X^N + K^N))
Expand All @@ -166,7 +166,7 @@ let
@parameters v K
eqs = [
Reaction(mm(X,v,K), [], [X]),
mm(V,v,K) ~ V + 1
mm(V,v,K) ~ V + 1
]
@named rs = ReactionSystem(eqs, t)

Expand Down Expand Up @@ -211,7 +211,7 @@ let
(v * (X^n) / (X^n + K^n) > 1000.0) => [X ~ v * (K^n) / (X^n + K^n) + 2]
]
continuous_events = ModelingToolkit.SymbolicContinuousCallback.(continuous_events)
discrete_events = ModelingToolkit.SymbolicDiscreteCallback.(discrete_events)
discrete_events = ModelingToolkit.SymbolicDiscreteCallback.(discrete_events)
@test isequal(only(Catalyst.get_rxs(rs_expanded)).rate, v0 + v * (X^n) / (X^n + Y^n + K^n))
@test isequal(get_continuous_events(rs_expanded), continuous_events)
@test isequal(get_discrete_events(rs_expanded), discrete_events)
Expand Down
4 changes: 1 addition & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ end
@time @safetestset "Graph visualization" begin include("extensions/graphmakie.jl") end
@time @safetestset "BifurcationKit Extension" begin include("extensions/bifurcation_kit.jl") end
@time @safetestset "HomotopyContinuation Extension" begin include("extensions/homotopy_continuation.jl") end

# BROKEN
# @time @safetestset "Structural Identifiability Extension" begin include("extensions/structural_identifiability.jl") end
@time @safetestset "Structural Identifiability Extension" begin include("extensions/structural_identifiability.jl") end

# Tests stability computation (but requires the HomotopyContinuation extension).
#@time @safetestset "Steady State Stability Computations" begin include("extensions/stability_computation.jl") end
Expand Down