md-basics tutorials: statistical mechanics you can watch; DriveFS mount tests + truncation fix#89
Merged
Merged
Conversation
Six new notebooks under md-basics/ — statistical mechanics you can watch, each validated headlessly in a real browser: - 01-maxwell-boltzmann: every atom starts at the same speed; the M-B distribution assembles itself (WCA gas, arcsine → Gaussian vx). - 02-condensation: quench a 2D vapor below coexistence; droplets nucleate and coarsen, colored by pe/atom. Optional KOKKOS "go big" cell with the basics/04 isolation check + fallback. - 03-real-vs-ideal-gas: measure Z = P/ρT across (ρ, T), overlay the second virial coefficient computed in numpy from the pair potential. - 04-reversibility-and-chaos: Loschmidt's paradox live — flip every velocity and un-melt a crystal (RMS return error ~1e-12), then find the chaos horizon where the return fails (positions matched by atom id, since LAMMPS re-sorts atoms in memory). - 05-thermal-conductivity: Müller-Plathe flux + ave/chunk temperature profile read from a file → κ ≈ 6 for the 2D LJ liquid. - 06-polymer-chains: numpy-generated FENE bead-spring data files, Rg ~ N^ν with the Flory exponent from a log-log fit. tests/drivefs-mount.spec.ts unit-tests the DriveFS mount snippet from the Python bindings against the real wasm filesystem with a mocked JupyterLite ContentsAPI — every reachable branch of toAPIPath (all four cwd cases, re-evaluated per call), node_ops, stream_ops, and mounting, plus LAMMPS end-to-end cases (write_dump, ave/time + close, ave/chunk + unfix, read_data of Python-written files, re-run overwrite). The tests exposed a real bug, now fixed: truncation arrives as a node-level setattr size change (Emscripten strips O_TRUNC before stream open), which the proxy ignored — so re-opening an existing output file with "w" kept the stale tail of the previous, longer content. setattr now honors attr.size (shrink, zero, and extend). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Six new tutorials (
md-basics/)Statistical mechanics made visible — each notebook takes one famous piece of physics and makes it happen live in the browser. All simulation decks were prototyped and validated in node against the real wasm first, then every notebook verified headlessly (playwright, real browser, full cell-by-cell execution):
pe/atom)ave/chunkprofile from a file → κLinked from the index page (new section) and
NOTEBOOK_TUTORIALS.md(Series 1 marked partially shipped).DriveFS file-sync: full branch tests + a real bug fix
tests/drivefs-mount.spec.tsextracts the_MOUNT_DRIVEFS_JSsnippet from the Python bindings and unit-tests it against the real wasm filesystem with a mocked JupyterLite ContentsAPI — 33 tests covering every reachable branch:toAPIPath: cwd inside/drive(prefix), exactly/drive, outside/drive,cwd()throwing, and per-call re-evaluationnode_ops: lookup hit/miss, mknod (file + dir), getattr, setattr (mode / timestamp / size), rename, unlink, rmdir, readdir, symlink→EPERM, readlink→EINVALstream_ops: open existing / missing+write (create) / missing+read (ENOENT), close with/without write flags (put vs no-put), read (normal / past-EOF), write (grow / in-place), llseek (SEEK_CUR / SEEK_END / negative→EINVAL), append modewrite_dump,fix ave/time+ close,fix ave/chunk+ unfix,read_data/runFileof store-seeded files, and re-run overwriteBug found and fixed: truncation reaches the filesystem as a node-level
setattr({size})(Emscripten stripsO_TRUNCbefore the stream opens), which the proxy ignored — re-opening an existing output file with"w"kept the stale tail of the previous longer content, so re-running any notebook that writes output files could corrupt them.setattrnow honorsattr.size(shrink / zero / extend), with regression tests for all three.The remaining unreachable branches are defensive fallbacks (documented in the spec header); the pyodide-only Python glue (
_mount_drivefscaching/fallback) is exercised by the headless notebook integration runs.Test plan
npx vitest run tests/drivefs-mount.spec.ts— 33/33npx vitest run tests/lammps.spec.ts tests/client.inject.spec.ts— no regressionsindex,basics/02,basics/05,materials/01— all pass with the fixed bindings🤖 Generated with Claude Code