Skip to content

Commit 8a9b4e4

Browse files
authored
Merge pull request #1131 from vyudu/dsl-no-infer-docs
`@require_declaration` docs edits
2 parents 1ca054c + 79dfbe4 commit 8a9b4e4

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

docs/src/model_creation/dsl_advanced.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -272,23 +272,24 @@ sol = solve(oprob)
272272
plot(sol)
273273
```
274274

275-
### [Turning off species, parameter, and variable inferring](@id dsl_advanced_options_require_dec)
276-
In some cases it may be desirable for Catalyst to not infer species and parameters from the DSL, as in the case of reaction networks with very many variables, or as a sanity check that variable names are written correctly. To turn off inferring, simply add the `@require_declaration` macro to one of the lines of the `@reaction_network` declaration. Having this macro means that every single variable, species, or parameter will have to be explicitly declared using the `@variable`, `@species`, or `@parameter` macro. In the case that the DSL parser encounters an undeclared symbolic, it will error with an `UndeclaredSymbolicError` and print the reaction or equation that the undeclared symbolic was found in.
275+
### [Turning off species, parameter, and variable inference](@id dsl_advanced_options_require_dec)
276+
In some cases it may be desirable for Catalyst to not infer species and parameters from the DSL, as in the case of reaction networks with very many variables, or as a sanity check that variable names are written correctly. To turn off inference, simply use the `@require_declaration` option when using the `@reaction_network` DSL. This will require every single variable, species, or parameter used within the DSL to be explicitly declared using the `@variable`, `@species`, or `@parameter` options. In the case that the DSL parser encounters an undeclared symbolic, it will error with an `UndeclaredSymbolicError` and print the reaction or equation that the undeclared symbolic was found in.
277277

278-
```@example dsl_advanced_no_infer
278+
```julia
279279
using Catalyst
280-
# The following case will throw an UndeclaredSymbolicError.
281-
try @macroexpand @reaction_network begin
280+
rn = @reaction_network begin
282281
@require_declaration
283282
(k1, k2), A <--> B
284283
end
285-
catch e
286-
println(e.msg)
287-
end
288284
```
289-
In order to avoid an error in this case all the relevant species and parameters will have to be declared.
285+
Running the code above will yield the following error:
290286
```
287+
LoadError: UndeclaredSymbolicError: Unrecognized variables A detected in reaction expression: "((k1, k2), A <--> B)". Since the flag @require_declaration is declared, all species must be explicitly declared with the @species macro.
288+
```
289+
In order to avoid the error in this case all the relevant species and parameters will have to be declared.
290+
```@example dsl_advanced_require_dec
291291
# The following case will not error.
292+
using Catalyst
292293
t = default_t()
293294
rn = @reaction_network begin
294295
@require_declaration
@@ -299,11 +300,11 @@ end
299300
```
300301

301302
The following cases in which the DSL would normally infer variables will all throw errors if `@require_declaration` is set and the variables are not explicitly declared.
302-
- Inferring a species in a reaction, as in the example above
303-
- Inferring a parameter in a reaction rate expression, as in the reaction line `k*n, A --> B`
304-
- Inferring a parameter in the stoichiometry of a species, as in the reaction line `k, n*A --> B`
305-
- Inferring a differential variable on the LHS of a coupled differential equation, as in `A` in `@equations D(A) ~ A^2`
306-
- Inferring an [observable](@ref dsl_advanced_options_observables) that is declared using `@observables`
303+
- Occurrence of an undeclared species in a reaction, as in the example above.
304+
- Occurrence of an undeclared parameter in a reaction rate expression, as in the reaction line `k*n, A --> B`.
305+
- Occurrence of an undeclared parameter in the stoichiometry of a species, as in the reaction line `k, n*A --> B`.
306+
- Occurrence of an undeclared differential variable on the LHS of a coupled differential equation, as in `A` in `@equations D(A) ~ A^2`.
307+
- Occurrence of an undeclared [observable](@ref dsl_advanced_options_observables) in an `@observables` expression, such as `@observables X1 ~ A + B`.
307308

308309
## [Naming reaction networks](@id dsl_advanced_options_naming)
309310
Each reaction network model has a name. It can be accessed using the `nameof` function. By default, some generic name is used:

0 commit comments

Comments
 (0)