Inspiration

Cartilage is the smooth layer on the ends of our bones that lets joints glide and absorb shocks. When it wears away, you get osteoarthritis, one of the most common causes of joint pain and disability. Researchers study it with computer models instead of patients, and many of those models are still written in Fortran 77, a language standardised in 1978. Each line has to fit the columns of an 80-column punch card, and the model only runs inside one commercial simulator. We wanted to show that this kind of "dead" research code can be brought back safely, and proven to be unchanged.

What it does

NecroFort takes BioUMAT, an MIT-licensed cartilage model from a 2019 osteoarthritis study, and resurrects it:

Safe Rust port: 5 of its 7 Fortran routines, including the full UMAT material material model, ported to memory-safe model, ported to memory-safe Rust (#![forb Rust (#![forbid(unsafe_code)]). Theid(unsafe_code)]). The GO TO 80/90 jump GO TO 80/90 j loop became a structured for loop. Hidden by-reference state became an explicit &mut UmatStateump loop became a structured for loop. Hidden by-reference state became an explicit&mut Umat. Inputs that would makeState`. Inputs that would make the original write out of bounds now return errors the original write out of bounds now return errors instead. Proof it's un instead. Proof itchanged: 7,168 property-based test cases compare the Rust with the original compiled by gfortran's unchanged: 7,168 property-based test cases compare the Rust with the original compiled by gfortran. UMAT matches it b. UMAT matches it bit for bit on every compared output (46,849 of 46,849 in the recorded run). Runs in the browser: compiled to a 31.it for bit on every compared output (46,849 of 46,849 in the recorded run). Runs in the browser: compiled to a 31.5 KB WebAssembly module5 KB WebAssembly module. In. In headless Chromium, one UMAT call took 4–10 µs. A self-healing pipe headless Chromium, one UMAT call took 4–10 µs. A self-healing pipeline: a Python orchestrator (Parse → Spec →line: a Python orchestrator (Parse → Spec → Transmute → Oracle Gate → Self-Heal → PR). Its demo mode plants a class Transmute → Oracle Gate → Self-Heal → PR). Its demo mode plants a classic 1-based-index bug; proptest catches it, shrinks it to aic 1-based-index bug; proptest catches it, shrinks it to a minimal input, and the pipeline repairs it from that input alone. A themed web app with three tabs minimal input, and the pipeline repairs it from that input alone. A themed web app with three tabs: Res: Resurrection Chamber: the Fortran and the Rust side by side, joined by 62 line-level links, with a guided tour, aurrection Chamber: the Fortran and the Rust side by side, joined by 62 line-level links, with a guided tour, a "cause of death" for each routine, and each line drawn as an IBM punch card. Graveyard & Swarm Dashboard: replays a real pipeline "cause of death" for each routine, and each line drawn as an IBM punch card. Graveyard & Swarm Dashboard: replays a real pipeline run. Live WASM Lab: run. Live WASM Lab: drag sliders to drag sliders to deform virtual cartilage and see the stress, the deform virtual cartilage and see the stress, the Jacobian, and a live Jacobian, and a live benchmark.

How we built it

The we built it The whole project was built in Kiro Web in conversation with the whole project was built in Kiro Web in conversation with the Kiro agent, gu Kiro agent, guided by steering, a spec and a hook that live in .kiro/. See section 3 for the Kiro details.

Oracle: oracle-harided by steering, a spec and a hook that live in .kiro/`. See section 3 for the Kiro details.

Oracle: oracle-harness/build.rs copness/build.rscopies the original Fortran routines withouties the original Fortran routines without changes and supplies a minimal changes and supplies a minimal ABA_PARAM.INC (the Abaqus header theABA_PARAM.IN code needs). It compiles them with gfortran -stdC (the Abaqus header the code needs). It compiles them with gfortran -std=legacy and links them=legacyand links them into the test binaries only. The FF into the test binaries only. The FFI calls to thatI calls to that build are the onlyunsafe` code in the repo.

**Rust build are the only unsafe code in the repo.

Rust ports: kept theports:** kept the Fortran evaluation order so that the Fortran evaluation order so that the results are bit-identical. results are bit-identical.

Orchestrator: standard-library Python. `f77_analyzer.py

Orchestrator: standparses fixed-form Fortran intoard-library Python.f77_analyzer.pyparses f a Kiro-style spec;graph.pyruns the state machine and writesrun_log.json`.

**UI:ixed-form Fortran into a Kiro-style spec; graph.py runs the state machine and writes run_log.json.

UI: React + Vite +** React + Vite + Tailwind, with char Tailwind, with charts and the punch card hand-drawn in SVG. It's published to Gitts and the punch card hand-drawn in SVG. It's published to GitHub Pages by an Actions workflow.

Challenges we ran into

The original doesn't compile as a whole. One routine has CALL RANDO CALL RANDOM-NUMBER(...)andM-NUMBER(...)and.OR. appl.OR. applied to integers, and UMAT needs a header that only Abaqus provied to integers, and UMAT needs a header that only Abaqus provides. We extractides. We extract the routines that do compile, the routines that do compile, without edit without editing them, and generate the header. Bit-identical floating point. That needed theing them, and generate the header. Bit-identical floating point. That same operation order and no f needed the same operation order and no fused multiply-add on either side (-ffp-contract=off). used multiply-add on either side (-ffp-contract=off). Quirks we had to keep, not fix: UMAT reuses itsQuirks we had to keep, DO-loop variable i as the not fix: UMAT reuses its DO-loop variable i as the Jacobian per Jacobian perturbation index. It perturbs the caller's input matrix in place and then restores it. Its constant FFD is rounded up fromturbation index. It perturbs the caller's input matrix in place and then restores it. Its constant FFD is rounded up from 1/√3, so f 1/√3, so fibribrils carry about 1e-14 of tension at rest. ils carry about 1e-14 of tension at rest. A read-only sandbox.A read-only sandbox. gfortran, was gfortran, wasm-pack and the wasm target allm-pack and the wasm target all had to be installed into a scratch directory.

Accomplishments that we're proud of

UMAT is bit-identud of UMAT is bit-identical to gical to gfortran. Bugs we planted on purpose in UMAT were all caught by the tests.fortran. Bugs we planted on purpose in UMAT were all caught by the tests. The 62 F The 62 Fortranortran↔Rust links are checked against the real source files on every build, so the before/after view can't sil↔Rust links are checked against the real source files on every build, so the before/after view can't silently drift out of date. A medently drift out of date. A medical research model now runs in any browser in microseconds.

What we learned

Property-based testing against the original binary is a stronger proof than reary* is a stronger proof than re-deriving the ma-deriving the maths. Kiro does much better on legacy codeths. Kiro does much better on legacy code when its steering files spell out when its steering files spell out the old language's rules: column lay the old language's rules: column layout, implicit typing, column-major arrays, and evaluation order.

What's next for NecroFort

Resurrect the's next Resurrect the remaining two routines ( remaining two routines (SDVINI, which doesn't compile as written, and FLOW). Add anSDVINI, which doesn't compile as written, and FLOW). Add an LLM-back LLM-backed healer for faults beyed healer for faults beyond index offsets. Point NecroFort at other Fortran research codes. NecroFort is a software demonstrationond index offsets.

Point NecroFort at other Fortran research codes. NecroFort is a software demonstration. It reproduces a published research model; it is not a med. It reproduces a published research model; it is not a medical device.

Built With

Share this project:

Updates

Submission history