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

Handle different parameters types #797

Merged
merged 20 commits into from
Apr 5, 2024

Conversation

TorkelE
Copy link
Member

@TorkelE TorkelE commented Mar 30, 2024

This PR make modifications so that non-default parameter types can be handled. It also adds tests for this in the context of Catalyst.

Currently, this only partially works for LatticeReactionSystems, i.e. ODEProblems cannot be created if a non-default parameter type has been given. However, the internals or LatticeReactionSystems have been remade a bit in a follow-up PR, so I don't want to touch that to risk messing up the merging of that. Once that is merged, I will ensure this is supported in the spatial case as well.

@TorkelE
Copy link
Member Author

TorkelE commented Mar 30, 2024

This PR is based on #784 (hence the number pf shown commits)

@TorkelE
Copy link
Member Author

TorkelE commented Mar 31, 2024

A fix to the symbolic stoichiometries tests (also expanding them a bit with things that are possible now) was added here as well. It basically utilises the ability to designated types for parameters to reenable these tests.

@TorkelE
Copy link
Member Author

TorkelE commented Mar 31, 2024

I have reverted the changes for spatial reaction systems, removing the changes to accommodate non-default types. The tests are still there and marked as broken. I will then introduce support for this once the internal remake has been merged.

@TorkelE TorkelE force-pushed the handle_different_paraemter_types branch from 9d793ac to 37215a9 Compare April 3, 2024 03:38
@TorkelE TorkelE mentioned this pull request Apr 3, 2024
47 tasks
Copy link
Member

@isaacsas isaacsas left a comment

Choose a reason for hiding this comment

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

I haven’t reviewed this yet, but please keep in-place test functions in-place. Generally everything related to ODEs and SDEs should be in place unless we are using static arrays, and we definitely shouldn’t be converting to non-recommended workflows (i.el changing existing in place tests to out of place).

Copy link
Member

@isaacsas isaacsas left a comment

Choose a reason for hiding this comment

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

Should we add some tests for having array parameters too? We need to consider them (and array variables), but we can also leave that for later PRs if you prefer.

src/reactionsystem.jl Show resolved Hide resolved
src/spatial_reaction_systems/spatial_reactions.jl Outdated Show resolved Hide resolved
src/spatial_reaction_systems/spatial_reactions.jl Outdated Show resolved Hide resolved
test/dsl/dsl_options.jl Show resolved Hide resolved
test/miscellaneous_tests/symbolic_stoichiometry.jl Outdated Show resolved Hide resolved
test/miscellaneous_tests/symbolic_stoichiometry.jl Outdated Show resolved Hide resolved
test/miscellaneous_tests/symbolic_stoichiometry.jl Outdated Show resolved Hide resolved
catalyst_jsys = convert(JumpSystem, rs)
unknownoid = Dict(unknown => i for (i, unknown) in enumerate(unknowns(catalyst_jsys)))
catalyst_vrj = ModelingToolkit.assemble_vrj(catalyst_jsys, equations(catalyst_jsys)[i], unknownoid)
@test isapprox(catalyst_vrj.rate(u0_2, ps_2, τ), jumps[i].rate(u0_2, ps_2, τ))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
@test isapprox(catalyst_vrj.rate(u0_2, ps_2, τ), jumps[i].rate(u0_2, ps_2, τ))
@test isapprox(catalyst_vrj.rate(u0_2, ps_2, τ), jumps[i].rate(u0_2, ps_2, τ))

Is ps_2 really the right input for the Catalyst generated function? Doesn't it need something that has been processed into an MTKParameter object now?

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried to generate MTKParameters and give as input, but that generates some internal error saying that MTKParameters cannot be used as input. You probably know more about these VariableRateJump than me though, so if you have some suggested update I am happy to make it.

Copy link
Member

Choose a reason for hiding this comment

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

Should we modify this test then to actually generate the JumpProblem over an ODEProblem and pull the ps and functions to test out of it? Then we don't have to deal with building the functions via the internal MTK functions anymore.

Copy link
Member

Choose a reason for hiding this comment

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

If you want to leave that for a future PR that is fine -- I'll make note of it in the TODO.

test/miscellaneous_tests/symbolic_stoichiometry.jl Outdated Show resolved Hide resolved
TorkelE and others added 13 commits April 3, 2024 14:17
Co-authored-by: Sam Isaacson <isaacsas@users.noreply.github.com>
…atalyst.jl into handle_different_paraemter_types
Co-authored-by: Sam Isaacson <isaacsas@users.noreply.github.com>
Co-authored-by: Sam Isaacson <isaacsas@users.noreply.github.com>
Co-authored-by: Sam Isaacson <isaacsas@users.noreply.github.com>
…atalyst.jl into handle_different_paraemter_types
Copy link
Member

@isaacsas isaacsas left a comment

Choose a reason for hiding this comment

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

Feel free to merge once you've addressed my comments. (i.e. I don't need to look at it further unless you have questions for me.)

src/reactionsystem.jl Show resolved Hide resolved
test/miscellaneous_tests/symbolic_stoichiometry.jl Outdated Show resolved Hide resolved
catalyst_jsys = convert(JumpSystem, rs)
unknownoid = Dict(unknown => i for (i, unknown) in enumerate(unknowns(catalyst_jsys)))
catalyst_vrj = ModelingToolkit.assemble_vrj(catalyst_jsys, equations(catalyst_jsys)[i], unknownoid)
@test isapprox(catalyst_vrj.rate(u0_2, ps_2, τ), jumps[i].rate(u0_2, ps_2, τ))
Copy link
Member

Choose a reason for hiding this comment

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

Should we modify this test then to actually generate the JumpProblem over an ODEProblem and pull the ps and functions to test out of it? Then we don't have to deal with building the functions via the internal MTK functions anymore.

catalyst_jsys = convert(JumpSystem, rs)
unknownoid = Dict(unknown => i for (i, unknown) in enumerate(unknowns(catalyst_jsys)))
catalyst_vrj = ModelingToolkit.assemble_vrj(catalyst_jsys, equations(catalyst_jsys)[i], unknownoid)
@test isapprox(catalyst_vrj.rate(u0_2, ps_2, τ), jumps[i].rate(u0_2, ps_2, τ))
Copy link
Member

Choose a reason for hiding this comment

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

If you want to leave that for a future PR that is fine -- I'll make note of it in the TODO.

test/miscellaneous_tests/symbolic_stoichiometry.jl Outdated Show resolved Hide resolved
@TorkelE TorkelE merged commit 18f5d3a into Catalyst_version_14 Apr 5, 2024
6 checks passed
@TorkelE TorkelE deleted the handle_different_paraemter_types branch June 8, 2024 18:27
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.

3 participants