Feature performance - #26
Conversation
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…path Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…etry buffer helper Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…eometries Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
irm-codebase
left a comment
There was a problem hiding this comment.
Looks good overall, but the unit tests need better environment isolation.
Details
In terms of memory efficiency this is night and day. Really impressive.
Some areas of the code seem a bit over optimised (e.g., plotting). It's ok to keep that as long as it does not become a maintenance burden.
General tests carried out:
- Executed the integration test.
- Executed for Mexico at state resolution (30+ shapes). Took ~13 minutes w/ 8 cores.
dask handles larger than memory operations well, as expected:
There was a problem hiding this comment.
consider renaming this to _plots.py or something similar, as everything here is related to plotting.
| # This call contains two optimisations for speed: | ||
| # 1. fig.savefig (rather than plt.savefig) disables pyplot's post-save re-render. | ||
| # 2. Omitting bbox_inches="tight" skips a measurement pre-render step. | ||
| fig.savefig(savefig, dpi=300) |
There was a problem hiding this comment.
I agree on using fig.savefig. Keeping bbox_inches="tight" might still be useful though, to avoid too much white space.
There was a problem hiding this comment.
It seems that bbox_inches="tight" requires rendering the whole figure an additional time, so it does have quite an impact..
| ) | ||
| assert process.returncode == 0, process.stdout + process.stderr | ||
| return process.stdout + process.stderr | ||
|
|
There was a problem hiding this comment.
Tests from here on seem a bit over engineered. We can keep, but we should not be overly attached to them.
|
This PR fixes hard-blocking issues related to this new feature. |
jnnr
left a comment
There was a problem hiding this comment.
Thanks for this! I am done with a first review. Test runs are running at the moment - I will check if the old results are reproduced for a European setting. I looked at most relevant parts, except for scripts/area_potential.py and scripts/resample.py. I will inspect them in a second round.
One of my central concern among the comments is that the test oracles probably do not give the validity that we desire for unit tests. In my view, it would be better to establish a source of truth can be easily checked by a human.
| return config | ||
|
|
||
|
|
||
| def sequential_area_potential(ds, config): |
There was a problem hiding this comment.
This oracle repeats the code implementing the logic of get_area_potential
Therefore, limited validity is provided.
A better approach would be to define and document expected results for simple examples that can be easily verified visually. For example, see https://github.com/modelblocks-org/gregor/blob/main/test/_files/test.png
|
|
||
|
|
||
| def _expected_masks(values, mapping): | ||
| """Independent oracle: per-category membership masks via np.isin.""" |
There was a problem hiding this comment.
Not sure how independent from
this really is, but fine for now.* Improve unit test isolation. Co-authored-by: Codex <codex@openai.com> * Fix Windows bug on unit tests. Root cause was attempt to delete open file. --- Co-authored-by: Codex <codex@openai.com> --------- Co-authored-by: Codex <codex@openai.com>
Co-authored-by: Ivan Ruiz Manuel <72193617+irm-codebase@users.noreply.github.com> Co-authored-by: Jann Launer <32454596+jnnr@users.noreply.github.com>
Feature performance ----------- Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Co-authored-by: Ivan Ruiz Manuel <72193617+irm-codebase@users.noreply.github.com>
Fixes #15
Summary of changes in this pull request
The main purpose of this PR was to address #15 and to optimise performance, but it bundles a couple of other changes too.
Claude Code was used for the memory and performance optimisations. In order to ensure these changes do not change results, a unit test suite checks against known-good data for a synthetic reference case, and for the Netherlands example already used in the integration test.
The following fixes and behaviour changes are also included:
protectedis now a fraction of a pixel (0-1), but can still be treated as a binary layer to keep the previous behaviour 1:1.Performance improvements included:
threads:is passed through to GDAL;resources: mem_mballows constraining parallelisation on memory-limited machines, and the memory-intensive rules also write a benchmark file for further monitoring.Testing added:
test-unitpixi environment pinned to the same versions asworkflow/envs/module.*.pin.txt(sync enforced by a test)pixi run update-reference; diffs totests/reference/are intentional and should be reviewed.Reviewer checklist
pipdependencies in the module's environment files (workflow/envs/).pathvars(e.g.,<results>) in their inputs and outputs.pre-commit.citests pass.INTERFACE.yamlmentions all relevantpathvarsandwildcards.README.mddescribes how to use the module and has the necessary citations.