Ship the MIR JIT in the wheels, so forward sensitivities run on a machine with no C compiler

Open
#1,852 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
18/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
c, cmake, python
Domain
build-system, cli

Research direction

The work spans the cibuildwheel configuration, _codegen_jit_backend in _codegen.py, the capabilities() output, and the vendored MIR under third_party/mir. Start by reading the mir.yml CI job and the compiler-probe logic in _codegen.py, then check how BNGSIM_ENABLE_MIR reaches the wheel build. Done means a wheel with no C compiler on PATH runs a forward sensitivity to the closed-form answer, while cc is still used where present.

Written by the indexing model from the issue text.

Description

Forward sensitivities compile generated C, so a wheel install needs a C compiler where it runs. Containers, cluster compute nodes and stock Windows often have none, and there a run with sensitivity_params raises CodegenToolchainError (#1690). The vendored MIR JIT compiles the same C in-process with no compiler, but the published wheels build without it (BNGSIM_ENABLE_MIR is OFF, and HAS_MIR is False).

Why it was off, and why that no longer holds

When the MIR CI job landed, #2 recorded that MIR stays out of the wheels for now. The blocker was that MIR handled some errors by calling exit(), so a model it could not compile would end the user's Python process instead of raising an error. Binary size and shipping a vendored compiler were the other reasons.

That blocker is fixed. Since #1215, MirJit gives each MIR context its own allocator, code allocator and error function, and each returns to MirJit::compile, which raises RuntimeError (third_party/mir/README.md.bngsim, "Running out"). The other known MIR problems are fixed or covered:

  • The SIGILL under Rosetta is fixed by a local carry (#1216).
  • mir.yml checks MIR against cc on Linux, macOS x86_64, macOS arm64 and Windows: bit-identical on x86_64, within about 1e-13 on arm64, where clang fuses multiply-adds and MIR does not.
  • The library adds about 1 MB to a wheel.

What to do

  1. Build MIR into the wheels. Set BNGSIM_ENABLE_MIR=ON in the cibuildwheel configuration, for every platform the wheels cover. Check the wheel sizes and that capabilities()["features"]["mir"] is true in each.
  2. Fall back to MIR when there is no compiler. A MIR build uses the JIT only when BNGSIM_CODEGEN_JIT=mir is set (_codegen_jit_backend in _codegen.py). Without a fallback, a wheel with MIR in it still raises CodegenToolchainError on a machine with no compiler. Keep cc first where it is present, since cc -O3 makes faster code, and use MIR where the compiler probe finds none. BNGSIM_CODEGEN_JIT=mir still forces MIR.
  3. Test the case MIR is for. mir.yml never takes the compilers off PATH (its header says so), so nothing tests a machine with no compiler. Add a wheel smoke test that runs a sensitivity with an empty PATH and an empty codegen cache, as in #1690's repro, and checks the answer against the closed form.
  4. Refresh the vendored MIR first, or decide not to. #1490 is open: upstream merged aarch64 and x86-64 code-generation fixes after our pin. Shipping MIR to every user makes that refresh matter more.
  5. Update what says a compiler is needed. The README, docs/installation.md, the sensitivities, steady-state and codegen guides, the agent guide's "What needs what" table, and the capabilities()["missing"]["mir"] text. The CodegenToolchainError message should no longer be what a wheel user hits.

Done when

  • pip install bngsim on a machine with no C compiler runs forward sensitivities, and a wheel test checks it.
  • cc is still used where it is present.
  • The docs and capabilities() say a compiler is optional for wheel installs.

Closes #1690 when done. Part of #1689.

Dominant language
Python
Stars
3
Forks
6
Avg merge
1d 1h
Merged PRs (30d)
295

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from lanl/bngsim

All issues in lanl/bngsim

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.