bayesmith.bridge.jaxns_bridge
Source-derived signatures and contracts. See the reference index for coverage and conventions.
Residual-evidence adapter. Public residual EvidenceTask execution is not enabled by this adapter or by installing its optional dependency. See the evidence boundary.
Module contract
The JAXNS nested-sampling adapter: one module, consuming one compiled problem.
R5 Task 6. The backend decision is recorded in the R5 backend
evaluation: jaxns passes
every condition that scores a candidate, blackjax fails condition 1 because it
does not answer ``overflowing_outside_latent``, and §0.6's default drops the
second backend.
**What this module is allowed to see.** A :class:`~bayesmith.compiled.
CompiledEvidenceProblem` and nothing else -- no ``Graph``, asserted by type on
the way in. That class sits in ``bayesmith.compiled`` rather than in
``dispatch/evidence.py`` where it was written, precisely so this import can be
at module scope: ``bridge -> dispatch`` would close a cycle that
``tests/test_layering.py`` raises on. The ruling is in that module.
**What this module does NOT build, and why that departs from plan 6.1.** The
plan says the adapter "returns a populated ``EvidenceResult``". It cannot, and
the reason is a rule this module found by breaking it:
``tests/test_layering.py::test_the_artifact_protocol_is_a_leaf_and_dispatch_is_
what_reaches_it`` asserts that the units reaching ``artifacts`` are exactly
``["dispatch", "evaluation"]``, and says a third "would have to be argued for".
A first draft of this file imported ``EvidenceComponent`` and
``WeightedDrawsPosterior`` at module scope and that assertion failed with
``bridge`` in the list -- which is the test doing precisely what its docstring
promises.
The edge is not argued for, because it is not needed. ``evaluation`` cannot do
its job without artifact types; this module can. It reports NUMBERS, and
``dispatch`` -- which already assembles every other ``EvidenceResult`` in this
package, at ``task.py:3246``, out of facts only the planner has
(``plan_ref``, ``fingerprints``, ``PRODUCER``) -- turns them into artifacts.
That is also what ``bridge/numpyro_bridge.py::nuts`` does: it returns
``dict[str, jax.Array]``, and ``bridge/arviz.py`` imports artifact types inside
a function for the same reason.
**So the split is: jaxns facts here, bayesmith policy in `dispatch`.** The bit
LABELS below are jaxns's own words; the map from a label to a termination
member is this package's judgement, and it is carried here as the enum's plain
string VALUES so that stating it costs no import. The test that it is total --
that every string is a real ``TerminationReason`` and every bit has one -- lives
in ``tests/``, where reaching ``artifacts`` is free.
**The box, and what it costs.** jaxns's ``Prior`` wants a quantile function
``U -> X``, and a compiled problem carries ``log_prior``, ``log_likelihood`` and
``prior_sample`` -- a density is not invertible by inspection and a sampler is
not a transform, so none of the three yields one. The generic route is the
reparametrisation the bake-off measured: declare a bounded box ``B``, give jaxns
a uniform prior over it, and move this package's own prior into the likelihood,
log L'(x) = log pi(x) + log L(x) + log |B|
so jaxns integrates ``INT_B pi L dx``. Three consequences, each a cost the
verdict already names: ``B`` is an input jaxns needs and the compiled problem
does not carry; the answer is the evidence TRUNCATED to ``B``, so mass outside
it is an error the oracle's own truncation term bounds; and the sampler now
contracts against ``pi L`` rather than ``L``, which is not the problem nested
sampling's efficiency argument is about.
**Two things jaxns does that a caller has to know.** Importing it writes
``jax_enable_x64`` **process-globally** -- reproduced here on 2026-09-07, with
``UserWarning: JAX x64 is not enabled. Setting it now.`` -- against this
package's rule that ``src/`` never touches ``jax.config``. §0.16's owner
decision attaches to this module because the backend it was conditional on was
chosen. And ``TerminationCondition()`` **disables every stopping rule**: each
field defaults to ``None``, ``None`` means "off", and the real defaults live in
``jaxns/public.py``, which builds one only when it is handed none. This module
never constructs one and never passes ``term_cond`` at all.JAXNS_TERMINATION
Defined in bayesmith.bridge.jaxns_bridge, line 99.
JAXNS_TERMINATION: tuple[tuple[str, str], ...] = (('reached max samples', 'budget_exhausted'), ('evidence uncertainty low enough', 'converged'), ('small remaining evidence', 'converged'), ('reached ESS', 'converged'), ('used max num likelihood evaluations', 'budget_exhausted'), ('likelihood contour reached', 'completed'), ('sampler efficiency too low', 'tolerance_unmet'), ('all live points on a single plateau', 'diverged'), ('relative spread of live points < rtol', 'converged'), ('absolute spread of live points < atol', 'converged'), ('no seed points left', 'diverged'), ('XL < max(XL) * peak_XL_frac', 'converged'))NestedEvidence
Defined in bayesmith.bridge.jaxns_bridge, line 191.
class NestedEvidence
log_evidence: float
standard_error: float
draws: tuple[tuple[str, np.ndarray], ...]
log_weights: np.ndarray
ess: float
termination: Termination
backend_name: str
backend_version: str | None
likelihood_evaluations: int
iterations: int
truncated_to: tuple[tuple[str, float, float], ...]
method: strWhat the backend produced, in artifact types and plain Python floats. Every number here has been through ``float()`` already. ``_finite`` requires ``type(value) in (int, float)``, so a ``np.float64`` or a jax scalar raises ``TypeError`` at the artifact boundary (§0.1), and a backend returns none of these as Python floats.
Termination
Defined in bayesmith.bridge.jaxns_bridge, line 134.
class Termination
reason: str
message: str
labels: tuple[str, ...]One jaxns bitmask, decoded. ``reason`` is a ``TerminationReason`` VALUE. A string rather than the enum member so that this module costs no edge to ``artifacts``; ``TerminationReason(record.reason)`` is what ``dispatch`` does with it, and a test asserts every value in the table is a real member.
decode_termination
Defined in bayesmith.bridge.jaxns_bridge, line 147.
decode_termination(mask: int) -> TerminationOne jaxns bitmask, decoded. The message names EVERY bit that fired, so collapsing the mask to one ``reason`` loses nothing a reader needs. A mask of zero raises. §0.1: "An unmapped backend signal is an error, not a default -- a nested sampler that stopped for an unrecognised reason must not be recorded as ``COMPLETED``." A run that stopped for no declared reason is exactly that case, and so is a bit above the twelve this table knows.
nested_evidence
Defined in bayesmith.bridge.jaxns_bridge, line 229.
nested_evidence(problem: CompiledEvidenceProblem, *, box: Mapping[str, tuple[float, float]], seed: int=0, num_live_points: int | None=None, max_samples: int=100000, method: str='jaxns_nested_sampling') -> NestedEvidenceIntegrate ``problem`` over ``box`` with jaxns, and report what came back. ``box`` is per residual parameter, ``(lower, upper)``. It is required because jaxns needs a domain and the compiled problem does not carry one; see this module's docstring for what the truncation costs.