Skip to content

xeus-based Jupyter kernel for Mathilda (#78) - #84

Closed
stblake wants to merge 2 commits into
mainfrom
mathilda-xeus
Closed

stblake wants to merge 2 commits into
mainfrom
mathilda-xeus

Conversation

@stblake

@stblake stblake commented Oct 1, 2026

Copy link
Copy Markdown
Owner

Summary

A native xeus-based Jupyter kernel for Mathilda (addresses #78), built and
validated end-to-end against xeus 6.0.6. It embeds the evaluator in process via
Mathilda's C ABI and lets xeus handle the Jupyter wire protocol — no Python
dependency at run time
. It's an interop on-ramp to the standard Jupyter
ecosystem (Lab / Notebook / VS Code / Colab) and complements the Tauri desktop
notebook in frontend/.

What's here

  • src/ffi/mathilda_ffi.{c,h} — a library-resident cell evaluator
    mathilda_ffi_eval_cell: multi-statement cells, Print→stream,
    Head::tag→message, ;/Null suppression, $Line/%/Out[n] history,
    Graphics→Plotly, Image, ?name→usage/names, results with KaTeX LaTeX.
    Plus mathilda_ffi_is_complete and mathilda_ffi_complete. It emits the
    same NDJSON events as repl.c's pipe mode, kept in step by
    make check-pipe-protocol and kernel/test/ffi_cell_test.c.
  • kernel/ — the xeus interpreter, CMake build, kernelspec, README, and
    tests (ffi_cell_test.c for the C layer; kernel_test.py for a full Jupyter
    round-trip via jupyter_client).
  • MathildaXeus.command — a clickable launcher that builds/installs the
    kernel into a conda-forge xeus env and opens JupyterLab.

Validation

kernel/test/kernel_test.py (jupyter_client) and kernel/test/ffi_cell_test.c
both pass: Integrate[x^2,x] → $\frac{1}{3}\,x^{3}$, multi-statement + Print,
1/0→Power::infy on stderr, syntax-error status, Plot[...]→Plotly,
completion, ?name inspect, is_complete, % history. make check-pipe-protocol
and make check-c99 stay green.

Notes for the reviewer / merge

  • No $VersionNumber bump in these commits: src/version.h was mid-edit in
    a parallel working session when this was branched, so the bump + tag were
    deferred. Please bump src/version.h (+0.001) and tag on merge, per CLAUDE.md.
  • This branch is based one merge-base behind main (PR GraphPlot rewritten as a layout engine; new HypergraphPlot ; v0.237 #83 landed meanwhile),
    but the changes are disjoint from those commits, so the merge is
    conflict-free.
  • Follow-ups (documented in kernel/README.md): image/png for Image[], a
    self-contained HTML+plotly.js fallback, and true mid-computation interrupt.

🤖 Generated with Claude Code

stblake and others added 2 commits October 1, 2026 15:44
A native C++ Jupyter kernel (kernel/, "xmathilda") that embeds the evaluator
in process via the C ABI and lets xeus handle the Jupyter wire protocol -- no
Python dependency at run time. Complements the Tauri notebook as a standard-
ecosystem on-ramp.

- src/ffi/mathilda_ffi.{c,h}: library-resident cell evaluator
  mathilda_ffi_eval_cell (multi-statement cells, Print->stream,
  Head::tag->message, ;/Null suppression, $Line/%/Out[n] history,
  Graphics->plot, Image, ?name->usage/names, expr+latex), plus
  mathilda_ffi_is_complete and mathilda_ffi_complete. Emits the same NDJSON
  events as repl.c's pipe mode; held in step by check-pipe-protocol and
  kernel/test/ffi_cell_test.c.
- kernel/: xeus interpreter, CMake build, kernelspec, README, and tests
  (ffi_cell_test.c for the C layer, kernel_test.py for the full Jupyter
  round-trip). Validated end-to-end against xeus 6.0.6.
- MathildaXeus.command: clickable launcher that builds/installs the kernel
  into a conda-forge xeus env and opens JupyterLab.

No $VersionNumber bump in this commit: src/version.h is mid-edit in a parallel
working session, so the bump + tag are deferred to avoid clobbering it.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
A Plot3D surface shades each quad its own colour and overlays a grid wireframe.
graphics3d_to_plotly_json flushed a separate mesh3d trace on every colour change
(one per quad) and a separate scatter3d trace per Line[] wireframe segment, so a
single Plot3D became ~1,700 traces / ~300 KB of JSON. That many separate WebGL
objects hangs the browser tab of any Plotly front end — including the new xeus
Jupyter kernel, where it looked like the notebook "crashed".

Now the whole surface is ONE mesh3d trace carrying per-quad colour via Plotly's
facecolor array, and the whole wireframe is ONE scatter3d trace with segments
separated by JSON null. Plot3D[Sin[x+y],{x,0,3},{y,0,3}] drops from 1,680 traces
to 2 (and 305 KB to 152 KB); it renders identically. Benefits every consumer of
the serializer (xeus kernel, desktop sidecar, mobile FFI).

test_plot3d now asserts the payload stays compact: exactly one mesh3d trace, at
most one scatter3d trace, and a facecolor array (per-quad shading preserved).

No $VersionNumber bump: src/version.h is mid-edit in a parallel session.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@stblake

stblake commented Oct 1, 2026

Copy link
Copy Markdown
Owner Author

Closing as already merged: this branch's content is already fully on main.

The two commits here landed on main earlier via cherry-pick/rebase (new hashes, identical patch-ids), as part of the v0.248 release line (main is now at v0.252):

  • 17b42aa2 (xeus kernel) ≡ 394a34c7 on main — identical patch-id 2e50c42f…
  • 9934887d (Plot3D Plotly trace fix) ≡ 2d229835 on main

Verification: all 15 files are byte-identical to main (same git object hashes), and a computed merge (git merge-tree origin/main mathilda-xeus) yields a tree identical to current main — merging would add nothing. The version-bump/tag note in the PR description is also already satisfied (bumped and tagged at v0.248).

No action needed; the xeus Jupyter kernel (#78) is shipped.

@stblake stblake closed this Oct 1, 2026
@stblake
stblake deleted the mathilda-xeus branch October 1, 2026 10:44
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