Skip to content

Support scaled SI units #2616

New issue

Have a question about this project? No Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “No Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? No Sign in to your account

Closed
TorkelE opened this issue Apr 5, 2024 · 5 comments · Fixed by #2621
Closed

Support scaled SI units #2616

TorkelE opened this issue Apr 5, 2024 · 5 comments · Fixed by #2621
Labels

Comments

@TorkelE
Copy link
Member

TorkelE commented Apr 5, 2024

E.g. this fails:

using ModelingToolkit, DynamicQuantities
@parameters p [unit = u"L/s"] d [unit = u"s^(-1)"]
@parameters t [unit = u"s"] 
@variables X [unit = u"L"]
D = Differential(t)
eqs =[D(X) ~ p - d*X]
ModelingToolkit.validate(eqs) # Does not work.

Instead, one have to do:

using ModelingToolkit, DynamicQuantities
@parameters p [unit = u"m^3/s"] d [unit = u"s^(-1)"]
@parameters t [unit = u"s"] 
@variables X [unit = u"m^3"]
D = Differential(t)
eqs =[D(X) ~ p - d*X]
ModelingToolkit.validate(eqs) # Does not work.

These are identical. For highly composite units, rather cumbersome expressions will be generated. Allowing composite units should be very desirable (and was how things used to work).

@TorkelE TorkelE added the bug Something isn't working label Apr 5, 2024
@ChrisRackauckas
Copy link
Member

@YingboMa do you know why this limitation exists?

@YingboMa YingboMa added feature and removed bug Something isn't working labels Apr 5, 2024
@YingboMa YingboMa changed the title Unit checking fails when using composite SI units Support scaled SI units Apr 5, 2024
@YingboMa
Copy link
Member

YingboMa commented Apr 5, 2024

First, L is not a SI unit; m^3 is a SI unit.

In principle, unit checking can pass as long as they have the same dimension, but what happens when there's x ~ y where x has the unit of L but y has the unit of m^3? The reason that we error for non-SI units is because that requires additional transformation to equations to be correct in general.

@isaacsas
Copy link
Member

isaacsas commented Apr 5, 2024

Mixing L and m^3 resulting in an error seems reasonable, but why can't non-SI units be supported anymore? They were supported previously with Unitful, and are incredibly common in chemistry / biology contexts (i.e. Molar concentrations for example which I guess are not SI but the most common concentration measure in most bio papers). @TorkelE's example that uses units of just L and s seems like it shouldn't require extra transformations to validate, just support for non-SI units.

@YingboMa
Copy link
Member

YingboMa commented Apr 5, 2024

There's no way of tell if someone uses constants like u"cm" or 1e-2u"m" though.

julia> using DynamicQuantities

julia> u"cm"
0.01 m

julia> 1e-2u"m"
0.01 m

julia> 1e-2u"m" === u"cm"
true

@YingboMa
Copy link
Member

YingboMa commented Apr 5, 2024

To support non-SI units, we need to use SymbolicDimensions from DynamicQuantities.

No Sign up for free to join this conversation on GitHub. Already have an account? No Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants