fix: matrix cache silently corrupts matrices when view/sensor/surface names collide - #65
Open
silaskalmbach wants to merge 1 commit into
Open
Conversation
… names collide
save_matrices keyed all per-entity matrices by bare entity name:
'{name}_sky_matrix' (TwoPhase, views AND sensors), '{name}_window_matrix'
(ThreePhase: views, sensors AND surfaces; FivePhase: views and sensors) and
'{name}_sun_direct_matrix' (FivePhase). When two groups share a name -- e.g.
a view and a sensor both named after the zone -- the later group overwrote
the earlier one in the .npz, and load_matrices restored the wrong array into
the survivor without any error. Downstream this manifests as degenerate
view matrices and noise-floor DGP values with no exception.
Namespace the keys per group (view_/sensor_/surface_) and stamp the file
with '_schema_version' = 2. Legacy (v1) files remain loadable when their
entity names do not collide; a colliding legacy file now raises ValueError
with a pointer to regenerate, instead of silently returning corrupt data.
Adds tests: roundtrips with colliding names for all three phase methods
(shapes and contents preserved), legacy-file compatibility, and the
legacy-collision error path.
There was a problem hiding this comment.
Pull request overview
Fixes silent matrix-cache corruption when view/sensor/surface entity names collide by namespacing cache keys per group and introducing a cache schema marker to distinguish legacy files.
Changes:
- Add schema v2 cache format with group-namespaced keys (
view_,sensor_,surface_) and write_schema_version = 2into newly saved caches. - Update matrix-cache load paths to support both v2 caches and collision-free legacy (v1) caches; legacy caches with colliding names now raise
ValueErrorinstead of silently loading corrupt data. - Add regression tests covering v2 roundtrips with colliding names across Two/Three/Five-phase methods plus legacy compatibility/error-path behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
frads/methods.py |
Introduces schema v2 namespacing for matrix-cache keys, adds _schema_version, and updates load/save logic to avoid collisions and detect legacy caches. |
tests/test_matrix_cache.py |
Adds regression tests for collision-safe roundtrips and legacy cache handling. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+562
to
+563
| if "_schema_version" in mdata: | ||
| return "view_", "sensor_", "surface_" |
Collaborator
|
Thanks. I'd probably try to do something cleaner and bump the cache format that would require users to regenerate all the matrices. I will keep this open for now while working on a solution. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
save_matrices keyed all per-entity matrices by bare entity name:
'{name}_sky_matrix' (TwoPhase, views AND sensors), '{name}_window_matrix'
(ThreePhase: views, sensors AND surfaces; FivePhase: views and sensors) and
'{name}_sun_direct_matrix' (FivePhase). When two groups share a name -- e.g.
a view and a sensor both named after the zone -- the later group overwrote
the earlier one in the .npz, and load_matrices restored the wrong array into
the survivor without any error. Downstream this manifests as degenerate
view matrices and noise-floor DGP values with no exception.
Namespace the keys per group (view_/sensor_/surface_) and stamp the file
with '_schema_version' = 2. Legacy (v1) files remain loadable when their
entity names do not collide; a colliding legacy file now raises ValueError
with a pointer to regenerate, instead of silently returning corrupt data.
Adds tests: roundtrips with colliding names for all three phase methods
(shapes and contents preserved), legacy-file compatibility, and the
legacy-collision error path.