Skip to content

FLINT joins the build: the ball arithmetic behind the interval types - #526

Merged
ofloveandhate merged 2 commits into
bertiniteam:integration/intervalsfrom
ofloveandhate:deps/flint-joins-the-build
Nov 7, 2026
Merged

ofloveandhate merged 2 commits into
bertiniteam:integration/intervalsfrom
ofloveandhate:deps/flint-joins-the-build

Conversation

@ofloveandhate

Copy link
Copy Markdown
Contributor

FLINT 3 carries Arb, the ball arithmetic chosen for the interval types (#412). ADR-0075, in this PR, records the choice and the rejected alternatives: our own interval type, MPFI through Boost.Multiprecision's complex_adaptor (non-enclosures across branch cuts; no win-64 build), C-XSC. The spike (#516) measured acb at 0.23 to 0.83 of complex_mp at equal precision on five platforms, and a Boost.Interval<double> complex rectangle at 7 to 30 times complex_dbl with the rounding mode set once per evaluation.

cmake/FindFLINT.cmake finds it, bertini2 links it PUBLIC, FlintVersion() reports it and info.flint_version exports it. That export is also the reference that keeps FLINT linked into the Python extension: libbertini2 is a static library, so the linker drops what nothing references, and the wheel repair tools then bundle nothing (the spike's Windows wheels weighed exactly what 4.0.0 did until this reference existed).

Every build route provides FLINT: the Ubuntu C++ job from apt (libflint-dev), macOS from Homebrew (flint), Windows from conda-forge (libflint, in both environment files and the recipe), and the Linux wheels from the deps image built by #525, whose -flint3.5.0 tag this PR pins. That image builds GMP 6.3.0 (FLINT needs 6.2.1 or later; AlmaLinux 9 ships 6.2.0), MPFR, MPC and FLINT from source, stripped.

test_flint asserts on every platform what b2 relies on: enclosure of products and quotients, a non-finite ball from division by a ball around zero, exact mpfr to arf conversion, one GMP shared with b2, a zero-filled acb being an exact zero (what numpy hands a dtype that needs initialization, so the ADR-0006 crash cannot happen for a FLINT-backed type), and the Boost rectangle enclosing the Arb evaluation of the same polynomial. It passes locally against conda-forge's FLINT 3.5.0.

Also: CLAUDE.md's dependency list, the changelog line under 4.1.0, and the ADR index row.

🤖 Generated with Claude Code

ofloveandhate and others added 2 commits November 3, 2026 21:30
… with GMP, MPFR and MPC built from source in the Linux deps image

FLINT 3 carries Arb, the arbitrary-precision ball arithmetic chosen for b2 interval types (bertiniteam#412; ADR-0075 records the choice and the rejected alternatives). cmake/FindFLINT.cmake finds it, bertini2 links it PUBLIC, FlintVersion() reports it and info.flint_version exports it, which is also the reference that keeps FLINT linked into the Python extension: libbertini2 is a static library, so the linker drops what nothing references and the wheel repair tools then bundle nothing.

Every build route provides it: the Ubuntu C++ job from apt, macOS from Homebrew, Windows from conda-forge, and the Linux wheels from the deps image. FLINT needs GMP 6.2.1 or later and the AlmaLinux 9 base ships 6.2.0, so the image now builds GMP (fat on x86_64, so the CPU-specific code is chosen at run time), MPFR, MPC and FLINT from source into /usr/local, stripped, since an unstripped libflint.so adds about 25 MB to every wheel. The four versions are pinned in ci-deps-versions.env, the image tag carries -flint<version>, and the image workflow also runs for pushes to integration/** so an integration branch publishes its own tag.

test_flint asserts on every platform what b2 relies on: enclosure of products and quotients, a non-finite ball from division by a ball around zero, exact mpfr to arf conversion, one GMP shared with b2, a zero-filled acb being an exact zero, and a Boost.Interval rectangle enclosing the Arb evaluation of the same polynomial.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The row needed the ADR-0074 row to follow, which reached develop in bertiniteam#523 after this branch was cut; the rebase brought it in.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
ofloveandhate added a commit to ofloveandhate/b2 that referenced this pull request Nov 4, 2026
…c ADR on integration/intervals (bertiniteam#526), and 0076 by the clang-cl ccache ADR now on develop

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ofloveandhate added a commit that referenced this pull request Nov 4, 2026
Closes #518.

A computation written out between its stages must continue, after a
restart, with the random draws an uninterrupted run would make. b2 could
set a seed and read it back, but not get the state the draws had
reached, nor set it.

### What changes

- **`RandomState`** (`random.hpp`) holds everything the calling thread's
next draws depend on: the global seed, whether one was chosen, the
ordinal the next `AdvanceSolveSeed` takes, and the thread's `b2rand/1`
draw stream. Its fields are public, and states compare with `==`.
- **`GetRandomState()` and `SetRandomState(state)`** get and set the
calling thread's state. The draws after setting a state are the draws
that followed getting it: tested for every kind of draw, a homotopy's
construction, and a solve.
- **Serialization at the edge.** `ToText()` and
`RandomState::FromText(text)` write and read versioned plaintext,
`b2randstate/1`; `FromText` refuses any other text with
`std::invalid_argument`. Boost.Serialization archives carry that text,
so a state goes through text and binary archives, and MPI. `DrawStream`
gains `ToText`, `FromText` and `==`.
- **Python:** `bertini.random.RandomState` (fields, `to_text`,
`from_text`, `==`, pickling as its text), `get_random_state()` and
`set_random_state(state)`.
- **`DeriveSolveSeed` is `AdvanceSolveSeed`** (Python
`advance_solve_seed`). "Derive" read as a derivative; the function
advances the solve-seed chain one step and returns its new seed. It has
shipped since 3.0.0, so the old names stay as deprecated aliases (C++
`[[deprecated]]`, Python `DeprecationWarning`) until 5.0. The Python
docstring said it drew from the stream; it draws nothing, and now says
so.
- **One source of randomness.** The thread's `std::mt19937` engine and
`ThreadEngine()` are removed. Every draw already came from the draw
stream (ADR-0044) and nothing drew from the engine, so no result
changes; it was a second piece of state that anyone saving the state
would have had to know about.

Per-path and per-worker streams are not part of the state: each is
reseeded from the global seed and its index when it is used (ADR-0071).

### Decisions

ADR-0077 records them, among them two open questions: whether "the
calling thread only" is enough (a program drawing setup randomness on
several threads of its own has a state per thread), and whether a
solve's `ScopedSessionState`, which restores the draw stream and
precision but not the seed or the solve ordinal, should restore the
whole state. ADR-0044's line keeping the engine is annotated. (It is
0077 because 0075 is the interval arithmetic ADR on
`integration/intervals`, #526, and 0076 the clang-cl ccache ADR, #524.)

### Docs

A tutorial, *Continuing a computation with the same random draws*, in
the record-keeping section, and a CHANGELOG entry under 4.1.0.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@ofloveandhate
ofloveandhate merged commit aa3bdd6 into bertiniteam:integration/intervals Nov 7, 2026
92 of 93 checks passed
ofloveandhate added a commit that referenced this pull request Nov 8, 2026
…MPFR thread-exit fix, Windows ccache, the random state and solution metadata JSON (#531)

Brings `develop` into `integration/intervals`, so the interval work
builds on what has landed there since the branch was cut:

- #527: the slim Windows conda environment, clang 22 with Visual
Studio's `link.exe`, and the fix for heap corruption when a worker
thread exits on Windows (ADR-0078, ADR-0079).
- #524: ccache caches the Windows builds (ADR-0076).
- #520: the random state can be got and set (ADR-0077).
- #522: a solution's metadata round-trips through exact JSON.

It is a merge, not a rebase, as an integration branch takes its trunk.
Two files conflicted, both lists where each side added entries: the
4.1.0 Added block of the changelog (FLINT here; the random state and
solution metadata on develop) and the ADR index (0075 here; 0076 to 0079
on develop). Both sides are kept, in order. The workflow,
`core/CMakeLists.txt` and `environment-win.yml` merged without conflict,
and `libflint` stays in the slim Windows environment.

One commit beyond the merge: the Windows jobs print FLINT's, GMP's,
MPFR's and MPC's versions with the other main conda packages.

What this run shows for the first time: FLINT linked by `link.exe` on
Windows (#526 linked it with `lld-link`), and `test_flint` under clang
22.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
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.

1 participant