Skip to content

Adopt adaptive-triangulation 0.3.1: batched tell_pending, Rust default_loss, and a Rust-backend CI job#499

Merged
basnijholt merged 1 commit into
mainfrom
rust-backend-0.3.1
Jun 10, 2026
Merged

Adopt adaptive-triangulation 0.3.1: batched tell_pending, Rust default_loss, and a Rust-backend CI job#499
basnijholt merged 1 commit into
mainfrom
rust-backend-0.3.1

Conversation

@basnijholt

Copy link
Copy Markdown
Member

Summary

Follow-up to #493, completing the two items it deferred. adaptive-triangulation 0.3.1 fixes the known degenerate-simplex divergence (curvature losses crashed on collinear input with the Rust backend), and 0.3.0 added two batched APIs targeting LearnerND's remaining Python hot loops. This PR bumps _MIN_RUST_VERSION to (0, 3, 1), adopts both APIs, and adds the deferred Rust-backend CI job.

Changes

  • Batched tell_pending: distributing a pending point over the simplices that contain it previously looped tri.point_in_simplex over every simplex sharing a vertex with the containing simplex (~14 checks per point in 2D, ~70 in 3D, ~96% misses). With the Rust backend this is now one tri.simplices_containing(point, simplex=hint) call (feature-detected via hasattr, so a directly-passed custom triangulation class keeps working). The pure-Python backend keeps the original loop, refactored into _simplices_containing_point + _add_pending_point_to_simplex so both paths share the insertion code.
  • Rust default_loss: when the Rust backend is active, LearnerND uses adaptive_triangulation.default_loss as the default loss_per_simplex — the same embedded-simplex-volume computation without the per-simplex Python tuple-splicing. Exposed as triangulation_backend.rust_default_loss (None on the python backend) to avoid a circular import with learnerND. Pickling adds no new constraint: a learner on the Rust backend already references adaptive_triangulation objects.
  • CI: new pytest_rust_backend nox session (installs .[test,other,rust], runs the suite with ADAPTIVE_TRIANGULATION_BACKEND=rust) and a test-rust-backend job in nox.yml.
  • rust extra bumped to adaptive-triangulation>=0.3.1; _MIN_RUST_VERSION = (0, 3, 1) (0.2.x installs now fall back to the python backend rather than using a version without the degenerate-simplex fix).

Performance

End-to-end LearnerND vs adaptive 1.5.0, both with the Rust backend (best of 3):

case 1.5.0 + rust this PR + rust speedup
2D ring_of_fire, 3000 pts 0.46 s 0.42 s 1.10×
3D sphere_of_fire, 1500 pts 0.74 s 0.52 s 1.42×

The gain grows with dimension (vertex stars get bigger). Sampled points are identical between the python and rust backends — asserted by a new test that runs both for 200 points.

Testing

  • Full suite with the Rust backend forced: 294 passed, 0 failures (the 7 curvature-loss failures documented in Add optional Rust-accelerated triangulation backend for LearnerND #493 are gone with 0.3.1).
  • Full suite without adaptive-triangulation installed: 292 passed (rust-specific tests skip).
  • New tests: test_rust_default_loss_matches_backend (both env configurations) and test_rust_backend_samples_identical_points.
  • pre-commit (ruff, ruff-format, mypy) passes on the changed files.

…t_loss, CI job

adaptive-triangulation 0.3.1 fixes the degenerate-simplex divergence noted
when the backend was introduced (curvature losses crashed on collinear
input) and 0.3.0 added two APIs that move LearnerND's remaining Python hot
loops into Rust. This bumps _MIN_RUST_VERSION to (0, 3, 1) and adopts both:

- tell_pending asks the triangulation for all simplices containing the
  pending point in one simplices_containing call (with the known containing
  simplex as a hint) instead of looping point_in_simplex over every
  neighbouring simplex; the pure-Python backend keeps the original loop.
- LearnerND's default loss_per_simplex is the Rust default_loss when the
  Rust backend is active (same embedded-simplex-volume computation).

Together: 1.10x (2D ring_of_fire, 3000 pts) to 1.42x (3D, 1500 pts) faster
end-to-end on top of the existing Rust backend, sampling identical points
(asserted by a new test).

Also adds the Rust-backend CI job deferred when the backend landed: a nox
session running the suite with ADAPTIVE_TRIANGULATION_BACKEND=rust, now
that the full suite passes with it (294 passed; previously 7 known
curvature-loss failures).
@basnijholt basnijholt merged commit b3a40ef into main Jun 10, 2026
18 of 19 checks passed
@basnijholt basnijholt deleted the rust-backend-0.3.1 branch June 10, 2026 22:48
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