eqiora.jax
Use Eqiora differentiable programs with JAX.
View sourceExample: differentiate a scalar objective
Section titled “Example: differentiate a scalar objective”Install the jax extra, then create program with the
differentiation example:
import jaximport jax.numpy as jnpfrom eqiora.jax import bind
jax.config.update("jax_enable_x64", True)operator = bind(program)parameters = (jnp.asarray(1.5, dtype=jnp.float64),)gradient = jax.grad(lambda p: jnp.square(operator(p)[0]).sum())(parameters)print(gradient)This differentiates the sum of squared output values. Keep the parameter leaves together on one CPU device with their exact native shapes and dtypes. See framework adapters for JIT and batching examples.
JaxProgram
Section titled “JaxProgram”JAX view of a program in this process, with first-order vmap support.
class JaxProgram: def __init__(self, program: DifferentiableProgram) -> None: ... @property def program(self) -> DifferentiableProgram: ... @property def inputs(self) -> tuple[DifferentiableValueSignature, ...]: ... @property def outputs(self) -> tuple[DifferentiableValueSignature, ...]: ... def __call__(self, parameters: Sequence[jax.Array]) -> tuple[jax.Array, ...]: ...Wrap a DifferentiableProgram so that JAX can call and differentiate it.
def bind(program: DifferentiableProgram) -> JaxProgram: ...