pyhs3.JaxifiedGraph

class pyhs3.JaxifiedGraph(inputs, input_names, fn)[source]

A JAX-callable wrapper around a compiled PyTensor expression.

Produced by jaxify(). Supports keyword-argument calls (the primary interface for dict-pytree-based optimizers like optimistix or everwillow) and positional calls via call_positional().

Calling a JaxifiedGraph does not jit it: JAX runs the graph eagerly, one operation at a time, which on a large likelihood is orders of magnitude slower than the same call wrapped in jax.jit. Wrap it for any repeated evaluation:

jg = jaxify(model.log_prob)
nll = jax.jit(lambda params: -jg(**params)[0])

For a likelihood evaluated repeatedly without JAX, pyhs3.Model.compile_nll() compiles it for you.

Variables:
  • inputs – Tuple of PyTensor input variables, in evaluation order.

  • input_names – Names of those variables (same order as inputs).

  • fn – The raw JAX callable returned by jax_funcify.

Parameters:
__init__(inputs, input_names, fn)
Parameters:

Methods

__init__(inputs, input_names, fn)

call_positional(*args)

Call with positional arguments — pure passthrough to fn.

Attributes

JaxifiedGraph.call_positional(*args)[source]

Call with positional arguments — pure passthrough to fn.

Like calling the graph, this is not jitted; wrap it in jax.jit for repeated use.

Parameters:

*args (object) – Values in the same order as self.input_names.

Return type:

Whatever fn returns (typically a 1-tuple of JAX arrays).

JaxifiedGraph.inputs
JaxifiedGraph.input_names
JaxifiedGraph.fn