-
Notifications
You must be signed in to change notification settings - Fork 2
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
Adds support for static models #373
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got slightly lost in one bit of the pseudocode, but the general approach seems sensible and flexible.
""" | ||
if self._static_data is None: | ||
self._update(time_index, **kwargs) | ||
self._build_static_data(time_index) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure that I follow this bit, does the update happen and then new static data gets built for the next time step?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly. This is run only once, the first time that we are required to run the update and, thereafter the updated values are used for updating the data object again and again. We need to run update at least once in this case since, otherwise, we do not know what to update the data with.
If pre-set data is provided as an external file/s, then the static_data
object is not none and this step is not needed.
Keeping aside changes in initialisation/validation, the only change to existing models would be to replace update
by _update
, since they are overwritting only one of the two options for updating the model. The _update_static
option is not model specific, and therefore is coded directly in the base model.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh right that makes sense now, cheers!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not so familiar with self._
, but the approach looks generally good to me.
This makes a lot sense to me - the flow of the logic for the "update once and then repeat" is very clean. I wonder if the There are no end of repeating patterns and sequences we might want to push in (La Niña, El Niño), but that seems like an evolution 😄 |
I'm not entirely sure what you mean here. Do you mean having a method called
I guess that the model can hold a single copy of that single step data, but then in the Data object it will need to update timestep after timestep to create the time series (when relevant), so other models can use it. I think that models that use that data should not need to worry about it being static or not, but just take the appropriate time from the Data object and go on with it, right? |
Yeah - wasn't a model of clarity was it. So:
|
Yup - agreed. |
Next week, this one. If you have any update or comment on what was said above, please let me know. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me.
I've been trying to progress on this before going on leave but I've hit a blocker - precisely because of the brand new variables system. For the case of the frozen model - updates once and then repeat for future iterations - things are clear as the inputs are the same as a normal model. I have not implemented it but I do not foresee any problem there: it will make a local copy of the relevant data (the Now, for the pre-set option things have gotten more complicated after implementing the variables system. As discussed above, that preset data will need to be passed as part of the data object, but that would mean that the model has different vars required for update when it is static or when it is not: in the first case, the pre-set data will need to be present, but in the normal case it will not, in general (or at least, not necessarily). As these variables are set before the model instances are initialised, when collecting the models, there is no way to modify them at runtime based on the model input settings (the static flag). There are a couple of options that come to my mind, none of them satisfactory:
It will be good to have your feedback on this, so I can work on it as soon as I'm back from leave. |
Yeah - that's a pain. First thoughts:
Having said that, I haven't got my head around how we work with avoiding running code in static mode models.
def __init__(self, ...):
super().__init__(data=data, static_data=static_data, core_components=core_components, **kwargs)
if self.entirely_static_init:
return
This reminds me a little of #188! Thinking about it - that "static" flag might allow us to avoid the extra
|
I've been working on this and after a few trials and errors I think there are only 3 scenarios involving the
I will implement a prototype of how that bypassing can be done with minimal fuss. |
Ok, so here you have another take at this. The code seems verbose because I tried to be thorough with the error messages, but actual lines changed are very few. This implements two methods:
For this to work, the following changes will need to be done to all the models:
OK, so give it some thoughts and we can move from here. The pending things/open questions are:
|
The I guess we might want to change how the |
@davidorme , did you have a chance to look into the new version of this? |
@dalonsoa I hadn't had a chance to review this new version yet. I'll try and have a look this week - for a mix of school inset days and thesis vivas to juggle. |
No rush. I was mentioning just in reference to #541 |
OK, I got the errors: For "soil":
For "litter:
So, the solution would be to get rid of those from the data object in the example, but chances are that will break a lot of things. |
Or @jacobcook1995 is this simply that you've now implemented the calculation of things we had to feed in by hand before, and we just need to update the data? That seems quite likely - there's been a lot of movement on those models. |
This error seems to be related to the content of |
Actually this isn't right sorry, the animal model needs to know about the size of the litter pools so there is a dependance there |
All of those variables do need to stay in the example data though as they are required for model initialisation. Maybe it's that they are all in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general looks good to me, just had a query about the error message that was causing problems above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! I've put some small comments and suggestions.
I'm planning to work on #581 from next week, but for that I really need this PR agreed and merged. Is there any barrier for that to happen? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for the delayed response, I was pretty much out of office for the last 6 weeks. I do not see any reason why you shouldn't merge this branch, in particular if it stops you from proceeding.
Yes, please. We really need to merge this - or ditch it altogether. I've already had to fix merge conflicts several times because - obviously - you keep working and adding stuff incompatible with the changes here, and today I've wasted 3h trying to incorporate the latest changes to the animal model without success because in the data object there's some data that should not be there. @TaranRallings , I get this error:
Either So, keeping aside this being a barrier or not, once @TaranRallings has fixed the above issue, please merge or close this PR without merging, but do not leave it lingering around for longer. |
Description
This PR setups the models such that they can be frozen or static, i.e. they are setup once and they are used the same, without updating, for the rest of the simulation. This is controlled by a
static
flag included in the configuration.There are two options for static models:
Documentation about using the flag has been added to the
config.md
file, but I'm not sure if there's a better place.Most modifications to the test have consisted in bypassing the static checks because, as the tests were designed, they were all failing. In all cases, only some of the variables required for init or for update were present in the data object, typically provided as a fixture, which were making the checks to decide on the staticity of the models fail. Options are to leave the patches used as they are, or to add all the missing variables. However, that might be a lot of work and I'm not entirely sure if it is worth the effort.
Fixes # N/A
Type of change
Key checklist
pre-commit
checks:$ pre-commit run -a
$ poetry run pytest
Further checks