omnibias.fields.jax.ops.norms
Structured scalar, vector, and tensor fields with derivative caches, calculus operators, and coordinate conventions.
import omnibias.fields.jax.ops.normsModule contract & mathematical conventions
Inner products and L2 / Sobolev norms as standalone ops (jax).
Bit-identical twin of omnibias.fields.torch.ops.norms.
Shared formulas do not imply universal floating-point identity. Verify dtype, shape, derivative-order support, and the stated numerical assumptions for the path you use.
inner_product
omnibias.fields.jax.ops.inner_productSource ↗inner_product(state: FieldState, name_a: str, name_b: str, *, rule: QuadratureSpec, weight: str | None=None) -> ArrayWeighted real inner product \langle a, b\rangle_w
= \int_\Omega w\,a\,b\,dx.
Parameters
| Name | Type & default | Contract |
|---|---|---|
statepositional-or-keyword | FieldStateRequired | See the operation contract and implementation below. |
name_apositional-or-keyword | strRequired | See the operation contract and implementation below. |
name_bpositional-or-keyword | strRequired | See the operation contract and implementation below. |
rulekeyword-only | QuadratureSpecRequired | See the operation contract and implementation below. |
weightkeyword-only | str | NoneDefault: None | See the operation contract and implementation below. |
ArrayExecuted regression · inner product cross backend
Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_inner_product_cross_backend(make_torch_field, make_jax_field): # type: ignore[no-untyped-def]
rule = gauss_legendre(BOUNDS, (8, 8))
ts = make_torch_field()(torch.as_tensor(rule.nodes, dtype=torch.float64))
js = make_jax_field()(jnp.asarray(rule.nodes, dtype=jnp.float64))
t = _np(ts.ops.inner_product(ts, "u", "v", rule=rule))
j = _np(js.ops.inner_product(js, "u", "v", rule=rule))
assert np.allclose(t, j, rtol=1e-12, atol=1e-12)python -m pytest "packages/omnibias-fields/tests/test_integration_norms.py::test_inner_product_cross_backend" -qRead the implementation
def inner_product(
state: FieldState,
name_a: str,
name_b: str,
*,
rule: QuadratureSpec,
weight: str | None = None,
) -> Array:
r"""Weighted real inner product :math:`\langle a, b\rangle_w
= \int_\Omega w\,a\,b\,dx`."""
a = value(state, name_a)
b = value(state, name_b)
integrand = a * b
if weight is not None:
integrand = integrand * value(state, weight)
return _integrate_values(integrand, rule)Other public import paths
omnibias.fields.jax.ops.inner_productomnibias.fields.jax.ops.norms.inner_product
l2_norm
omnibias.fields.jax.ops.l2_normSource ↗l2_norm(state: FieldState, name: str, *, rule: QuadratureSpec) -> Array\lVert u\rVert_{L^2} = \sqrt{\int_\Omega u^2\,dx}.
Parameters
| Name | Type & default | Contract |
|---|---|---|
statepositional-or-keyword | FieldStateRequired | See the operation contract and implementation below. |
namepositional-or-keyword | strRequired | See the operation contract and implementation below. |
rulekeyword-only | QuadratureSpecRequired | See the operation contract and implementation below. |
ArrayRead the implementation
def l2_norm(state: FieldState, name: str, *, rule: QuadratureSpec) -> Array:
r""":math:`\lVert u\rVert_{L^2} = \sqrt{\int_\Omega u^2\,dx}`."""
sq = _integrate_values(value(state, name) ** 2, rule)
return jnp.sqrt(sq)Other public import paths
omnibias.fields.jax.ops.l2_normomnibias.fields.jax.ops.norms.l2_norm
sobolev_norm
omnibias.fields.jax.ops.sobolev_normSource ↗sobolev_norm(state: FieldState, name: str, *, rule: QuadratureSpec, k: int=1, weights: tuple[float, ...] | None=None) -> ArraySobolev norm \lVert u\rVert_{H^k} for k in {0, 1, 2}.
See omnibias.fields.torch.ops.norms.sobolev_norm for the definition.
Parameters
| Name | Type & default | Contract |
|---|---|---|
statepositional-or-keyword | FieldStateRequired | See the operation contract and implementation below. |
namepositional-or-keyword | strRequired | See the operation contract and implementation below. |
rulekeyword-only | QuadratureSpecRequired | See the operation contract and implementation below. |
kkeyword-only | intDefault: 1 | See the operation contract and implementation below. |
weightskeyword-only | tuple[float, ...] | NoneDefault: None | See the operation contract and implementation below. |
ArrayExplicit validation & failure cases
- When
k < 0, raisesValueError(f'k must be >= 0, got {k}'). - When
k > 2, raisesNotImplementedError(f'sobolev_norm currently supports k in {{0, 1, 2}}; got k={k}. Higher orders need the full multi-index expansion.'). - When
len(coeffs) != k + 1, raisesValueError(f'weights must have length k+1 = {k + 1}, got {len(coeffs)}').
These are explicit source guards. Backend operations may also raise for invalid shapes, dtypes, or unsupported devices.
Executed regression · sobolev norm cross backend
Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_sobolev_norm_cross_backend(make_torch_field, make_jax_field): # type: ignore[no-untyped-def]
rule = gauss_legendre(BOUNDS, (8, 8))
ts = make_torch_field()(torch.as_tensor(rule.nodes, dtype=torch.float64))
js = make_jax_field()(jnp.asarray(rule.nodes, dtype=jnp.float64))
for k in (0, 1, 2):
t = _np(ts.u.sobolev_norm(rule=rule, k=k))
j = _np(js.u.sobolev_norm(rule=rule, k=k))
assert np.allclose(t, j, rtol=1e-12, atol=1e-12), kpython -m pytest "packages/omnibias-fields/tests/test_integration_norms.py::test_sobolev_norm_cross_backend" -qRead the implementation
def sobolev_norm(
state: FieldState,
name: str,
*,
rule: QuadratureSpec,
k: int = 1,
weights: tuple[float, ...] | None = None,
) -> Array:
r"""Sobolev norm :math:`\lVert u\rVert_{H^k}` for ``k`` in ``{0, 1, 2}``.
See :func:`omnibias.fields.torch.ops.norms.sobolev_norm` for the definition.
"""
if k < 0:
raise ValueError(f"k must be >= 0, got {k}")
if k > 2:
raise NotImplementedError(
"sobolev_norm currently supports k in {0, 1, 2}; "
f"got k={k}. Higher orders need the full multi-index expansion."
)
coeffs = (1.0,) * (k + 1) if weights is None else weights
if len(coeffs) != k + 1:
raise ValueError(f"weights must have length k+1 = {k + 1}, got {len(coeffs)}")
total = coeffs[0] * _integrate_values(value(state, name) ** 2, rule)
if k >= 1:
g = gradient(state, name)
total = total + coeffs[1] * _integrate_values((g ** 2).sum(axis=-1), rule)
if k >= 2:
h = spatial_hessian(state, name)
total = total + coeffs[2] * _integrate_values((h ** 2).sum(axis=(-2, -1)), rule)
return jnp.sqrt(total)Other public import paths
omnibias.fields.jax.ops.sobolev_normomnibias.fields.jax.ops.norms.sobolev_norm