Replies: 3 comments 10 replies
-
I've got a sketch in my head for this. At the moment the def __init__(
self, update_interval: timedelta64, start_time: datetime64, **kwargs: Any
):
self.update_interval = update_interval
self.next_update = start_time + update_interval
# Save variables names to be used by the __repr__
self._repr = ["update_interval", "next_update"] I think that is altered to: ```python
def __init__(
self, data: Data, update_interval: timedelta64, start_time: datetime64, **kwargs: Any
):
self.data = data
self.update_interval = update_interval
self.next_update = start_time + update_interval
# Save variables names to be used by the __repr__
self._repr = ["update_interval", "next_update"] So the flow of the program is:
One other thing we discussed at various points was having a way of declaring required variables for initialising a model. The idea I had for this is making a class variable to hold a list of variable names that have to be present and aligned onto the right core axes in As a sketch: class BaseModel(ABC):
"""A superclass for all `vr` models.
Describes the common functions and attributes that all `vr` models should have. This
includes functions to setup, spin up and update the specific model, as well as a
function to cleanup redundant model data. At this level these functions are not
define and are mere placeholders to be overwritten (where appropriate) by the
inheriting classes.
Args:
start_time: Point in time that the model simulation should be started.
end_time: Time that the model simulation should end
update_interval: Time to wait between updates of the model state.
Attributes:
name: Names the model that is described
required_variables: A tuple of required variable names and the core axes
they must match. For example: ``(('temperature', ('spatial', 'temporal')))``
"""
name = "base"
required_variables: tuple[tuple[str, tuple[str]]] = tuple()
def __init__(
data: Data, update_interval: timedelta64, start_time: datetime64, **kwargs: Any
):
self.data = data
self.check_required_variables()
self.update_interval = update_interval
self.next_update = start_time + update_interval
# Save variables names to be used by the __repr__
self._repr = ["update_interval", "next_update"]
def check_required_variables(self):
"""A docstring"""
all_required = True
for varname, core_axes in self.required_variables:
if not varname in self.data:
LOGGER.error(f"{self.name} model missing required variable: {varname}")
all_required = False
continue
for axname in core_axes:
if not self.data.on_core_axis(varname, axname):
LOGGER.error(
f"{self.name} model: variable {varname} not on core axis {axname}"
)
all_required = False
if not all_required:
LOGGER.critical(f"{self.name} model missing required variable: {varname}")
raise ConfigurationError(
f"Required data not correctly configured for {self.name} model"
) |
Beta Was this translation helpful? Give feedback.
-
It isn't even a copy - its a reference to the exact same object: An instance of the If this is not the case (@dalonsoa , @alexdewar ) then I have utterly dropped the ball on the core development 😰 |
Beta Was this translation helpful? Give feedback.
-
As Alex says, the object will be passed by reference, so there will be no copy of information. I think that the key aspect is that of ownership of the Data object. If it is assigned as the attribute of half a dozen models, where it is actually living? Objects in Python are kept alive for as long as there is a reference to them. I am not sure if this aspect will matter much in this particular workflow, but I think it will be cleaner if Data is passed to the models using weak references, leaving the ownership of the object to the caller. Here you have a detailed description of a use case for this and how to implement it: https://docs.python.org/3/library/weakref.html |
Beta Was this translation helpful? Give feedback.
-
In our group meeting yesterday, we once more discussed the need for a central 'data' object that is accessible for all modules and stores all relevant variables that go in and out of the modules (and between modules). I would like to discuss the mechanism of accessing and updating this object. As mentioned yesterday, it is crucial that processes in different modules and updating of the data object happen in a coordinated way and that the correct time step is accessed; at the same time we want to store as little data as possible. (For those who did not attend the meeting yesterday, we currently use different dummy versions of the data object to develop the modules which is not ideal.)
So the question is: Should each module load the whole data object, do it's thing for the current time step, update the data object and return the info to a central location? How does it work that it is pushed back to where it is accessible for everyone?
Beta Was this translation helpful? Give feedback.
All reactions