Skip to content

Commit 92a0957

Browse files
committed
add option to access state bounds
1 parent e1e6b9a commit 92a0957

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/variables.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,16 +237,17 @@ function tunable_parameters(sys, p = parameters(sys); default = false)
237237
end
238238

239239
"""
240-
getbounds(sys::ModelingToolkit.AbstractSystem)
240+
getbounds(sys::ModelingToolkit.AbstractSystem, p = parameters(sys))
241241
242242
Returns a dict with pairs `p => (lb, ub)` mapping parameters of `sys` to lower and upper bounds.
243243
Create parameters with bounds like this
244244
```
245245
@parameters p [bounds=(-1, 1)]
246246
```
247+
248+
To obtain state bounds, call `getbounds(sys, states(sys))`
247249
"""
248-
function getbounds(sys::ModelingToolkit.AbstractSystem)
249-
p = parameters(sys)
250+
function getbounds(sys::ModelingToolkit.AbstractSystem, p = parameters(sys))
250251
Dict(p .=> getbounds.(p))
251252
end
252253

test/test_variable_metadata.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ d = FakeNormal()
3535
## System interface
3636
@parameters t
3737
Dₜ = Differential(t)
38-
@variables x(t)=0 u(t)=0 [input = true] y(t)=0 [output = true]
38+
@variables x(t)=0 [bounds = (-10, 10)] u(t)=0 [input = true] y(t)=0 [output = true]
3939
@parameters T [tunable = true, bounds = (0, Inf)]
4040
@parameters k [tunable = true, bounds = (0, Inf)]
4141
@parameters k2
@@ -57,6 +57,9 @@ lb, ub = getbounds(p)
5757
b = getbounds(sys)
5858
@test b[T] == (0, Inf)
5959

60+
b = getbounds(sys, states(sys))
61+
@test b[x] == (-10, 10)
62+
6063
p = tunable_parameters(sys, default = true)
6164
sp = Set(p)
6265
@test k sp

0 commit comments

Comments
 (0)