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

Update Reaction constructor #856

Merged
merged 5 commits into from
Jun 5, 2024
Merged

Conversation

TorkelE
Copy link
Member

@TorkelE TorkelE commented May 21, 2024

  • Permits [] and nothing to be used interchangeably (previously there were some cases which unintentionally would not work).
  • Ensures that the Reaction structure is concretely typed.

src/reaction.jl Outdated
"""The rate function (excluding mass action terms)."""
rate::Any
"""Reaction substrates."""
substrates::Vector
substrates::Vector{BasicSymbolic{Real}}
Copy link
Member Author

Choose a reason for hiding this comment

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

We should know that species are BasicSymbolic{Real}.

Technically, someone could declare a constantspecies parameter, and set it to a non-default type (i.e. BasicSymbolic{Int64}). However, we probably should not permit this?

Copy link
Member

Choose a reason for hiding this comment

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

There was a reason this was left untyped I believe but I'm not remembering it. The case you mention is one possibility for someone making a jump model though. If we want to type these maybe they should be Any. Let me think about it a bit.

Copy link
Member

Choose a reason for hiding this comment

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

Let me know when you've reverted this and updated the PR as we discussed.

Copy link
Member Author

Choose a reason for hiding this comment

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

The decision is to change to

substrates::Vector{S}
products::Vector{R}

for now

(sorry, was a bit unsure what the final conclusion was if there was one, more than happy to make this switch)

Copy link
Member

Choose a reason for hiding this comment

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

No, it was to just leave them untyped as they currently are.

@@ -85,9 +92,6 @@ function get_netstoich(subs, prods, sstoich, pstoich)
[el for el in nsdict if !_iszero(el[2])]
end

# Get the net stoichiometries' type.
netstoich_stoichtype(::Vector{Pair{S, T}}) where {S, T} = T
Copy link
Member Author

Choose a reason for hiding this comment

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

No longer needed as we need to check both S and T (as S might now need to be converted from Num to BasicSymbolic{Real}.

@isaacsas
Copy link
Member

isaacsas commented May 21, 2024

Actually, now I think this is a bad idea. Someone has made the confusing choice to define get_variables(e::Equation) completely inconsistently with get_variables! in Symbolics, where the latter gets dependent variables (so rhs only).

I think if we want such a function for Reactions we should come up with a different name to avoid confusion (since we already have get_variables! defined on it).

@TorkelE
Copy link
Member Author

TorkelE commented May 21, 2024

Do you mean this definition:

# determine which unknowns a reaction depends on
function MT.get_variables!(deps::Set, rx::Reaction, variables)
    (rx.rate isa Symbolic) && get_variables!(deps, rx.rate, variables)
    for s in rx.substrates
        # parametric stoichiometry means may have a parameter as a substrate
        any(isequal(s), variables) && push!(deps, s)
    end
    deps
end

and this PR #855?

To do get_variables(x) where you return a vector of all the symbolic variables in x (whatever it is) is (to me) the established way to use the function, so get_variables(rx::Reaction) makes sense. Practically, I think we should have some function that does this, as it seems like something genuinely useful.

@TorkelE TorkelE force-pushed the update_possible_Reaction_inputs branch 2 times, most recently from 9d960ca to 9844a99 Compare May 21, 2024 17:22
isempty(vec) && (return type[])
type[value(v) for v in vec]
end

Copy link
Member Author

Choose a reason for hiding this comment

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

helper function to ensure something have the best type

@TorkelE TorkelE force-pushed the update_possible_Reaction_inputs branch from 97b6842 to 82c7730 Compare June 4, 2024 20:11
@TorkelE TorkelE merged commit 50acd56 into master Jun 5, 2024
6 of 7 checks passed
@TorkelE TorkelE deleted the update_possible_Reaction_inputs branch June 5, 2024 01:10
@TorkelE TorkelE restored the update_possible_Reaction_inputs branch June 5, 2024 01:52
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.

None yet

2 participants