forked from SciML/ModelingToolkit.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_variable_metadata.jl
100 lines (80 loc) · 1.96 KB
/
test_variable_metadata.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using ModelingToolkit
# Bounds
@variables u [bounds = (-1, 1)]
@test getbounds(u) == (-1, 1)
@test hasbounds(u)
@variables y
@test !hasbounds(y)
# Disturbance
@variables u [disturbance = true]
@test isdisturbance(u)
@variables y
@test !isdisturbance(y)
# Tunable
@parameters u [tunable = true]
@test istunable(u)
@parameters y
@test !istunable(y)
# Distributions
struct FakeNormal end
d = FakeNormal()
@parameters u [dist = d]
@test hasdist(u)
@test getdist(u) == d
@parameters y
@test !hasdist(y)
## System interface
@parameters t
Dₜ = Differential(t)
@variables x(t)=0 [bounds = (-10, 10)] u(t)=0 [input = true] y(t)=0 [output = true]
@parameters T [tunable = true, bounds = (0, Inf)]
@parameters k [tunable = true, bounds = (0, Inf)]
@parameters k2
eqs = [Dₜ(x) ~ (-k2 * x + k * u) / T
y ~ x]
sys = ODESystem(eqs, t, name = :tunable_first_order)
p = tunable_parameters(sys)
sp = Set(p)
@test k ∈ sp
@test T ∈ sp
@test k2 ∉ sp
@test length(p) == 2
lb, ub = getbounds(p)
@test lb == [0, 0]
@test ub == [Inf, Inf]
b = getbounds(sys)
@test b[T] == (0, Inf)
b = getbounds(sys, states(sys))
@test b[x] == (-10, 10)
p = tunable_parameters(sys, default = true)
sp = Set(p)
@test k ∈ sp
@test T ∈ sp
@test k2 ∈ sp
@test length(p) == 3
## Descriptions
@variables u [description = "This is my input"]
@test getdescription(u) == "This is my input"
@test hasdescription(u)
@variables u
@test getdescription(u) == ""
@test !hasdescription(u)
@parameters t
@variables u(t) [description = "A short description of u"]
@parameters p [description = "A description of p"]
@named sys = ODESystem([u ~ p], t)
@test_nowarn show(stdout, "text/plain", sys)
@testset "binary" begin
@parameters t
@variables u(t) [binary = true]
@parameters p [binary = true]
@test isbinaryvar(u)
@test isbinaryvar(p)
end
@testset "integer" begin
@parameters t
@variables u(t) [integer = true]
@parameters p [integer = true]
@test isintegervar(u)
@test isintegervar(p)
end