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

[BUG]: Keep greek letters in extracted model somehow #6224

Closed
pascaleproulx opened this issue Jan 24, 2025 · 2 comments · Fixed by #6595
Closed

[BUG]: Keep greek letters in extracted model somehow #6224

pascaleproulx opened this issue Jan 24, 2025 · 2 comments · Fixed by #6595
Assignees
Labels
bug Something isn't working

Comments

@pascaleproulx
Copy link
Contributor

Describe the bug
Keep greek letters in extracted model somehow

Screenshots

Image

@pascaleproulx pascaleproulx added the bug Something isn't working label Jan 24, 2025
@YohannParis
Copy link
Member

Only the name should be translated to unicode characters.

@YohannParis YohannParis self-assigned this Feb 14, 2025
@liunelson
Copy link
Member

liunelson commented Feb 18, 2025

So, when one sends Greek letters in the LaTeX to "Create model from equations" operator, the SymPy intermediate code writes them as words, which MIRA then uses to make the AMR with names beta, gamma, ... as opposed to the unicode characters.

A solution would be to pass the model AMR through some regex that will convert any Greek letter words in the state/parameter/observable "name" (not "id" nor anywhere else) to the unicode character, e.g. beta -> β

https://en.wikipedia.org/wiki/Greek_letters_used_in_mathematics,_science,_and_engineering

Caveat:

LaTeX

[
  "\\frac{d S(t)}{d t} = - \\beta * S(t) * I(t) - \\mu",
  "\\frac{d I(t)}{d t} = \\beta * S(t) * I(t) - \\gamma * I(t) - \\mu",
  "\\frac{d R(t)}{d t} = \\gamma * I(t) - \\mu"
]

becomes SymPy:

import sympy

# Define time variable
t = sympy.symbols("t")

# Define variables with time derivative to be time-dependent functions
S, I, R = sympy.symbols("S I R", cls=sympy.Function)

# Define all parameters
beta, mu, gamma = sympy.symbols("beta mu gamma")

# Define the equations without time-derivative on the left hand side
equation_output = [
    sympy.Eq(S(t).diff(t), (-beta * S(t) * I(t) - mu).expand()),
    sympy.Eq(I(t).diff(t), (beta * S(t) * I(t) - gamma * I(t) - mu).expand()),
    sympy.Eq(R(t).diff(t), (gamma * I(t) - mu).expand())
]

and then this AMR

{
  "header": {
    "name": "Model",
    "schema": "https://raw.githubusercontent.com/DARPA-ASKEM/Model-Representations/petrinet_v0.6/petrinet/petrinet_schema.json",
    "schema_name": "petrinet",
    "description": "Model",
    "model_version": "0.1"
  },
  "properties": {},
  "model": {
    "states": [
      {
        "id": "I",
        "name": "I(t)",
        "grounding": {
          "identifiers": {},
          "modifiers": {}
        },
        "units": {
          "expression": "1",
          "expression_mathml": "1"
        }
      },
      {
        "id": "S",
        "name": "S(t)",
        "grounding": {
          "identifiers": {},
          "modifiers": {}
        },
        "units": {
          "expression": "1",
          "expression_mathml": "1"
        }
      },
      {
        "id": "R",
        "name": "R(t)",
        "grounding": {
          "identifiers": {},
          "modifiers": {}
        },
        "units": {
          "expression": "1",
          "expression_mathml": "1"
        }
      }
    ],
    "transitions": [
      {
        "id": "t0:I->",
        "input": [
          "I"
        ],
        "output": [],
        "properties": {
          "name": "t0:I->"
        }
      },
      {
        "id": "t1:S->",
        "input": [
          "S"
        ],
        "output": [],
        "properties": {
          "name": "t1:S->"
        }
      },
      {
        "id": "t2:R->",
        "input": [
          "R"
        ],
        "output": [],
        "properties": {
          "name": "t2:R->"
        }
      },
      {
        "id": "t3:S->I",
        "input": [
          "I",
          "S"
        ],
        "output": [
          "I",
          "I"
        ],
        "properties": {
          "name": "t3:S->I"
        }
      },
      {
        "id": "t4:I->R",
        "input": [
          "I"
        ],
        "output": [
          "R"
        ],
        "properties": {
          "name": "t4:I->R"
        }
      }
    ]
  },
  "semantics": {
    "ode": {
      "rates": [
        {
          "target": "t0:I->",
          "expression": "mu",
          "expression_mathml": "mu"
        },
        {
          "target": "t1:S->",
          "expression": "mu",
          "expression_mathml": "mu"
        },
        {
          "target": "t2:R->",
          "expression": "mu",
          "expression_mathml": "mu"
        },
        {
          "target": "t3:S->I",
          "expression": "I*S*beta",
          "expression_mathml": "ISbeta"
        },
        {
          "target": "t4:I->R",
          "expression": "I*gamma",
          "expression_mathml": "Igamma"
        }
      ],
      "initials": [
        {
          "target": "I",
          "expression": "0.0",
          "expression_mathml": "0.0"
        },
        {
          "target": "S",
          "expression": "0.0",
          "expression_mathml": "0.0"
        },
        {
          "target": "R",
          "expression": "0.0",
          "expression_mathml": "0.0"
        }
      ],
      "parameters": [
        {
          "id": "mu",
          "name": "mu",
          "value": 0,
          "units": {
            "expression": "1",
            "expression_mathml": "1"
          }
        },
        {
          "id": "beta",
          "name": "beta",
          "value": 0,
          "units": {
            "expression": "1",
            "expression_mathml": "1"
          }
        },
        {
          "id": "gamma",
          "name": "gamma",
          "value": 0,
          "units": {
            "expression": "1",
            "expression_mathml": "1"
          }
        }
      ],
      "observables": [],
      "time": {
        "id": "t",
        "units": {
          "expression": "day",
          "expression_mathml": "day"
        }
      }
    }
  },
  "metadata": {
    "annotations": {}
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants