agentleFS
90184479018447/julia-pro-p/skills/debugging-toolkit/SKILL.md

debugging-toolkit

Skill0 starsChanged 2 days agoMITView on GitHub

Numerical debugging in Julia: localise the first wrong value, rule dtype and precision in or out, then fix the cause. Use when a Julia program fails or returns a wrong number.

The file

Files
SKILL.md

Numerical debugging

A wrong number is a different failure from a crash: there is no stack, no exception, and the line that produced it ran without complaint. The work is to find the first place the value diverges from what it should be, which is why the order below starts at reproduction and not at a hypothesis.

The order

StepDone when
Reproducethe same wrong value comes out of a seed plus one minimal input, in the environment recorded with it
Localisethe first line where the value diverges is named, with the value before and after
Rule precision in or outthe same run in Float64 either changes the answer or does not, and that is stated
Bisectthe commit that introduced it is identified, not guessed
Fix the causethe reproduction goes green with the fix and stays red without it

The localisation step is where most time goes and where most shortcuts fail: bisecting inside a function range finds a suspect but not a line, and a suspect gets rewritten.

Julia

@code_warntype f(x)     # Any or Union in the body: the instability is here
@inferred f(x)          # fails in the test suite instead of in production
@allocated f(x)         # bytes per call; 0 means allocation-free
@btime f($x)            # time and allocations, via BenchmarkTools
using Debugger; @enter f(x)   # step through when reading is not enough

A type instability shows up as a boxed value and a 10-100× slowdown long before it shows up as a wrong answer, so it is worth checking whenever a numerical function is slower than its arithmetic.

NaN and infinity

SignalLikely causeCheck
NaN at step 1 to 3learning rate or an unnormalised inputrun one step with the rate divided by 100
NaN spreading from one variabledivide by zero or log(0)clip the argument, print the argument not the result
inf then NaNoverflow in Float32 (finfo.max ≈ 3.4e38)rerun in Float64; if it survives, the model is wrong, not the dtype
gradient exploding, value finelong product of Jacobiansclip by global norm, then check whether the clip is doing the work
NaN only at the boundarymasked or padded entries entering a reductionprint the mask, not the tensor

Reproducibility

Pin the seed, the dtype, and the thread count before comparing two runs; a difference that survives all three is a real difference. A threaded reduction can change the last bits with the thread count, which is why a race is compared against the serial run before the code is blamed.

Done when

The failure reproduces from a seed and a minimal input; the first wrong value is localised to a line rather than a function; precision and dtype are ruled in or out by rerunning in Float64; the change that introduced it is identified by bisect; and the reproduction turns green with the fix while staying red without it.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.