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