Skip to content

doc: add enzyme integration demo + blog post#542

Open
dionhaefner wants to merge 32 commits into
mainfrom
dion/enzyme-demo
Open

doc: add enzyme integration demo + blog post#542
dionhaefner wants to merge 32 commits into
mainfrom
dion/enzyme-demo

Conversation

@dionhaefner

@dionhaefner dionhaefner commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

Relevant issue or PR

n/a

Description of changes

  • New demo notebook enzyme-lfortran showcasing how to use Enzyme-differentiated Fortran solvers in optimization tasks via Tesseract + Tesseract-JAX.
  • New example fortran_enzyme explaining (and testing) Enzyme integration into arbitrary Tesseracts.
  • New blog post that outlines how the demo works and explains its significance to a broader (tech) audience.
  • Slightly refactor blog pages so blog post footer is part of the template and does not need to be manually inserted after every blog post.
  • Use {figure} MyST environments instead of <figure> raw HTML in all blog posts.
  • Add some guidance to AGENTS.md that should help agents working on demos in the future.

Testing done

👀, new example + demo pass on CI

@codecov

codecov Bot commented Mar 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.95%. Comparing base (0e08e21) to head (5c7e83d).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #542      +/-   ##
==========================================
+ Coverage   68.30%   77.95%   +9.64%     
==========================================
  Files          39       39              
  Lines        4635     4635              
  Branches      754      754              
==========================================
+ Hits         3166     3613     +447     
+ Misses       1224      716     -508     
- Partials      245      306      +61     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

dionhaefner and others added 22 commits April 16, 2026 23:03
Fix the three failing checks on the Enzyme proof-of-concept PR:

- test-docs: add an explicit MyST anchor to the "What's next" heading in
  the Fortran/Enzyme blog post so the in-page cross-reference resolves
  (Sphinx treats the unresolved-xref warning as an error).

- tests-e2e (enzyme_ad): the e2e harness requires every examples/ dir to
  have a TEST_CASES entry. Add enzyme_ad with check_gradients=True, a
  regression test case (test_cases/test_apply.json) with analytically
  computed expected output, and a check-gradients input. Verified locally:
  the full build + apply + check-gradients + serve test passes.

- tests-demos (enzyme_thermal_2d): the demo lane auto-discovers every
  demo/ dir and runs requirements.txt + demo.ipynb. This dir had neither
  and the notebook loaded pre-built images (including a jax-thermal-2d
  Tesseract absent from this branch). Make it a self-contained, runnable
  demo:
    * add requirements.txt
    * rewrite the notebook as demo.ipynb: build + serve the Enzyme
      Tesseract in-notebook, drive both inverse problems (scalar
      calibration + 900-parameter thermal forensics) with
      jax.value_and_grad through tesseract-jax, and tear down at the end
    * add a Tikhonov term to the forensics loss so the recovered field
      matches the blog (~0.98 correlation)
    * add an abstract_eval endpoint to the 2D tesseract_api.py and make
      the input validators abstract-safe (skip on ShapeDType, drop
      field-level gt constraints that can't apply to abstract scalars) so
      tesseract-jax transforms work

Verified locally: demo notebook executes end-to-end with no errors and
blog-consistent results.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
conf.py copies every demo/*/demo.ipynb into docs/content/demo/, so the new
enzyme_thermal_2d demo notebook needs a toctree entry or the docs build fails
("document isn't included in any toctree", with warnings treated as errors).
Add it to the demos toctree and a description card.

Verified locally: `SPHINXOPTS="-W" make html` succeeds with no warnings.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Realign the blog post with the rewritten demo notebook, which drives both
inverse problems with jax.value_and_grad via Tesseract-JAX rather than the
manual vector_jacobian_product API:

- Introduce apply_tesseract + a solve() helper up front, and use
  jax.value_and_grad in the Part 1 snippet (matching demo.ipynb).
- Fold the standalone "JAX integration via Tesseract-JAX" section into a
  short wrap-up, keeping the swap-for-pure-JAX and layers-of-indirection
  points without re-introducing the code as if it were new.
- Note the Tikhonov regularization the forensics problem now uses.
- Soften result claims to match what the demo reproduces: k1 is weakly
  identifiable from 9 noisy sensors (k0 recovered well), and the 900-element
  field correlation is ~0.98 rather than ">0.99".

Verified locally: `SPHINXOPTS="-W" make html` succeeds with no warnings.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Reduce vertical whitespace in blog posts:

- Code blocks: trim wrapper margin (1.5rem -> 1rem) and pre padding
  (1rem/1.25rem -> 0.7rem/1.1rem), and tighten the gap when a short intro
  line is immediately followed by a code block. Short one-line bash/python
  snippets no longer sit in oversized boxes.

- Tables: size to content width (width:auto, capped at 100%) instead of
  stretching full-width, with a fit-content wrapper so the table isn't
  centered in an empty box, plus tighter row padding. The small 2-3 row
  comparison tables now waste far less horizontal and vertical space.

All scoped to .blog-page so docs and landing pages are unaffected. Verified
by rendering the Fortran/Enzyme post.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@dionhaefner dionhaefner changed the title doc: add enzyme integration proof of concept doc: add enzyme integration demo + blog post Jun 17, 2026
@dionhaefner dionhaefner marked this pull request as ready for review June 17, 2026 10:30

@samalipio samalipio left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks wicked. Dropped some optional suggestions.

Comment thread docs/blog/2026-05-15-fortran-enzyme-autodiff.md Outdated
Comment thread docs/blog/2026-05-15-fortran-enzyme-autodiff.md Outdated
Comment thread docs/blog/2026-05-15-fortran-enzyme-autodiff.md Outdated
Comment thread docs/blog/2026-05-15-fortran-enzyme-autodiff.md Outdated
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.

2 participants