@@ -8,12 +8,11 @@ using ModelingToolkit: get_iv, get_unit, validate, ValidationError
8
8
# ## Basic Tests ###
9
9
10
10
# 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.
12
11
let
13
12
# Creates a `ReactionSystem` programmatically, while designating units.
14
13
@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 )]
17
16
rxs = [Reaction (k1, nothing , [A]),
18
17
Reaction (k2, [A], [B]),
19
18
Reaction (k3, [A, B], [B], [1 , 1 ], [2 ])]
23
22
24
23
# Test that all reactions have the correct unit.
25
24
for rx in reactions (rs)
26
- @test get_unit (oderatelaw (rx)) == u "m /s"
25
+ @test get_unit (oderatelaw (rx)) == u "μM /s"
27
26
# 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"
29
28
end
30
29
31
30
# Tests that the system can be converted to MTK systems without warnings.
35
34
@test_nowarn convert (NonlinearSystem, rs)
36
35
37
36
# 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 " ]
39
38
bad_rx1 = Reaction (k1, [A], [D])
40
39
bad_rx2 = Reaction (k1, [A], [B, D])
41
40
bad_rx3 = Reaction (k1, [A, D], [B])
56
55
@test (@test_logs (:warn , ) match_mode= :any validate (bad_rx8)) == false
57
56
58
57
# Tests that creating systems with non-matching units yields warnings.
59
- @parameters k2 [unit= u "A " ]
58
+ @parameters k2 [unit= u "g " ]
60
59
bad_rxs = [
61
60
Reaction (k2, nothing , [A]),
62
61
Reaction (k2, [A], [B]),
@@ -72,14 +71,14 @@ begin
72
71
rs = @reaction_network begin
73
72
@ivs t [unit= u " s" ]
74
73
@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 " ]
78
77
end
79
78
@parameters begin
80
- k1, [unit= u "m /s" ]
79
+ k1, [unit= u "μM /s" ]
81
80
k2, [unit= u " s" ^ (- 1 )]
82
- k3, [unit= u "m *s" ^ (- 1 )]
81
+ k3, [unit= u "μM *s" ^ (- 1 )]
83
82
end
84
83
k1, 0 --> A
85
84
k2, A --> B
@@ -88,26 +87,26 @@ begin
88
87
89
88
# Checks that the `ReactionSystem`'s content have the correct units.
90
89
@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 )])
93
92
for rx in reactions (rs)
94
- @test get_unit (oderatelaw (rx)) == u "m /s"
93
+ @test get_unit (oderatelaw (rx)) == u "μM /s"
95
94
# 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"
97
96
end
98
97
99
- # Checks that system declarations with erroneous errors yields errors.
98
+ # Checks that system declarations with erroneous units yields errors.
100
99
@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.
102
101
@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 " ]
106
105
end
107
106
@parameters begin
108
- k1, [unit= u "m /s" ]
107
+ k1, [unit= u "μM /s" ]
109
108
k2, [unit= u " s" ^ (- 1 )]
110
- k3, [unit= u "m *s" ^ (- 1 )]
109
+ k3, [unit= u "μM *s" ^ (- 1 )]
111
110
end
112
111
k1, 0 --> A
113
112
k2, A --> B
@@ -116,14 +115,14 @@ begin
116
115
@test_logs (:warn , ) match_mode= :any @reaction_network begin
117
116
@ivs t [unit= u " s" ]
118
117
@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 " ]
122
121
end
123
122
@parameters begin
124
- k1, [unit= u "m " ]
123
+ k1, [unit= u "μM " ] # Here, k1's unit is wrong.
125
124
k2, [unit= u " s" ^ (- 1 )]
126
- k3, [unit= u "m *s" ^ (- 1 )]
125
+ k3, [unit= u "μM *s" ^ (- 1 )]
127
126
end
128
127
k1, 0 --> A
129
128
k2, A --> B
@@ -132,14 +131,14 @@ begin
132
131
@test_logs (:warn , ) match_mode= :any @reaction_network begin
133
132
@ivs t [unit= u " s" ]
134
133
@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 " ]
138
137
end
139
138
@parameters begin
140
- k1, [unit= u "m /s" ]
139
+ k1, [unit= u "μM /s" ]
141
140
k2, [unit= u " s" ^ (- 1 )]
142
- k3, [unit= u "m *s" ^ (- 1 )]
141
+ k3, [unit= u "μM *s" ^ (- 1 )]
143
142
end
144
143
k1, 0 --> A
145
144
k2, A --> B
@@ -169,20 +168,20 @@ let
169
168
@test_nowarn @reaction_network begin
170
169
@ivs t [unit= u " s" ]
171
170
@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 " ]
179
178
end
180
179
@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 " ]
186
185
n3
187
186
end
188
187
k1* X1, 2 X1 --> Z1
0 commit comments