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

Enable functional/time dependent parameters #1191

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

TorkelE
Copy link
Member

@TorkelE TorkelE commented Mar 7, 2025

Adds docs and tests. Also modifies the main code to enable these to be used within Catalyst.

Example:

using Catalyst, DataInterpolations, OrdinaryDiffEqDefault, Plots

# Create input function/data
tend = 120.0
ts = collect(0.0:1.0:tend)
light = sin.(ts/6) .+ 1
light = [max(0.0, l - rand()) for l in light]
interpolated_light = LinearInterpolation(light, ts)
plot(interpolated_light)

image

# Create model
t = default_t()
in_type = typeof(interpolated_light)
@parameters kA kD (light_in::in_type)(..)
@species Pₐ(t) Pᵢ(t)
rxs = [
    Reaction(kA*light_in(t), [Pᵢ], [Pₐ]),
    Reaction(kD, [Pₐ], [Pᵢ])
]
@named rs = ReactionSystem(rxs, t)
rs = complete(rs)

# Simulate the model.
u0 = [Pᵢ => 1.0, Pₐ => 0.0]
ps = [kA => 1.5, kD => 1.0, light_in => interpolated_light]
oprob = ODEProblem(rs, u0, tend, ps)
sol = solve(oprob)
plot(sol)

image

@TorkelE TorkelE changed the title [WIP] Enable functional/time depe3ndent parameters [WIP] Enable functional/time dependent parameters Mar 9, 2025
@TorkelE TorkelE changed the title [WIP] Enable functional/time dependent parameters Enable functional/time dependent parameters Mar 9, 2025
@@ -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 Author

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).

@TorkelE
Copy link
Member Author

TorkelE commented Mar 9, 2025

Builds on the change in #1192, however, but otherwise this is now ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant