Skip to content

Commit 2cdb3b6

Browse files
committed
Add additional check for assignment instead of equation
1 parent cb8aebb commit 2cdb3b6

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
ProcessBasedModelling.jl follows semver 2.0.
44
Changelog is kept with respect to v1 release.
55

6+
## 1.7
7+
8+
- Added an additional check when constructing the raw equations that catches
9+
errors of typing `x = expression` instead of `x ~ expression` as a process.
10+
611
## 1.6
712

813
- Added an additional step when constructing the raw equation vector to be passed into an MTK model. In this step it is also checked that the RHS for all equations is an `Expression`. Sometimes it is easy to get confused and mess up and make it be an `Equation` (i.e., assigning the LHS-variable twice). This now will give an informative error.

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ProcessBasedModelling"
22
uuid = "ca969041-2cf3-4b10-bc21-86f4417093eb"
33
authors = ["Datseris <[email protected]>"]
4-
version = "1.6.0"
4+
version = "1.7.0"
55

66
[deps]
77
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"

src/make.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ During construction, the following automations improve user experience:
1414
a [`ParameterProcess`](@ref) is created for said variable(s) and a warning is thrown.
1515
- Else, an informative error is thrown.
1616
- An error is also thrown if any variable has two or more processes assigned to it.
17+
- An error is thrown if any of the given processes are not actually processes,
18+
but rather expressions without a LHF-variable.
1719
1820
`processes` is a `Vector` whose elements can be:
1921
@@ -161,7 +163,9 @@ end
161163

162164
function check_rhs_validity(processes)
163165
for p in processes
164-
if rhs(p) isa Equation
166+
if !(typeof(p) <: Union{Process, Equation})
167+
throw(ArgumentError("Process $(p) is not actually a process!"))
168+
elseif rhs(p) isa Equation
165169
lvar = lhs_variable(p)
166170
throw(ArgumentError("Process assigned to variable $(lvar) is ill defined. "*
167171
"The RHS is an `<: Equation` type but it shouldn't be."

test/runtests.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,16 @@ end
238238
@test_throws ["an `<: Equation` type"] processes_to_mtkeqs(procs)
239239
end
240240

241+
@testset "not actual process" begin
242+
@variables z(t) = 0.0
243+
@variables x(t) = 0.0
244+
procs = [
245+
ExpRelaxation(x, x^2, 1.0),
246+
-x, # is an equation, not a process!
247+
]
248+
@test_throws ["not actually"] processes_to_mtkeqs(procs)
249+
end
250+
241251
@testset "registering default" begin
242252
using .TestDefault
243253
@variables z(t) = 0.1

0 commit comments

Comments
 (0)