Skip to content

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

Open
@mdAshford

Description

@mdAshford

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.

Activity

MartinOtter

MartinOtter commented on Apr 28, 2021

@MartinOtter
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @MartinOtter@mdAshford

        Issue actions

          @instantiateModel with Unitful quantities fails with default UNITFUL_FANCY_EXPONENTS [=true] · Issue #115 · ModiaSim/Modia.jl