Skip to content

feat: Hilbert and knapsack placement with measured costs; markers in one pass - #76

Merged
max-models merged 21 commits into
develfrom
claude/tree-d3d-poison-maxwell-atyjic
Nov 25, 2026
Merged

max-models merged 21 commits into
develfrom
claude/tree-d3d-poison-maxwell-atyjic

Conversation

@max-models

@max-models max-models commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Summary

Load balancing:

  • placement="hilbert" places patches along a Hilbert curve (cunumpy's hilbert_encode). Each rank's run is connected, without the Z curve's jumps.
  • morton_ranks is now curve_ranks(..., curve="morton" | "hilbert").
  • placement="balanced" also takes cost, cut by knapsack_ranks: the largest cost first, onto the least loaded rank.
  • cost may also map a patch (level, box) to a measured cost. deposit(..., times=...) and interpolate(..., times=...) collect seconds per patch; a patch without a measurement gets the mean cost per cell.
  • rebalance(cost, placement=...) places by any of these.

Per-patch costs:

  • The cloud-in-cell deposit and interpolate add the markers of all patches in one pass: one bincount into a buffer of the blocks, equal to mpifield's kernels to 1e-12 (new test, periodic axes included). Higher B-spline degrees still run the kernels patch by patch.
  • A marker's owner rank comes from a table when its patch is on one rank.
  • Halo signatures test all patches of a level against each other at once.

RESULTS.md compares against devel, together with max-models/mpiarray#74 (one gather and scatter per array in CopyPlan). Serial, median of 3, ms per step:

mesh devel this
clusters 228 217 (−5%)
clusters cut to 16 cells 450 356 (−21%)
quadtree, block 8 661 486 (−26%)
quadtree, block 16 416 308 (−26%)
quadtree, block 32 406 355 (−13%)

This needs max-models/cunumpy#146 (hilbert_encode); merge that first. The halo numbers need max-models/mpiarray#74.

Checklist

  • pre-commit run and pytest pass (738 passed locally, the new tests also under mpirun -n 2/3/4)
  • New code has docstrings and tests
  • The docs (docs/, tutorials or README.qmd) are updated where the behaviour changed
  • The commit messages follow Conventional Commits (feat:, fix:, docs:, ...)

…, owners by rank table, and regrid(fields=).

Copy link
Copy Markdown
Owner Author

The pytest jobs fail only in test_hilbert_runs_are_contiguous_and_balanced and test_measured_times_per_patch_weigh_the_placement, with AttributeError: module 'cunumpy.algorithms' has no attribute 'hilbert_encode'. The other 709 tests pass. CI installs cunumpy from devel, which gets hilbert_encode with max-models/cunumpy#146. After that merges, rerun this PR's CI. The pyright errors are fixed in 9416ba5; the hilbert_encode one has the same cause.


Generated by Claude Code

@max-models
max-models merged commit 42ef6a8 into devel Nov 25, 2026
25 of 36 checks passed
Sign up for free to 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.

1 participant