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

[Wip] Refactor "src/dsl.jl" file #985

Open
wants to merge 40 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
efd44be
save progress
TorkelE May 27, 2024
d2985c0
save progress
TorkelE May 28, 2024
b06068f
save progress
TorkelE May 28, 2024
5cc8f41
save progress
TorkelE May 28, 2024
15273f1
save progress
TorkelE May 28, 2024
b105b3e
add additional tests
TorkelE May 28, 2024
1324428
up
TorkelE May 28, 2024
71c9b5c
fix
TorkelE Jun 2, 2024
9ab9290
Merge branch 'master' into dsl_file_improvements
TorkelE Jun 11, 2024
d45f0a7
merge fixes
TorkelE Jun 11, 2024
b6ba044
Merge branch 'master' into src___refactoring___dsl_file
TorkelE Jul 13, 2024
cdac225
merge fixes
TorkelE Jul 13, 2024
ea9aae3
up
TorkelE Jul 13, 2024
7084133
test fixes
TorkelE Jul 14, 2024
a6b4c3a
format
TorkelE Jul 14, 2024
160668f
up
TorkelE Jul 14, 2024
9c265ee
observables fix
TorkelE Jul 14, 2024
34fc2c0
spatial transport reaction dsl fix
TorkelE Jul 14, 2024
e9fa7ba
Merge branch 'master' into src___refactoring___dsl_file
TorkelE Jul 16, 2024
37ea1d9
iv is now a parmaeter
TorkelE Jul 16, 2024
87464f7
Add tests for various erroneous declarations
TorkelE Jul 17, 2024
8156eca
update old @variable test
TorkelE Jul 17, 2024
fba3f5e
Merge branch 'master' into src___refactoring___dsl_file
TorkelE Jan 16, 2025
50f8f82
save progress
TorkelE Jan 16, 2025
4e720ee
save progress
TorkelE Jan 16, 2025
a1e967a
save progress
TorkelE Jan 17, 2025
fadeb67
Merge branch 'master' into src___refactoring___dsl_file
TorkelE Jan 18, 2025
b235784
save progress
TorkelE Jan 18, 2025
18fcbf1
prepare formatting round
TorkelE Jan 18, 2025
9230667
up
TorkelE Jan 18, 2025
78ca087
multiple fixes
TorkelE Jan 18, 2025
9d62c28
docstring fix
TorkelE Jan 18, 2025
9a928fe
fixes
TorkelE Jan 18, 2025
53a6254
up
TorkelE Jan 18, 2025
27f7add
fix function expansion of differentials
TorkelE Jan 18, 2025
99e54d2
spelling fix
TorkelE Jan 18, 2025
7ec7383
better handling of forbidden symbols and more tests
TorkelE Jan 19, 2025
5f35480
improve option error handling, more tests
TorkelE Jan 19, 2025
292da20
minor upodates after read through
TorkelE Jan 19, 2025
2902101
doc fix, combinatorial_ratelaw error handling
TorkelE Jan 20, 2025
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
1 change: 1 addition & 0 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ of all options currently available.
- [`continuous_events`](@ref constraint_equations_events): Allows the creation of continuous events.
- [`discrete_events`](@ref constraint_equations_events): Allows the creation of discrete events.
- [`combinatoric_ratelaws`](@ref faq_combinatoric_ratelaws): Takes a single option (`true` or `false`), which sets whether to use combinatorial rate laws.
- [`require_declaration`](@ref dsl_advanced_options_require_dec): Turns off all inference of parameters, species, variables, the default differential, and observables (requiring these to be explicitly declared using e.g. `@species`).

## [ModelingToolkit and Catalyst accessor functions](@id api_accessor_functions)
A [`ReactionSystem`](@ref) is an instance of a
Expand Down
29 changes: 28 additions & 1 deletion docs/src/model_creation/dsl_advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ ModelingToolkit.getdescription(two_state_system.kA)
```

### [Designating constant-valued/fixed species parameters](@id dsl_advanced_options_constant_species)

Catalyst enables the designation of parameters as `constantspecies`. These parameters can be used as species in reactions, however, their values are not changed by the reaction and remain constant throughout the simulation (unless changed by e.g. the [occurrence of an event](@ref constraint_equations_events). Practically, this is done by setting the parameter's `isconstantspecies` metadata to `true`. Here, we create a simple reaction where the species `X` is converted to `Xᴾ` at rate `k`. By designating `X` as a constant species parameter, we ensure that its quantity is unchanged by the occurrence of the reaction.
```@example dsl_advanced_constant_species
using Catalyst # hide
Expand Down Expand Up @@ -501,6 +500,34 @@ Catalyst.getdescription(rx)

A list of all available reaction metadata can be found [in the api](@ref api_rx_metadata).

## [Declaring individual reaction using the `@reaction` macro](@id dsl_advanced_options_reaction_macro)
Catalyst exports a macro `@reaction` which can be used to generate a singular [`Reaction`](@ref) object of the same type which is stored within the [`ReactionSystem`](@ref) structure (which in turn can be generated by `@reaction_network `). In the following example, we create a simple [SIR model](@ref basic_CRN_library_sir). Next, we instead create its individual reaction components using the `@reaction` macro. Finally, we confirm that these are identical to those stored in the initial model (using the [`reactions`](@ref) function).
```@example dsl_advanced_reaction_macro
using Catalyst # hide
sir_model = @reaction_network begin
α, S + I --> 2I
β, I --> R
end
infection_rx = @reaction α, S + I --> 2I
recovery_rx = @reaction β, I --> R
issetequal(reactions(sir_model), [infection_rx, recovery_rx])
```

Here, the `@reaction` macro is followed by a single line consisting of three parts:
- A rate (at which the reaction occurs).
- Any number of substrates (which are consumed by the reaction).
- Any number of products (which are produced by the reaction).
The rules of writing and interpreting this line are [identical to those for `@reaction_network`](@ref dsl_description_reactions) (however, bi-directional reactions are not permitted).

Generally, the `@reaction` macro provides a more concise notation to the [`Reaction`](@ref) constructor. One of its primary uses is for [creating models programmatically](@ref programmatic_CRN_construction). When doing so, it can often be useful to use [*interpolation*](@ref dsl_advanced_options_symbolics_and_DSL_interpolation) of symbolic variables declared previously:
```@example dsl_advanced_reaction_macro
t = default_t()
@parameters k b
@species A(t)
ex = k*A^2 + t
rx = @reaction b*$ex*$A, $A --> C
```

Copy link
Member Author

Choose a reason for hiding this comment

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

Previously there was actually no section on this in the DSL. The updated @reaction docstring now references this one.

## [Working with symbolic variables and the DSL](@id dsl_advanced_options_symbolics_and_DSL)
We have previously described how Catalyst represents its models symbolically (enabling e.g. symbolic differentiation of expressions stored in models). While Catalyst utilises this for many internal operation, these symbolic representations can also be accessed and harnessed by the user. Primarily, doing so is much easier during programmatic (as opposed to DSL-based) modelling. Indeed, the section on [programmatic modelling](@ref programmatic_CRN_construction) goes into more details about symbolic representation in models, and how these can be used. It is, however, also ways to utilise these methods during DSL-based modelling. Below we briefly describe two methods for doing so.

Expand Down
5 changes: 0 additions & 5 deletions src/Catalyst.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,6 @@ const CONSERVED_CONSTANT_SYMBOL = :Γ
const forbidden_symbols_skip = Set([:ℯ, :pi, , :t, :∅])
const forbidden_symbols_error = union(Set([:im, :nothing, CONSERVED_CONSTANT_SYMBOL]),
forbidden_symbols_skip)
const forbidden_variables_error = let
fvars = copy(forbidden_symbols_error)
delete!(fvars, :t)
fvars
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.

Per discussion, this one is not actually used.


### Package Main ###

Expand Down
2 changes: 1 addition & 1 deletion src/chemistry_functionality.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function make_compound(expr)
# Cannot extract directly using e.g. "getfield.(composition, :reactant)" because then
# we get something like :([:C, :O]), rather than :([C, O]).
composition = Catalyst.recursive_find_reactants!(expr.args[3], 1,
Vector{ReactantStruct}(undef, 0))
Vector{DSLReactant}(undef, 0))
Copy link
Member Author

Choose a reason for hiding this comment

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

Better name so that it is not confused with other structures (thanks for the name suggestion)

components = :([]) # Becomes something like :([C, O]).
coefficients = :([]) # Becomes something like :([1, 2]).
for comp in composition
Expand Down
Loading
Loading