Skip to content

Discrete constraints¤

For PointSetConstraint, runtime operator knobs can be set once via eval_kwargs and are merged into each .loss(...) call.

PointSetConstraint.weight can be a scalar global multiplier or a DomainFunction evaluated pointwise on the anchor set.

Discrete point constraints¤

phydrax.constraints.PointSetConstraint ¤

A constraint evaluated on an explicit finite set of points.

Given a fixed collection of points \(\{z_i\}_{i=1}^N\) (encoded as a PointsBatch) and a residual DomainFunction \(r(z)\), the pointwise squared residual is

\[ \rho(z_i)=\|r(z_i)\|_F^2. \]

The scalar loss is then

For reduction="mean" with scalar global weight:

\[ \ell = w\,\frac{1}{N}\sum_{i=1}^N \rho(z_i), \]

For reduction="sum" with scalar global weight:

\[ \ell = w\sum_{i=1}^N \rho(z_i), \]

where \(w\) is the scalar global weight.

If weight is provided as a DomainFunction, it is evaluated pointwise on the stored points and multiplied into the per-point squared residual before reduction.

__init__(*, points: PointsBatch, residual: Callable[[Mapping[str, DomainFunction]], DomainFunction], constraint_vars: Sequence[str] | None = None, weight: DomainFunction | ArrayLike = 1.0, label: str | None = None, reduction: Literal['mean', 'sum'] = 'mean', eval_kwargs: Mapping[str, Any] | None = None) ¤

Create a point-set constraint from points and a residual callable.

from_points(*, component: DomainComponent, points: Mapping[str, ArrayLike] | ArrayLike, residual: Callable[[Mapping[str, DomainFunction]], DomainFunction], constraint_vars: Sequence[str] | None = None, weight: DomainFunction | ArrayLike = 1.0, label: str | None = None, reduction: Literal['mean', 'sum'] = 'mean', eval_kwargs: Mapping[str, Any] | None = None) -> PointSetConstraint classmethod ¤

Build a PointSetConstraint from raw point coordinates.

from_operator(*, points: PointsBatch, operator: Callable[..., DomainFunction], constraint_vars: str | Sequence[str], weight: DomainFunction | ArrayLike = 1.0, label: str | None = None, reduction: Literal['mean', 'sum'] = 'mean', eval_kwargs: Mapping[str, Any] | None = None) -> PointSetConstraint classmethod ¤

Build a PointSetConstraint from an operator applied to named fields.

loss(functions: Mapping[str, DomainFunction], /, *, key: Key[Array, ''] = jr.key(0), **kwargs: Any) -> Array ¤

Evaluate the point-set loss.

This evaluates the residual on the stored points and applies the configured reduction (mean or sum).


phydrax.constraints.DiscreteInteriorDataConstraint(constraint_var: str, domain, /, *, points: Mapping[str, ArrayLike] | ArrayLike | None = None, values: ArrayLike | None = None, sensors: Mapping[str, ArrayLike] | ArrayLike | None = None, times: ArrayLike | None = None, sensor_values: ArrayLike | None = None, num_points: SamplingNumPoints | None = None, structure: ProductStructure | None = None, dense_structure: ProductStructure | None = None, sampler: str = 'latin_hypercube', weight: DomainFunction | ArrayLike = 1.0, reduction: Literal[mean, sum] = 'mean', idw_exponent: float = 2.0, eps_snap: float = 1e-12, lengthscales: Mapping[str, float] | None = None, where: Mapping[str, Callable] | None = None, where_all: DomainFunction | None = None, label: str | None = None) -> FunctionalConstraint | PointSetConstraint ¤

Discrete interior data-fit constraint from anchors or sensor tracks.

This enforces agreement between a field \(u\) and discrete data in one of two forms:

1) Anchors (scattered measurements): given points \(\{z_i\}_{i=1}^N\) and values \(\{y_i\}\), enforce \(u(z_i)\approx y_i\), producing a PointSetConstraint with residual \(r_i = u(z_i) - y_i\).

2) Sensor tracks (fixed sensors over time): given sensor locations \(x_m\), times \(t_j\), and measurements \(y_{m,j}\), construct a target function \(g(x,t)\) (via spatial IDW + time interpolation) and enforce \(u(x,t)\approx g(x,t)\) at sampled \((x,t)\) pairs, producing a FunctionalConstraint.

For anchor data, a continuous target function can be constructed via inverse distance weighting (IDW) interpolation; see idw_interpolant.

Returns:

  • A PointSetConstraint (anchors), or a FunctionalConstraint (sensor tracks).

phydrax.constraints.DiscreteTimeDataConstraint(constraint_var: str, domain: TimeInterval, /, *, times: ArrayLike, values: ArrayLike, weight: DomainFunction | ArrayLike = 1.0, label: str | None = None, reduction: Literal[mean, sum] = 'mean') -> PointSetConstraint ¤

Discrete data-fit constraint \(u(t_i)\approx y_i\) with smooth time interpolation.

Constructs a cubic Hermite spline target \(g(t)\) through the samples (times, values) and enforces \(u(t_i)\approx g(t_i)\) at the provided times.

Discrete boundary / initial constraints¤

phydrax.constraints.DiscreteDirichletBoundaryConstraint(constraint_var: str, component: DomainComponent | DomainComponentUnion, /, *, points: Mapping[str, ArrayLike] | ArrayLike, values: ArrayLike, idw_exponent: float = 2.0, eps_snap: float = 1e-12, lengthscales: Mapping[str, float] | None = None, weight: DomainFunction | ArrayLike = 1.0, label: str | None = None, reduction: Literal[mean, sum] = 'mean') -> PointSetConstraint ¤

Discrete Dirichlet constraint on a boundary component at explicit anchor points.

Interpolates the provided (points, values) into a DomainFunction target via inverse-distance weighting (IDW), and then enforces u(points) = target(points).

Arguments:

  • constraint_var: Name of the constrained field.
  • component: Boundary DomainComponent associated with the points.
  • points: Anchor point coordinates (mapping by label, or stacked array).
  • values: Target values at the anchor points.
  • idw_exponent: Power \(p\) in IDW weights \(w_j \propto (\|z-z_j\|^2 + \varepsilon)^{-p/2}\).
  • eps_snap: Snap threshold \(\varepsilon\) used to return exact anchors when very close.
  • lengthscales: Optional per-label lengthscales used inside the distance metric.
  • weight: Scalar multiplier applied to this term.
  • reduction: "mean" or "sum".

phydrax.constraints.DiscreteNeumannBoundaryConstraint(constraint_var: str, component: DomainComponent | DomainComponentUnion, /, *, points: Mapping[str, ArrayLike] | ArrayLike, values: ArrayLike, var: str = 'x', mode: Literal[reverse, forward] = 'reverse', idw_exponent: float = 2.0, eps_snap: float = 1e-12, lengthscales: Mapping[str, float] | None = None, weight: DomainFunction | ArrayLike = 1.0, label: str | None = None, reduction: Literal[mean, sum] = 'mean') -> PointSetConstraint ¤

Discrete Neumann constraint on a boundary component at explicit anchor points.

Interpolates the provided (points, values) into a DomainFunction target via inverse-distance weighting (IDW), and then enforces \(\partial u/\partial n = g\) at the provided points.

Arguments:

  • constraint_var: Name of the constrained field.
  • component: Boundary DomainComponent associated with the points.
  • points: Anchor point coordinates (mapping by label, or stacked array).
  • values: Target Neumann data \(g\) at the anchor points.
  • var: Geometry label used to compute normals and differentiate.
  • mode: Differentiation mode ("reverse" or "forward").
  • idw_exponent: Power \(p\) in IDW weights \(w_j \propto (\|z-z_j\|^2 + \varepsilon)^{-p/2}\).
  • eps_snap: Snap threshold \(\varepsilon\) used to return exact anchors when very close.
  • lengthscales: Optional per-label lengthscales used inside the distance metric.
  • weight: Scalar multiplier applied to this term.
  • reduction: "mean" or "sum".

phydrax.constraints.DiscreteInitialConstraint(constraint_var: str, component: DomainComponent | DomainComponentUnion, /, *, evolution_var: str = 't', points: Mapping[str, ArrayLike] | ArrayLike, values: ArrayLike, time_derivative_order: int = 0, mode: Literal[reverse, forward] = 'reverse', time_derivative_backend: Literal[ad, jet] = 'ad', idw_exponent: float = 2.0, eps_snap: float = 1e-12, lengthscales: Mapping[str, float] | None = None, weight: DomainFunction | ArrayLike = 1.0, label: str | None = None, reduction: Literal[mean, sum] = 'mean') -> PointSetConstraint ¤

Discrete initial-condition constraint from anchor points on the initial surface.

Enforces

\[ \left.\frac{\partial^n u}{\partial t^n}\right|_{t=t_0}(x_i) \approx y_i \]

at provided anchor points, where n = time_derivative_order and \(t_0\) is the start of the time interval.

Arguments:

  • constraint_var: Name of the constrained field.
  • component: Domain component on the initial surface (or a union of such components).
  • evolution_var: Time label used for the initial slice (default: "t").
  • points: Anchor point coordinates (mapping by label, or stacked array).
  • values: Target values \(y_i\) at the anchor points.
  • time_derivative_order: Derivative order \(n\) for \(\partial^n/\partial t^n\).
  • mode: Differentiation mode ("reverse" or "forward").
  • time_derivative_backend: Backend for time derivatives ("ad" or "jet").
  • idw_exponent: Power \(p\) in IDW weights \(w_j \propto (\|z-z_j\|^2 + \varepsilon)^{-p/2}\).
  • eps_snap: Snap threshold \(\varepsilon\) used to return exact anchors when very close.
  • lengthscales: Optional per-label lengthscales used inside the distance metric.
  • weight: Scalar multiplier applied to this term.
  • reduction: "mean" or "sum".

Discrete ODE constraints¤

phydrax.constraints.DiscreteODEConstraint(constraint_var: str, domain: TimeInterval, operator: Callable[[DomainFunction], DomainFunction], /, *, times: ArrayLike, weight: DomainFunction | ArrayLike = 1.0, label: str | None = None, reduction: Literal[mean, sum] = 'mean') -> PointSetConstraint ¤

Discrete ODE residual constraint evaluated at explicit times.

Evaluates the ODE residual \(\mathcal{R}(u)(t_i)\) at the provided times times and applies a mean/sum reduction of \(\|\mathcal{R}(u)(t_i)\|_F^2\).