simulation-dev
Skill351 starsChanged 3 months agoApache-2.0View on GitHub
General simulation development best practices for correctness, stability, and debuggability. Use when implementing or modifying simulation systems, solvers, constraints, or GPU kernels, especially for index safety, NaN/Inf issues, and diagnostics.
In this repository19 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- .cursor/rules/cpp-format.mdcCursor rule
- .cursor/rules/self-improvement.mdcCursor rule
- cmake-workflowSkill
- commit-conventionSkill
- commitSkill
- cursor-rulesSkill
- documentSkill
- fix-issueSkill
- fix-prSkill
- formatSkill
- github-prSkill
- gpu-optimizationSkill
- project-structureSkill
- push-tagSkill
- repository-setupSkill
- review-prSkill
- run-testsSkill
- xmake-workflowSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
27 rules. About 0 are common, 19 are distinctive, and 8 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈19
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
- Distinctive: line 10
Follow the owner working agreements, especially CUDA rules 9-16.
- Distinctive: line 15
Use this skill when:
- Very specific: line 26
Use named raw-CUDA kernels and the in-tree cuda_tool diagnostics.
- Distinctive: line 35
Verify assumptions at boundaries (API input, scene load, assembly, solver entry).
- Very specific: line 36
Use clear sentinel conventions and assert them (-1, empty, null, etc.).
- Distinctive: line 42
Prefer host-side prevalidation to avoid propagating bad mappings into kernels.
- Very specific: line 46
Check for finite values (isfinite) at key checkpoints.
- Distinctive: line 48
Add conservative guards for divide-by-near-zero and invalid square roots/logs.
- Distinctive: line 52
Every assertion should answer:
- Distinctive: line 62
keep wording short and actionable.
- Very specific: line 66
Use UIPC_KERNEL_ASSERT and the UIPC_KERNEL_* diagnostics from src/backends/cuda/cuda_tool/debug.h.
- Very specific: line 68
Use named __global__ functions and raw <<<grid, block, 0, stream>>> launches so logs and profiler symbols identify the owning subsystem.
- Very specific: line 70
Use cuda_tool::BufferView / CBufferView and sparse-matrix views for GPU buffers.
- Very specific: line 72
Keep optional dumps for critical vectors, matrices, topology maps and frame/ iteration context.
- Distinctive: line 74
Use scoped timers around hot phases, outside CUDA-graph capture.
- Distinctive: line 81
Keep index guards before memory access and validate finite intermediates.
- Very specific: line 82
Use cuda_tool::debug_sync_all() at diagnostic boundaries to attribute errors.
- Distinctive: line 86
Keep kernel launch sizing through the existing occupancy helpers and their per-kernel-address cache.
- Distinctive: line 103
Use this loop as the default process for debugging simulation issues:
- Distinctive: line 106
Use diagnostics to understand behavior, form a concrete assumption, then add debug code to validate that assumption.
- Distinctive: line 107
After validating the assumption, implement the fix in the minimal case first.
- Distinctive: line 109
Add a regression test for the confirmed fix.
- Distinctive: line 111
If any step fails or new evidence contradicts the assumption, return to step 1 or 2 and iterate until root cause and fix are both confirmed.
- Distinctive: line 125
Write/modify logic with invariants first.
- Distinctive: line 126
Add assertions at boundaries and first-use sites.
- Distinctive: line 127
Add diagnostics (timers, buffer names, optional dumps).
- Distinctive: line 132
Only then profile and optimize.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 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
Simulation Development Best Practices
General rules for building simulation code that is correct first, debuggable second, and fast third.
Follow the owner working agreements, especially CUDA rules 9-16. MUDA is removed; do not restore its dependency, wrappers, or compatibility layer.
When to Use
Use this skill when:
- adding or modifying simulation systems, solvers, integrators, constraints, or contact logic,
- touching CPU/GPU compute paths that can fail from invalid indices or unstable numerics,
- debugging crashes, divergence, NaN/Inf, or non-deterministic behavior,
- improving diagnostics, assertions, and reproducibility.
Core Principles
- Correctness before performance.
- Fail fast on invalid states.
- Reproduce with fixed inputs while preserving parallel execution.
- Use named raw-CUDA kernels and the in-tree
cuda_tooldiagnostics. - Validate data at subsystem boundaries.
- Instrument first, optimize after evidence.
Safety Rules (Always Apply)
Input and shape validation
- Validate counts, offsets, dimensions, and index ranges before compute.
- Verify assumptions at boundaries (API input, scene load, assembly, solver entry).
- Use clear sentinel conventions and assert them (
-1, empty, null, etc.).
Index safety for GPU/parallel code
- Guard every computed index before read/write.
- Return early on invalid thread work instead of continuing with partial writes.
- Prefer host-side prevalidation to avoid propagating bad mappings into kernels.
Numerical robustness
- Check for finite values (
isfinite) at key checkpoints. - Assert on first invalid scalar near source (residuals, energies, step sizes, norms).
- Add conservative guards for divide-by-near-zero and invalid square roots/logs.
Assertion Best Practices
Every assertion should answer:
- What failed?
- Where in the pipeline?
- With what values?
- What is the likely cause?
Checklist for high-quality assert messages:
- include stage/iteration/frame context,
- include offending value and expected range/invariant,
- include at least one hint for root-cause direction,
- keep wording short and actionable.
Diagnostics and Observability
- Use
UIPC_KERNEL_ASSERTand theUIPC_KERNEL_*diagnostics fromsrc/backends/cuda/cuda_tool/debug.h; kernel assertions followuipc::RUNTIME_CHECK. - Use named
__global__functions and raw<<<grid, block, 0, stream>>>launches so logs and profiler symbols identify the owning subsystem. - Use
cuda_tool::BufferView/CBufferViewand sparse-matrix views for GPU buffers; pass explicit counts/offsets and report their values on failure. - Keep optional dumps for critical vectors, matrices, topology maps and frame/
iteration context. Do not use removed
.name()orfile_line()wrappers. - Use scoped timers around hot phases, outside CUDA-graph capture. Gate debug dumps and synchronization so the normal path retains its existing overhead.
CUDA Debug Checklist
For each touched GPU code path:
- Keep index guards before memory access and validate finite intermediates.
- Use
cuda_tool::debug_sync_all()at diagnostic boundaries to attribute errors; remove or gate these barriers after diagnosis. - Reuse persistent CUB workspace and preserve buffer initialization contracts
(
resize,resize_discard,resize_preserve). - Keep kernel launch sizing through the existing occupancy helpers and their per-kernel-address cache.
- Preserve stream dependencies and fill every reported gradient/Hessian slot.
Reproduction Workflow
- Reproduce on the smallest failing case with fixed inputs and random seeds.
- Compare isolated runs with the single-process aggregate to detect global-state pollution; preserve existing concurrent assembly and solver paths.
- Enable strict checks and locate the first invalid value or missing dependency.
- Bisect by pipeline stage (assemble -> solve -> update).
- Distinguish an algorithmic error or synchronization defect from rounding due solely to valid atomic-add arrival order. Do not add sorting, fixed-order reductions or serialization merely to obtain bitwise-identical trajectories.
Simulation Debug Loop (Iterative)
Use this loop as the default process for debugging simulation issues:
- Build a minimal reproducible scene/case that is easy to debug.
- Use diagnostics to understand behavior, form a concrete assumption, then add debug code to validate that assumption.
- After validating the assumption, implement the fix in the minimal case first.
- Re-run the original scene/case to verify the real issue is resolved.
- Add a regression test for the confirmed fix.
If any step fails or new evidence contradicts the assumption, return to step 1 or 2 and iterate until root cause and fix are both confirmed.
During active GPU debugging, insert cuda_tool::debug_sync_all() at key boundaries to stop immediately when a kernel fails, then remove or gate it once diagnosis is complete.
Convergence and Stability Guidelines
- Separate stopping criteria from failure criteria.
- Distinguish "did not converge yet" from "invalid state".
- Track monotonic indicators where expected (energy, residual envelopes).
- For iterative methods, sample/check periodically to limit synchronization overhead.
- Provide explicit fallback or abort policy for non-convergence in strict mode.
Change Workflow
- Write/modify logic with invariants first.
- Add assertions at boundaries and first-use sites.
- Add diagnostics (timers, buffer names, optional dumps).
- Verify on:
- minimal case,
- representative case,
- stress case.
- Only then profile and optimize.
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.

