Skip to content

Commit

Permalink
Eagerly screen units
Browse files Browse the repository at this point in the history
  • Loading branch information
YingboMa committed Jan 3, 2024
1 parent 8f09054 commit 3e474bd
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Distributed = "1"
Distributions = "0.23, 0.24, 0.25"
DocStringExtensions = "0.7, 0.8, 0.9"
DomainSets = "0.6"
DynamicQuantities = "0.8"
DynamicQuantities = "0.8, 0.9, 0.10"
ForwardDiff = "0.10.3"
FunctionWrappersWrappers = "0.1"
Graphs = "1.5.2"
Expand Down
3 changes: 2 additions & 1 deletion src/systems/unit_check.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ function __get_literal_unit(x)
return nothing
end
v = value(x)
getmetadata(v, VariableUnit, nothing)
u = getmetadata(v, VariableUnit, nothing)
u === nothing ? nothing : screen_unit(u)
end
function __get_scalar_unit_type(v)
u = __get_literal_unit(v)
Expand Down
7 changes: 1 addition & 6 deletions test/dq_units.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,11 @@ end
end
@named p1 = Pin()
@named p2 = Pin()
@named op = OtherPin()
@test_throws MT.ValidationError @named op = OtherPin()
@named lp = LongPin()
good_eqs = [connect(p1, p2)]
bad_eqs = [connect(p1, p2, op)]
bad_length_eqs = [connect(op, lp)]
@test MT.validate(good_eqs)
@test !MT.validate(bad_eqs)
@test !MT.validate(bad_length_eqs)
@named sys = ODESystem(good_eqs, t, [], [])
@test_throws MT.ValidationError ODESystem(bad_eqs, t, [], []; name = :sys)

# Array variables
@variables t [unit = u"s"] x(t)[1:3] [unit = u"m"]
Expand Down

0 comments on commit 3e474bd

Please sign in to comment.