quchip.utils.jax_utils¶
Tracer-detection and array-namespace dispatch helpers shared across quchip.
JAX is a required dependency of quchip (see pyproject.toml), so these
helpers import it unconditionally.
Functions
|
Return the array's namespace ( |
|
Return |
|
Return |
|
Return |
|
Return a Python |
|
Return |
- quchip.utils.jax_utils.contains_tracer(pytree)[source]¶
Return
Trueif pytree has anyjax.core.Tracerleaf.Uses
jax.tree_util.tree_leaves()so nested tuples/lists/dicts and custom registered pytrees are traversed correctly.Covers all built-in JAX transforms:
jit,vmap,grad,linearize,pmap, and their composition all produce subclasses ofjax.core.Tracer.
- quchip.utils.jax_utils.array_namespace(array)[source]¶
Return the array’s namespace (
jax.numpyornumpy).Uses
__array_namespace__when available, falling back to NumPy. Single source of truth so dispatch logic stays consistent across engine, control, and analysis layers.
- quchip.utils.jax_utils.is_jax_namespace(xp)[source]¶
Return
Trueif xp isjax.numpy(by module name).
- quchip.utils.jax_utils.is_jax_array(array)[source]¶
Return
Trueif array usesjax.numpyas its namespace.
- quchip.utils.jax_utils.select_array_module(prefer_jax)[source]¶
Return
jax.numpyif prefer_jax, else NumPy.
- quchip.utils.jax_utils.maybe_concrete_scalar(value)[source]¶
Return a Python
floatif value is a concrete, real-valued 0-d scalar, elseNone.Used throughout device, drive, and envelope constructors to inspect a parameter that might be a JAX tracer. Returns
None— not afloator a raised error — for a JAX tracer, a non-scalar, or a complex or otherwise non-float-convertible payload. Callers therefore treat complex-valued input the same as traced input: the concrete validation check is skipped rather than run against a lossy cast.