Skip to content

Yh cyber windowed blending sampler - #53

Open
yh-cyber wants to merge 22 commits into
mainfrom
yh-cyber-windowed-blending-sampler
Open

Yh cyber windowed blending sampler#53
yh-cyber wants to merge 22 commits into
mainfrom
yh-cyber-windowed-blending-sampler

Conversation

@yh-cyber

@yh-cyber yh-cyber commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Summary

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): added test_sampler file to add unit tests, all pass

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

I think there might be something wrong with scripts/quality-check.sh for me.

This is what I got when I ran scripts/quality-check.sh

$ scripts/quality-check.sh
==> Checking formatting (ruff format --check)
17 files already formatted

==> Checking code style (ruff check)
error: a value is required for '[FILES]...' but none was supplied

For more information, try '--help'.

Found style problems. Many can be fixed automatically with:
  scripts/format-check.sh --fix
(terrain-diffusion) 


$ uv run ruff check src tests
All checks passed!
(terrain-diffusion) 

@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 32536161368

Coverage increased (+1.2%) to 97.921%

Details

  • Coverage increased (+1.2%) from the base build.
  • Patch coverage: 189 of 189 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: 529
Covered Lines: 518
Line Coverage: 97.92%
Coverage Strength: 0.98 hits per line

💛 - Coveralls

@KurbyDoo KurbyDoo 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.

overall the structure looks good, just some things to clean up function boundaries and make testing easier

column_distance = np.abs(columns - center_column)

# weight: apply formula. multiplied 0.9 so values stay above 0
row_weight = 1 - 0.9 * row_distance / (height / 2)

@KurbyDoo KurbyDoo Aug 22, 2026

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.

should this be (height - 1) / 2 and (width - 1) / 2? If so reuse center_row and center_column

) -> list[tuple[int, int]]:
"""Takes a region height and width, a window size, and a step size, and returns the list of top left positions to place windows at.
The step is smaller than the window, which is what makes them overlap.
If step does not divide evenly (extends), push last window to row/column of region_cl/row - window_size, so that no window hangs over the edge."""

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.

Lets change this to assert that the region is divisible by the window size, this will simplify the function body

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.

so throw an error if the window is not divisible

return positions


def weight_grid(height: int, width: int) -> np.ndarray:

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.

if the window size is always going to be square, lets change the parameters to only take in an edge length

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.

then we can simplify the body below to not compute separately for columns and rows

seed: int, height: int, width: int, window_size: int, step: int, pipeline, store
) -> np.ndarray:
"""Make noise canvas of given dimensions. Make noise and weight grid.
For each window position, cut the window out of the noise canvas, send it to pipeline (#23), add the processed output and its weight to Terrain Store (at that position).

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 clean up the comments to avoid referencing the issue numbers


processed_patch = pipeline.generate(
window
) # based on unmerged commit i believe this will be pipeline.generate(window)

@KurbyDoo KurbyDoo Aug 22, 2026

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.

should be merged now, could you rebase to verify?
sorry nevermind it isn't merged and similar to the store, I think we want to change this to not take in a pipeline object, see the comment on the header of this function

window
) # based on unmerged commit i believe this will be pipeline.generate(window)

store.add(processed_patch, row, column, weights)

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 the interface for store might be a bit different, but this is fine for now

Comment thread tests/test_sampler.py
def test_greater_zero(self):
"Assert every value is greater than zero"
weights = weight_grid(10, 20)
assert np.all(weights > 0)

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 add a test with concrete values, pick a 9x9 region with 3x3 window size and assert the window matches to a deterministic 9x9 grid

return weights


def starting_noise(seed: int, height: int, width: int) -> np.ndarray:

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 rename to something general to what the function does? like generate_noise_from_seed or something

Comment thread tests/test_sampler.py
assert noise.shape == (height, width)


class FakePipeline:

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.

nit: you can call objects "Mocks" if they are fake representations of a object to be built later

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.

actually, can you look into the mocker pytest fixture to generate mocks for these objects instead of creating new classes?

return generator.random((height, width))


def produce_region(

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.

lets not pass the store into this function, instead make the function return the weight and weighted sum grid. the caller of this method should be responsible for caching in the terrain store afterwards, this way we can avoid making mocks for the store in this change

@KurbyDoo KurbyDoo Aug 22, 2026

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.

~~and same with the pipeline, this function looks like its trying to do what generation orchestration does ~~
for now lets keep the pipeline but remove the store, we can change this later

@KurbyDoo

Copy link
Copy Markdown
Member

I have a fix for the script error? Could you take a look #54

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

Labels

None yet

Projects

None yet

3 participants