Lab note · August 30, 2026

The Paper Is the Program: MechDSL Goes Public

MechDSL — a compiler that takes finite-element problems written in LaTeX and emits GPU solver code — is now public, along with its browser workbench. Here is what it does, what it refuses to promise, and why the pseudocode in the paper is now literally the kernel on the GPU.

MechDSLFEMLaTeXcode generationTaichicomputational mechanicsopen source

The Paper Is the Program

Hand-drawn diagram: scrolls of governing equations, weak forms, tensor notation, and pseudocode feed a geared machine labeled MechDSL Compiler, which emits a scroll of GPU solver code wired into a GPU chip.
Banner: LaTeX goes in, GPU kernels come out. Illustration generated with Nano Banana (Gemini), which explains why the emitted code on the scroll does not, itself, compile.

TL;DR

MechDSL is a compiler whose source language is LaTeX. You write a finite-element problem the way you would write it in a paper — tensor math, a strain-energy density, a few directives — and it compiles through a symbolic pipeline into deterministic GPU solver code. Its companion, algo2code, transpiles LaTeX algorithm boxes into executable kernels, and in v0.2.0 the radial-return update and the PCG solver running on the GPU literally are the transpiled pseudocode. Both repositories are now public under CEmM2, MIT licensed, on PyPI (pip install mechdsl-core), with a verification suite pinned to closed-form and literature references. It will not replace your production solver. It was never asked to.

The Translation Tax

Every computational mechanics paper contains a complete, precise specification of a solver. The energy functional is there. The weak form is there. The return-mapping algorithm sits in a tidy algpseudocode box, numbered and labeled, wanting for nothing. The field has, over several decades, converged on exactly one language in which everyone agrees to be precise, and that language is LaTeX.

And then the ritual begins. Someone — statistically, a graduate student with three months of optimism — translates that specification into ten thousand lines of C++, where the physics is lovingly smeared across assembly loops, the Voigt convention changes twice without announcement, and the return map acquires an off-by-one that will be discovered at a conference, by a stranger, during the questions. The next person to extend the code must first reverse-engineer the math back out of it, which is how one paper generates employment for three cohorts.

MechDSL starts from the observation that this translation step is not a law of nature. The paper is the program. It just needed a compiler.

What It Actually Does

MechDSL is a compiler whose source language is LaTeX. You write the problem the way you would write it for a journal that enforces notation: tensor expressions in Einstein notation, a strain-energy density, % mechanics directives for the element, formulation, material parameters, and boundary conditions. Then mechdsl.compile_latex(source) takes it through a six-layer pipeline: a symbolic frontend built on SymPy and NRPyLaTeX, a mechanics-level intermediate representation, an element-level IR, einsum-based contraction optimisation with a JIT budget that refuses to emit kernels the compiler cannot afford, and deterministic code emission targeting Taichi for GPU execution. MFEM and MOOSE emission exist as experimental backends, because the IR was designed to be framework-agnostic and we intend to hold it to that.

The part I am most attached to is the algorithm side. The companion package, algo2code, transpiles LaTeX algpseudocode boxes — a radial-return map, a preconditioned conjugate-gradient loop, a Newmark integrator — directly into executable Taichi, NumPy, or C. In v0.2.0 this is not a demo one shows and then quietly disables. The J2 radial-return kernel and the PCG solver that the Newton driver can use are the transpiled algorithms, injected over a lean runtime through explicit solver and operator seams, with no NumPy loitering in the hot paths. The algorithm box in the paper and the kernel on the GPU are the same artifact. If the pseudocode is wrong, the simulation is wrong, which sounds like a threat but is in fact the entire point: there is now exactly one place to be wrong.

What Ships, and What It Refuses to Promise

v0.2.0 covers Total and Updated Lagrangian formulations, convected curvilinear coordinates, and a material catalog that runs from St. Venant–Kirchhoff and J2 power-law plasticity through Neo-Hookean, Mooney-Rivlin, Ogden, HGO anisotropy, Perzyna and Johnson-Cook viscoplasticity, and Lemaitre damage. Elements: Hex8 in the stable core; Hex8-reduced with hourglass control, Hex20, Tet4, and Tet10 in the experimental tier.

The word "tier" is doing honest work in that sentence. MechDSL ships with a two-tier support policy written directly into the README: an MVP-stable core we commit to keeping stable, and an experimental tier that is clearly labeled as such and may shift without a period of public mourning. Readers of this blog will recognize this as the same accounting complaint I make about everyone else's papers, applied to my own repository, which seemed only fair.

The same instinct explains the verification suite. Every claim is gated by comparisons against things that do not care about our feelings: patch tests, rigid-body motion, a cantilever against Euler–Bernoulli, a thick cylinder against Lamé, a necking bar against Simo & Hughes, an HGO strip against the closed form, and automatic-differentiation oracles cross-checking every stress tangent. If the compiler emits something that disagrees with Lamé, the compiler loses. Lamé has seniority.

A Workbench, So You Don't Have to Trust Me

There is also mechdsl-workbench, a small browser workbench: LaTeX on the left, the compiled mechanics or transpiled algorithm on the right. It exists because "read our six-layer IR documentation" is not an invitation, it is a homework assignment. Paste in an energy density, watch what comes out, and form your own opinion at a safe distance from my enthusiasm.

Why Public, and Why Now

MechDSL is developed in our group as both a research tool and a teaching instrument. The gap between "I can derive the return map" and "I can implement the return map" is where most graduate students lose a semester, and it is a strange gap to defend, since the derivation was the intellectually interesting part. Making the mirrors public means students and collaborators can read, run, extend, and — the category I most want — file issues where the language does not yet say what the paper says. A DSL is a bet about what a field's notation actually means; the fastest way to lose that bet honestly is in public.

To try it:

pip install "mechdsl-core[verify]"          # the full engine (Taichi included — sizeable)
pip install mechdsl-core                    # or just emission: LaTeX in, solver source out
pip install "mechdsl-workbench[mechdsl]"    # or the browser workbench with the engine inside

From source, if you prefer to watch the machinery:

git clone https://github.com/CEmM2/MechDSL.git
cd MechDSL && uv sync --all-packages
uv run python examples/run_compile_latex.py

Docs: cemm2.github.io/MechDSL · MIT licensed. Bring your favorite constitutive model and your least favorite index convention. We take both.