snapy-multi-block-output
Skill4 starsChanged 8 months agoMITView on GitHub
Debug multi-MeshBlock-per-process bugs in snapy, especially geometry partitioning, process-group lifecycle, and output combining.
In this repository15 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- cross-repo-readSkill
- disortSkill
- paddle-examplesSkill
- repo-routerSkill
- snapy-multi-block-outputSkill
- thermodynamicsSkill
- tutorial-styleSkill
- cross-repo-readSkill
- disortSkill
- paddle-examplesSkill
- repo-routerSkill
- thermodynamicsSkill
- tutorial-styleSkill
The file
We split this skill into the rules it gives an agent
11 rules. About 0 are common, 3 are distinctive, and 8 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
8
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 8
Use this skill when repos/snapy is running more than one MeshBlock on the same process and behavior differs from the one-block-per-process …
- Very specific: line 15
If 1x1 matches Nx1 but not 1xN, inspect same-process assumptions before changing backend communication.
- Distinctive: line 17
Check that each local block has a distinct global block rank and that geometry/coordinate partitioning is recomputed from that block rank.
- Very specific: line 19
Check process-group lifetime and shutdown paths for duplicate collectives or duplicate shutdown() calls from multiple local blocks.
- Very specific: line 41
When a Python driver is migrated from MeshBlock to Mesh, update both the constructor path and the runtime loop.
- Very specific: line 47
Prefer bound Python surfaces over old implicit/runtime attributes: block.options.device_str() instead of block.device(), …
- Very specific: line 51
Follow the paddle Python driver pattern for time stepping: keep an explicit cycle, call mesh.set_cycle(cycle), use mesh.forward(vars, dt, …
- Very specific: line 54
Keep per-block custom physics after mesh.forward(...) if the forcing or source term is still applied block-by-block.
- Very specific: line 78
Prefer fixing shared Mesh orchestration and output code over adding case-specific workarounds in examples.
- Distinctive: line 80
Treat duplicated coordinates in merged NetCDF as an upstream geometry/output bug, not a physics discrepancy.
- Distinctive: line 84
Keep trial runs short first.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Snapy Multi-Block Output
Use this skill when repos/snapy is running more than one MeshBlock on the
same process and behavior differs from the one-block-per-process case.
Workflow
- Compare three decompositions on the same case:
1 proc x 1 block,1 proc x N blocks, andN proc x 1 block. - If
1x1matchesNx1but not1xN, inspect same-process assumptions before changing backend communication. - Check that each local block has a distinct global block rank and that geometry/coordinate partitioning is recomputed from that block rank.
- Check process-group lifetime and shutdown paths for duplicate collectives or
duplicate
shutdown()calls from multiple local blocks. - Check output-combine timing: combine once per process only after all local block files for that output step exist.
- Validate merged outputs numerically across decompositions and inspect merged coordinates for monotonicity and duplication.
Common Failure Modes
- Coordinate options are partitioned from env rank before
Meshrewrites the local block's global rank, so multiple local blocks write the same spatial slab. - Output combine runs once per block instead of once per process, so process- local files are merged too early or by the wrong root.
- Shared process-group shutdown is executed by each local block, which can abort NCCL or deadlock Gloo near finalize.
- Standalone
MeshBlock::initialize()exchange logic is reused block-by-block underMesh, causing deadlocks because local-copy orchestration is bypassed.
Python Driver Migration Notes
- When a Python driver is migrated from
MeshBlocktoMesh, update both the constructor path and the runtime loop; partial migrations tend to fail on stale bindings rather than on physics. - Construct from
MeshOptionsandMesh, then treatmesh.blocksas the local per-process blocks for block-specific setup like initialization or forcing. - Prefer bound Python surfaces over old implicit/runtime attributes:
block.options.device_str()instead ofblock.device(),layout.options.rank()instead oflayout.rank(), andintg = mesh.module("block0.intg")instead ofblock.intg. - Follow the
paddlePython driver pattern for time stepping: keep an explicitcycle, callmesh.set_cycle(cycle), usemesh.forward(vars, dt, stage), and stop withintg.stop(cycle, time). - Keep per-block custom physics after
mesh.forward(...)if the forcing or source term is still applied block-by-block. - Validate launch topology together with the API migration:
process_world_size * blocks_per_processmust match the layout's expected global block count. For cubed-sphere that meansworld_size * blocks_per_process == 6. - For smoke tests, start with a reduced slab config to verify Python binding
assumptions on one GPU, then run a short
torchrun --nproc_per_node=2test for the real2 GPUs x 3 blocks/processcubed-sphere path.
NCCL Multi-Block Note
- For NCCL with multiple
MeshBlocks per process, point-to-point tags are not a reliable discriminator the way they are with Gloo. - For cubed-sphere multi-block-per-process runs, per-block
send/recvlaunch is insufficient even if local copies and topology are correct. - The durable fix pattern is:
route cubed-sphere exchange through the shared
Layout::launch_exchange()path, order remote ops by actual exchange-loop order rather than buffer id, and for NCCL launch remote work process-wide across all local blocks sorecv/sendposting order is identical on both processes.
Guardrails
- Prefer fixing shared
Meshorchestration and output code over adding case-specific workarounds in examples. - Treat duplicated coordinates in merged NetCDF as an upstream geometry/output bug, not a physics discrepancy.
- Validate both
glooandncclwhen the change touches communication or output ownership. - Keep trial runs short first; only start full runs after the three decomposition variants match exactly.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

