Skip to content

Set global units in the context manager? #9

Description

@blakeaw

It might be interesting to see if the global units of a model set with SimulationUnits could be defined inside the units context manager. This would help simplify the model code.

However, it's unclear if this would work with the current units context setup. The pysb Model object would likely need to be defined before entering the units context, allowing the context manager to accept unit arguments and assign a SimulationUnits object to the model. So, it would look something like:

Model()
with units(time="h", concentration="nM", volume="L"):
    Parameter(....)
    ....
    ....

Then, as part of the units context initialization, it would define SimulationUnits(time="h", concentration="nM", volume="L") for the model.

This might also help facilitate dynamic changes to the model units by calling the units context outside the model definition. Something like:

from my_model import model
from psyb.units import units

with units(time="s", concentration="uM", volume="pL"):
    # do something with model, now with base units of s, uM, and pL...

However, some mechanism to iterate over the model components and update all units would be necessary in this case. Maybe the units context could check for an existing SimulationUnits object and then override and update component units.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestquestionFurther information is requested

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions