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.
It might be interesting to see if the global units of a model set with
SimulationUnitscould be defined inside theunitscontext manager. This would help simplify the model code.However, it's unclear if this would work with the current
unitscontext setup. The pysbModelobject would likely need to be defined before entering theunitscontext, allowing the context manager to accept unit arguments and assign aSimulationUnitsobject to the model. So, it would look something like:Then, as part of the
unitscontext initialization, it would defineSimulationUnits(time="h", concentration="nM", volume="L")for the model.This might also help facilitate dynamic changes to the model units by calling the
unitscontext outside the model definition. Something like:However, some mechanism to iterate over the model components and update all units would be necessary in this case. Maybe the
unitscontext could check for an existingSimulationUnitsobject and then override and update component units.