Skip to content

Set global units in the context manager? #9

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

Open
blakeaw opened this issue Jan 28, 2025 · 0 comments
Open

Set global units in the context manager? #9

blakeaw opened this issue Jan 28, 2025 · 0 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@blakeaw
Copy link
Contributor

blakeaw commented Jan 28, 2025

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.

@blakeaw blakeaw added enhancement New feature or request question Further information is requested labels Jan 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant