# f2j

- **Event:** [Meta Global AI Developer Hackathon](https://cerebralvalley.ai/e/meta-ai-developer-hackathon)
- **When:** Oct 26, 12:00 PM – Nov 4, 9:00 PM (EST)
- **Where:** Online
- **Team:** [MD RABBI](https://cerebralvalley.ai/u/rabbim)
- **GitHub:** https://github.com/Mrabbi3/f2j
- **Demo video:** https://drive.google.com/file/d/1ZNHUmzAMwyDFdatk-8paqbL_ly8skE7S/view?usp=sharing
- **Gallery:** https://cerebralvalley.ai/e/meta-ai-developer-hackathon/hackathon/gallery
- **Page:** https://cerebralvalley.ai/e/meta-ai-developer-hackathon/hackathon/gallery/233

Climate, weather, ocean and engineering models still run on Fortran written before GPUs existed. That code can’t run on GPUs, can’t be differentiated for calibration or machine learning, and the people who wrote it are retiring. Rewriting it by hand takes years, and nobody can prove the rewrite is right.

f2j translates Fortran into JAX one routine at a time and checks each translation against the original. Muse Spark (muse-spark-1.3 on the Meta Model API) writes the code. The original Fortran, compiled with f2py, is the judge. Every candidate must pass five checks:

it compiles
it matches the Fortran to a relative tolerance of 1e-10
it gives the same results when batched with jax.vmap
its gradients agree with finite differences of the Fortran
it passes held-out tests the model never sees

gcov shows that the tests actually reach the code. When a candidate fails, Muse Spark gets the exact mismatch plus a hint such as “output is transposed”, and tries again. Routines that can’t be translated safely, such as ones that keep hidden state, stay in Fortran behind a JAX callback, so the whole model still runs.

On the repo’s shallow-water example, the live run with Muse Spark gave these results:

8 of 9 routines translated, each passing all five checks on its first try; the ninth stayed in Fortran by design
8 model calls, 51 seconds, $0.05
over 200 time steps, the JAX model stayed within 2 × 10⁻¹⁴ of the Fortran

The translated model can then do things the Fortran never could:

recover a physical parameter from data in five Gauss–Newton steps, using derivatives through the whole model
run a 64-member ensemble about 4× faster per member on a laptop CPU

You can try it in about two minutes with no API key: an offline replay mode reproduces the full pipeline, including the repair loop.

## More from Meta Global AI Developer Hackathon

- [Trust. Proof. Work.](https://cerebralvalley.ai/e/meta-ai-developer-hackathon/hackathon/gallery/230)
- [shivam](https://cerebralvalley.ai/e/meta-ai-developer-hackathon/hackathon/gallery/231)
- [Rackham](https://cerebralvalley.ai/e/meta-ai-developer-hackathon/hackathon/gallery/232)
- [yokoten doctor](https://cerebralvalley.ai/e/meta-ai-developer-hackathon/hackathon/gallery/234)
- [exotic](https://cerebralvalley.ai/e/meta-ai-developer-hackathon/hackathon/gallery/235)
- [MARMAR Health](https://cerebralvalley.ai/e/meta-ai-developer-hackathon/hackathon/gallery/236)

---

Markdown version of https://cerebralvalley.ai/e/meta-ai-developer-hackathon/hackathon/gallery/233. Site index for agents: https://cerebralvalley.ai/llms.txt · full text: https://cerebralvalley.ai/llms-full.txt
