Skip to content

Add the terrain store: region grids and tile cache - #55

Open
mouftz wants to merge 3 commits into
mainfrom
store-region-grids
Open

Add the terrain store: region grids and tile cache#55
mouftz wants to merge 3 commits into
mainfrom
store-region-grids

Conversation

@mouftz

Copy link
Copy Markdown
Contributor

Summary

Implements the Terrain Store (#31) — all six sub-tickets in one PR, since
the two halves are small and share a module.

Adds numpy (2.5.2) as the project's first runtime dependency, per
CONTRIBUTING: pyproject.toml and uv.lock are both committed.

Validation

  • scripts/quality-check.sh passes locally
  • Appropriate /test commands were run and are passing (e.g. /test gpu)
  • Unit tests were added / e2e tests were added where applicable
  • Manual testing, if applicable (describe further):

27 tests in tests/test_store.py, covering every assertion listed in
#40#45. The overlap test uses the worked 1×6 example from #31 directly.
Full suite is 68 passed.

Checklist

  • The change is focused and easy to review.
  • Tests were added or updated for behaviour changes.
  • No secrets, generated files, or files that only make sense on my machine are included.
  • Relevant documentation is updated.

Additional Comments

Two decisions worth a second opinion:

  • put copies the incoming array so the generator can reuse its buffer,
    but get hands back the cache's own grid rather than a copy — copying
    on every read would undo the point of caching. Callers should treat a
    returned tile as read-only. Happy to change this if you would rather it
    be defensive on both sides.
  • Disk persistence is mentioned in the module docstring but has no
    sub-ticket, so it is not implemented here.

Closes#40, #41, #42, #43, #44, #45

@mouftzmouftz self-assigned this Aug 23, 2026
@coveralls

coveralls commented Aug 23, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 33993292664

Coverage increased (+0.7%) to 98.525%

Details

  • Coverage increased (+0.7%) from the base build.
  • Patch coverage: 241 of 241 lines across 2 files are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines:746
Covered Lines:735
Line Coverage:98.53%
Coverage Strength:0.99 hits per line

💛 - Coveralls

@mouftz
mouftzforce-pushed the store-region-grids branch from d974f1c to 1ea3053CompareAugust 23, 2026 15:07
@mouftz
mouftz requested a review from KurbyDooAugust 23, 2026 18:28

@KurbyDooKurbyDoo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed some of the specifications of the original tickets since they don't really match what I'm thinking anymore, could you update this PR accordingly? Thanks

Comment threadsrc/terrain_diffusion/store.py Outdated
Comment threadsrc/terrain_diffusion/store.py Outdated
@mouftz
mouftz requested a review from KurbyDooSeptember 5, 2026 21:32

@KurbyDooKurbyDoo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

structure looks good overall!

please remove all comments that are not nessasary, it makes the code hard to read and confusing / misleading for future editors. ideally behaviour should be obvious from variable and function names and comments should only be used for when the reason for doing something is not clear. comments should also not reference issue numbers or talk about things that do not exist in the codebase / are not implemented yet

also add the coverage file to gitignore thanks

"""
self._tiles[seed] = np.array(tile)
self._tiles.move_to_end(seed)
def _drop_least_recently_used(self) -> None:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename this function to something more clear, right now its not obvious that this function does the capacity check in addition to dropping

Comment threadtests/test_store.py
assert weights.sum() == 4


def test_adding_the_same_window_twice_doubles_it() -> None:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is incorrect behaviour we dont want to enforce in testing, in practice we never want to add the same window twice. remove this test, in a follow up, we will enforce not adding duplicate windows

Comment threadtests/test_store.py
OTHER_SEED = 5678


def a_store(tile_height: int = 4, tile_width: int = 4, capacity: int = 8) -> TerrainStore:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you make this a pytest fixture instead? fixures are pytests way of naming objects that reset every test within a test suite

"not built yet, see #56"
)

sums, tile_weights = self.grids(seed, x, y)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if we add a window that goes over the tile edge? shouldnt we be storing the weights and product in the adjacent tiles?

Comment threadtests/test_store.py
def test_a_window_that_hangs_off_the_edge_is_refused(row: int, col: int) -> None:
"""numpy slices clip rather than complain, so this has to be caught by hand."""
grids = RegionGrids(4, 4)
def test_a_window_that_crosses_the_edge_of_a_tile_is_refused(row: int, col: int) -> None:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you implement the behaviour for splitting windows across tiles, then change this test to validate that behaviour instead

Comment threadtests/test_store.py
cache = TileCache(capacity=4)
tile = np.arange(9.0).reshape(3, 3)
def fill(store: TerrainStore, seed: int, x: int, y: int, value: float) -> None:
"""Cover a whole tile with one value, so it can be read back."""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there should be some way for this to be handled cleanly with pytest rather than making it a function, similar to fixtures, can you look in to this?

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create empty sum and weight grids for a region

3 participants

@mouftz@coveralls@KurbyDoo