Skip to content

Commit 08f70b2

Browse files
committed
local update with M units (fails with MTK)
1 parent 2e66d1d commit 08f70b2

File tree

2 files changed

+45
-45
lines changed

2 files changed

+45
-45
lines changed

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ BifurcationKit = "0.3"
3939
DataStructures = "0.18"
4040
DiffEqBase = "6.83.0"
4141
DocStringExtensions = "0.8, 0.9"
42+
DynamicQuantities = "0.13.2"
4243
Graphs = "1.4"
4344
HomotopyContinuation = "2.9"
4445
JumpProcesses = "9.3.2"

test/miscellaneous_tests/units.jl

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ using ModelingToolkit: get_iv, get_unit, validate, ValidationError
88
### Basic Tests ###
99

1010
# Checks that units work with programmatic model creation.
11-
# μM and M units currently do not work, so am using other units in the meantime.
1211
let
1312
# Creates a `ReactionSystem` programmatically, while designating units.
1413
@variables t [unit=u"s"]
15-
@species A(t) [unit=u"m"] B(t) [unit=u"m"] C(t) [unit=u"m"]
16-
@parameters k1 [unit=u"m/s"] k2 [unit=u"s"^(-1)] k3 [unit=u"m*s"^(-1)]
14+
@species A(t) [unit=u"μM"] B(t) [unit=u"μM"] C(t) [unit=u"μM"]
15+
@parameters k1 [unit=u"μM/s"] k2 [unit=u"s"^(-1)] k3 [unit=u"μM*s"^(-1)]
1716
rxs = [Reaction(k1, nothing, [A]),
1817
Reaction(k2, [A], [B]),
1918
Reaction(k3, [A, B], [B], [1, 1], [2])]
@@ -23,9 +22,9 @@ let
2322

2423
# Test that all reactions have the correct unit.
2524
for rx in reactions(rs)
26-
@test get_unit(oderatelaw(rx)) == u"m/s"
25+
@test get_unit(oderatelaw(rx)) == u"μM/s"
2726
# we don't currently convert units, so they will be the same as for ODEs
28-
@test get_unit(jumpratelaw(rx)) == u"m/s"
27+
@test get_unit(jumpratelaw(rx)) == u"μM/s"
2928
end
3029

3130
# Tests that the system can be converted to MTK systems without warnings.
@@ -35,7 +34,7 @@ let
3534
@test_nowarn convert(NonlinearSystem, rs)
3635

3736
# Tests that creating `Reaction`s with non-matching units yields warnings.
38-
@species B(t) [unit=u"m"] D(t) [unit=u"A"]
37+
@species B(t) [unit=u"μM"] D(t) [unit=u"g"]
3938
bad_rx1 = Reaction(k1, [A], [D])
4039
bad_rx2 = Reaction(k1, [A], [B, D])
4140
bad_rx3 = Reaction(k1, [A, D], [B])
@@ -56,7 +55,7 @@ let
5655
@test (@test_logs (:warn, ) match_mode=:any validate(bad_rx8)) == false
5756

5857
# Tests that creating systems with non-matching units yields warnings.
59-
@parameters k2 [unit=u"A"]
58+
@parameters k2 [unit=u"g"]
6059
bad_rxs = [
6160
Reaction(k2, nothing, [A]),
6261
Reaction(k2, [A], [B]),
@@ -72,14 +71,14 @@ begin
7271
rs = @reaction_network begin
7372
@ivs t [unit=u"s"]
7473
@species begin
75-
A(t), [unit=u"m"]
76-
B(t), [unit=u"m"]
77-
C(t), [unit=u"m"]
74+
A(t), [unit=u"μM"]
75+
B(t), [unit=u"μM"]
76+
C(t), [unit=u"μM"]
7877
end
7978
@parameters begin
80-
k1, [unit=u"m/s"]
79+
k1, [unit=u"μM/s"]
8180
k2, [unit=u"s"^(-1)]
82-
k3, [unit=u"m*s"^(-1)]
81+
k3, [unit=u"μM*s"^(-1)]
8382
end
8483
k1, 0 --> A
8584
k2, A --> B
@@ -88,26 +87,26 @@ begin
8887

8988
# Checks that the `ReactionSystem`'s content have the correct units.
9089
@test get_unit(get_iv(rs)) == u"s"
91-
@test all(get_unit.([rs.A, rs.B, rs.C]) .== [u"m", u"m", u"m"])
92-
@test all(get_unit.([rs.k1, rs.k2, rs.k3]) .== [u"m/s", u"s"^(-1), u"m*s"^(-1)])
90+
@test all(get_unit.([rs.A, rs.B, rs.C]) .== [u"μM", u"μM", u"μM"])
91+
@test all(get_unit.([rs.k1, rs.k2, rs.k3]) .== [u"μM/s", u"s"^(-1), u"μM*s"^(-1)])
9392
for rx in reactions(rs)
94-
@test get_unit(oderatelaw(rx)) == u"m/s"
93+
@test get_unit(oderatelaw(rx)) == u"μM/s"
9594
# we don't currently convert units, so they will be the same as for ODEs
96-
@test get_unit(jumpratelaw(rx)) == u"m/s"
95+
@test get_unit(jumpratelaw(rx)) == u"μM/s"
9796
end
9897

99-
# Checks that system declarations with erroneous errors yields errors.
98+
# Checks that system declarations with erroneous units yields errors.
10099
@test_logs (:warn, ) match_mode=:any @reaction_network begin
101-
@ivs t [unit=u"1/s"]
100+
@ivs t [unit=u"1/s"] # Here, t's unit is wrong.
102101
@species begin
103-
A(t), [unit=u"m"]
104-
B(t), [unit=u"m"]
105-
C(t), [unit=u"m"]
102+
A(t), [unit=u"μM"]
103+
B(t), [unit=u"μM"]
104+
C(t), [unit=u"μM"]
106105
end
107106
@parameters begin
108-
k1, [unit=u"m/s"]
107+
k1, [unit=u"μM/s"]
109108
k2, [unit=u"s"^(-1)]
110-
k3, [unit=u"m*s"^(-1)]
109+
k3, [unit=u"μM*s"^(-1)]
111110
end
112111
k1, 0 --> A
113112
k2, A --> B
@@ -116,14 +115,14 @@ begin
116115
@test_logs (:warn, ) match_mode=:any @reaction_network begin
117116
@ivs t [unit=u"s"]
118117
@species begin
119-
A(t), [unit=u"m"]
120-
B(t), [unit=u"m"]
121-
C(t), [unit=u"m"]
118+
A(t), [unit=u"μM"]
119+
B(t), [unit=u"μM"]
120+
C(t), [unit=u"μM"]
122121
end
123122
@parameters begin
124-
k1, [unit=u"m"]
123+
k1, [unit=u"μM"] # Here, k1's unit is wrong.
125124
k2, [unit=u"s"^(-1)]
126-
k3, [unit=u"m*s"^(-1)]
125+
k3, [unit=u"μM*s"^(-1)]
127126
end
128127
k1, 0 --> A
129128
k2, A --> B
@@ -132,14 +131,14 @@ begin
132131
@test_logs (:warn, ) match_mode=:any @reaction_network begin
133132
@ivs t [unit=u"s"]
134133
@species begin
135-
A(t), [unit=u"m*s"]
136-
B(t), [unit=u"m"]
137-
C(t), [unit=u"m"]
134+
A(t), [unit=u"μM*s"] # Here, A's unit is wrong.
135+
B(t), [unit=u"μM"]
136+
C(t), [unit=u"μM"]
138137
end
139138
@parameters begin
140-
k1, [unit=u"m/s"]
139+
k1, [unit=u"μM/s"]
141140
k2, [unit=u"s"^(-1)]
142-
k3, [unit=u"m*s"^(-1)]
141+
k3, [unit=u"μM*s"^(-1)]
143142
end
144143
k1, 0 --> A
145144
k2, A --> B
@@ -169,20 +168,20 @@ let
169168
@test_nowarn @reaction_network begin
170169
@ivs t [unit=u"s"]
171170
@species begin
172-
X1(t), [unit=u"m"]
173-
Z1(t), [unit=u"m"]
174-
X2(t), [unit=u"m"]
175-
Z2(t), [unit=u"m"]
176-
X3(t), [unit=u"m"]
177-
Y3(t), [unit=u"m"]
178-
Z3(t), [unit=u"m"]
171+
X1(t), [unit=u"μM"]
172+
Z1(t), [unit=u"μM"]
173+
X2(t), [unit=u"μM"]
174+
Z2(t), [unit=u"μM"]
175+
X3(t), [unit=u"μM"]
176+
Y3(t), [unit=u"μM"]
177+
Z3(t), [unit=u"μM"]
179178
end
180179
@parameters begin
181-
k1, [unit=u"m^(-2)/s"]
182-
v2, [unit=u"m^(-2)/s"]
183-
K2, [unit=u"m"]
184-
v3, [unit=u"m^(-1)/s"]
185-
K3, [unit=u"m"]
180+
k1, [unit=u"μM^(-2)/s"]
181+
v2, [unit=u"μM^(-2)/s"]
182+
K2, [unit=u"μM"]
183+
v3, [unit=u"μM^(-1)/s"]
184+
K3, [unit=u"μM"]
186185
n3
187186
end
188187
k1*X1, 2X1 --> Z1

0 commit comments

Comments
 (0)