Skip to content
New issue

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

By clicking “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? Sign in to your account

@instantiateModel with Unitful quantities fails with default UNITFUL_FANCY_EXPONENTS [=true] #115

Open
mdAshford opened this issue Apr 27, 2021 · 1 comment

Comments

@mdAshford
Copy link

I'm ecstatic over this update. Sundials was making me crazy. Thank you for your hard work.

Here is a small item:

@instantiateModel fails when the Model contains Unitful quantities, as in the pendulum example in the README.

Unitful's default behavior is to render exponents as unicode subscripts. Upon parsing those expressions, Unitful does not recognize them as units, causing @instantiateModel to fail.

Setting

ENV["UNITFUL_FANCY_EXPONENTS"]=false

before calling @instantiateModel prevents the problem.

@MartinOtter
Copy link
Member

@instantiateModel fails when the Model contains Unitful quantities, as in the pendulum example in the README.

The pendulum example in the README file is available as Modia/examples/Pendulum.jl. When executing it on my (Windows) machine, it translates and simulates correctly.

The docu in Unitful states:

By default, exponents on units or dimensions are indicated using Unicode superscripts on macOS and without superscripts on other operating systems. You can set the environment variable UNITFUL_FANCY_EXPONENTS to either true or false to force using or not using the exponents.

So, you are probably working on macOS. It feels a bit dangerous that a global environment variable is set inside Modia. It would be better to extend Modia, so that units with exponents are also correctly handled on macOS without setting this environment variable. When inspecting https://en.wikipedia.org/wiki/Unicode_subscripts_and_superscripts it seems quite complicated to support this, because there are Unicode superscripts for a large set of characters. We also have no access to macOS, and cannot test such a bug fix.

The simplest solution is probably to follow your suggestion, so set ENV["UNITFUL_FANCY_EXPONENTS"]=false on macOS when entering @instantiateModel, and additionally print a warning message, if ENV["UNITFUL_FANCY_EXPONENTS"] was not set or has a value of true on macOS.

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

No branches or pull requests

2 participants