Conversation
use torch.where in phenology add config flag for carbon balance
|
In order to reduce the execution time, I have implemented the following modifications:
|
|
In order to make the tests more manageable (the test action takes >2h if unchecked), I have introduced two
@SarahAlidoost, we could think about using |
|
SarahAlidoost
left a comment
There was a problem hiding this comment.
@SCiarella Awesome! 👍 The changes look very good, nice to see that all differentiable crop modules are now integrated in wofost72 and gradients are valid 😄 In #88, we will show the optimization of wofost72_pp. Thanks for implementing the soil module too.
I left a few suggestions:
- I added some inline comment about issue #60. In
wofost72.py, we have conditions likeif torch.all(self.pheno.states.STAGE == 0). Right nowSTAGEis either an integer or an array where all values are the same. But actually, with different crops and agro-management, this condition might not work. This should be fixed when engine can handle different crops and agro-management. - I suggested choosing different data for fast test.
After addressing these, we can merge this 🚀
| self.rates = self.RateVariables(kiosk, shape=shape) | ||
| self.kiosk = kiosk | ||
|
|
||
| self._connect_signal(self._on_CROP_FINISH, signal=signals.crop_finish) |
There was a problem hiding this comment.
| # see issue #60 | |
| self._connect_signal(self._on_CROP_FINISH, signal=signals.crop_finish) |
|
|
||
| # Send crop_finish signal if maturity reached for one. | ||
| # assumption is that all elements mature simultaneously | ||
| # TODO: revisit this when fixing engine for agromanager |
There was a problem hiding this comment.
| # TODO: revisit this when fixing engine for agromanager, see issue #60 |
| msg = "Finished state integration for %s" | ||
| self.logger.debug(msg % day) | ||
|
|
||
| def _on_CROP_FINISH(self, day, finish_type=None): |
There was a problem hiding this comment.
| # TODO: revisit this when fixing engine for agromanager, see issue #60 | |
| def _on_CROP_FINISH(self, day, finish_type=None): |
| self.params.shape, day.toordinal(), dtype=self.dtype, device=self.device | ||
| ) | ||
|
|
||
| def get_variable(self, varname): |
There was a problem hiding this comment.
We can remove this function. I couldn't do it in the review because this part is not changed in this PR.
| EVS = Tensor(-99.0) | ||
| WTRA = Tensor(-99.0) |
There was a problem hiding this comment.
| EVS = Tensor(-99.0) | |
| WTRA = Tensor(-99.0) | |
| EVS = Tensor(0.0) | |
| WTRA = Tensor(0.0) |
| test_data_url = params.get("test_data_url") | ||
| if test_data_url is not None: | ||
| match = re.search(r"_(\d+)\.yaml$", str(test_data_url)) | ||
| if match and int(match.group(1)) > 5: |
There was a problem hiding this comment.
Good idea! Files 1:5 are all the same crop and similar agro management data. It is better to choose files 05, 06, 10, 20, 30, 44. These cover different crops and agro management info, and perhaps edge cases, if any. Is it possible to use those files instead? we can hard code the file names here.
| self.pheno.calc_rates(day, drv) | ||
|
|
||
| # if before emergence there is no need to continue | ||
| # because only the phenology is running. |
There was a problem hiding this comment.
| # because only the phenology is running. | |
| # because only the phenology is running. | |
| # TODO: revisit this when fixing #60 |
| # if before emergence there is no need to continue | ||
| # because only the phenology is running. | ||
| # Just run a touch() to to ensure that all state variables are available | ||
| # in the kiosk |
There was a problem hiding this comment.
| # in the kiosk | |
| # in the kiosk | |
| # TODO: revisit this when fixing #60 |
Good idea! This has been done in pcse as well, quick and full test. I see that the action still takes 20 minutes. Later we can think about optimizing this further.
That's a good solution. Also, we can remove |



This PR closes #49.
Noticeably,
Wofost72uses kiosk variables such asEVSthat come from the soil model. So in order to make wofost72 consistently differentiable and vectorized, I had to implement a differentiable soil modelsoil/classic_waterbalance.pywhich is inspired by the corresponding model from pcse.This PR also adds a lot of tests, making issue #81 more relevant than ever.