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 units #798

Merged
merged 20 commits into from
Apr 8, 2024
Merged

Handle units #798

merged 20 commits into from
Apr 8, 2024

Conversation

TorkelE
Copy link
Member

@TorkelE TorkelE commented Mar 31, 2024

This updates Catalyst to properly handle units in v14 (when depending on MTK v9).

Currently, Molar units are not supported by dynamic quantities (SymbolicML/DynamicQuantities.jl#127), so I just used m in the test (which is weird, but should work equivalently well until we can replace it with something sensibly-looking).

When I tried

using DynamicQuantities, Unitful

in the main Catalyst.jl source file, things stopped working, so I have currently commented out Unitful. It is possible that we might be able to support it, but I will have to look further at that.

@TorkelE
Copy link
Member Author

TorkelE commented Mar 31, 2024

This PR is based on #784, hence the number if displayed commits.

@isaacsas
Copy link
Member

Look at how ModelingToolkit imports them both. It seems to only import dynamic quantities.

@TorkelE
Copy link
Member Author

TorkelE commented Mar 31, 2024

Will have a look at MTK, that makes sense. Seems like something that should be solvable

@TorkelE
Copy link
Member Author

TorkelE commented Mar 31, 2024

I've added some additional improvements. Have tried some more, and still have not gotten Unitful to work. Hopefully SymbolicML/DynamicQuantities.jl#128 gets merged soon, when it do we will have molar units (M) as well.

@TorkelE
Copy link
Member Author

TorkelE commented Apr 1, 2024

Molar is fixed in DynamicQuantities now. Unfortunately, MTK still do not accept it (SciML/ModelingToolkit.jl#2590).

@TorkelE TorkelE mentioned this pull request Apr 3, 2024
47 tasks
@TorkelE TorkelE force-pushed the handle_units branch 2 times, most recently from f0aa3b3 to a90eda7 Compare April 5, 2024 20:42
@TorkelE TorkelE changed the base branch from master to Catalyst_version_14 April 5, 2024 21:27
Project.toml Show resolved Hide resolved
@@ -302,6 +302,7 @@ let

for repeat in 1:5
sol = solve(sprob, ImplicitEM(); saveat = 1.0, adaptive = false, dt = 0.01, seed = rand(rng, 1:100))
SciMLBase.successful_retcode(sol) || continue
Copy link
Member Author

Choose a reason for hiding this comment

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

Rarely, but it does happen, StochasticDiffEq fails to initiate the problem properly, giving a NaN solution and a failed test. Added this one so we should not have to worry about it.
(I am surprised though that it caused a failure in this run, but not for the last PR, given that new change was made to this file since then)

Copy link
Member

Choose a reason for hiding this comment

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

But shouldn't this be deterministic given we are using StableRNGs with a fixed seed? (i.e. if we pick a seed where it doesn't error then it never should.)

test/miscellaneous_tests/symbolic_stoichiometry.jl Outdated Show resolved Hide resolved
@@ -302,6 +302,7 @@ let

for repeat in 1:5
sol = solve(sprob, ImplicitEM(); saveat = 1.0, adaptive = false, dt = 0.01, seed = rand(rng, 1:100))
SciMLBase.successful_retcode(sol) || continue
Copy link
Member

Choose a reason for hiding this comment

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

But shouldn't this be deterministic given we are using StableRNGs with a fixed seed? (i.e. if we pick a seed where it doesn't error then it never should.)

Comment on lines 114 to 117
sol_base = solve(jprob_base, SSAStepper(); seed, saveat = 1.0)
sol_alt = solve(jprob_alt, SSAStepper(); seed, saveat = 1.0)
sol_base == sol_alt
sol_alt1 = solve(jprob_alt1, SSAStepper(); seed, saveat = 1.0)
sol_alt2 = solve(jprob_alt2, SSAStepper(); seed, saveat = 1.0)
@test_broken sol_base == sol_alt1 == sol_alt2
Copy link
Member

Choose a reason for hiding this comment

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

Why broken?

@TorkelE TorkelE merged commit b6a9a04 into Catalyst_version_14 Apr 8, 2024
3 checks passed
@TorkelE TorkelE deleted the handle_units 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.

2 participants