Costs, Priors & Solvers¶
The functional core under the model classes: pure cost functions that score a candidate state against observations and prior, prior modules that supply the regularisation term, and the inner-loop solver functions that drive the 4DVarNet iteration. The model classes are thin, stateful-looking wrappers over these pieces — drop down to this layer when building custom methods or instrumenting the optimisation.
Cost functions¶
The variational cost \(J(x) = J_\text{obs}(x) + J_\text{prior}(x)\) and its
gradient, with the observation and prior terms also available separately
(decomposed_loss returns them unsummed for logging). The _1d / _2d
suffixes match the Batch1D / Batch2D carriers. See
3DVar and
strong-constraint 4DVar for the math each term
implements.
vardax — Modular variational data assimilation with learned components.
All public symbols are re-exported from the private _src subpackage so
that user code imports from the top-level namespace:
variational_cost
¶
variational_cost(
x: Float[Array, ...],
batch: Batch1D,
prior_fn: Callable[..., Any],
alpha_obs: float = 0.5,
alpha_prior: float = 0.5,
) -> Float[Array, ""]
Compute the variational cost \(U(x)\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Float[Array, ...]
|
Current state estimate. |
required |
batch
|
Batch1D
|
Observed data batch with |
required |
prior_fn
|
Callable[..., Any]
|
Callable |
required |
alpha_obs
|
float
|
Weight for the observation term (default |
0.5
|
alpha_prior
|
float
|
Weight for the prior term (default |
0.5
|
Returns:
| Type | Description |
|---|---|
Float[Array, '']
|
Scalar cost value. |
Examples:
With the trivial IdentityPrior the
prior term vanishes, leaving the weighted observation MSE.
>>> import jax.numpy as jnp, vardax
>>> batch = vardax.Batch1D(input=jnp.zeros((1, 2, 4)), mask=jnp.ones((1, 2, 4)))
>>> x = jnp.ones((1, 2, 4))
>>> float(vardax.variational_cost(x, batch, vardax.IdentityPrior()))
0.5
Source code in src/vardax/_src/costs.py
variational_cost_grad
¶
variational_cost_grad(
x: Float[Array, ...],
batch: Batch1D,
prior_fn: Callable[..., Any],
alpha_obs: float = 0.5,
alpha_prior: float = 0.5,
) -> Float[Array, ...]
Gradient of variational_cost w.r.t. x.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Float[Array, ...]
|
Current state estimate. |
required |
batch
|
Batch1D
|
Observed data batch. |
required |
prior_fn
|
Callable[..., Any]
|
Callable |
required |
alpha_obs
|
float
|
Weight for the observation term. |
0.5
|
alpha_prior
|
float
|
Weight for the prior term. |
0.5
|
Returns:
| Type | Description |
|---|---|
Float[Array, ...]
|
Gradient array with the same shape as |
Source code in src/vardax/_src/costs.py
obs_cost_1d
¶
obs_cost_1d(
state: Float[Array, "B T N"],
obs: Float[Array, "B T N"],
mask: Float[Array, "B T N"],
nan_to_num: bool = False,
) -> Float[Array, ""]
Observation cost for 1-D data.
Computes the masked mean-squared error between the state and observations:
where \(\Omega\) is the set of observed locations (mask == 1).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
Float[Array, 'B T N']
|
Current state estimate of shape |
required |
obs
|
Float[Array, 'B T N']
|
Observations of shape |
required |
mask
|
Float[Array, 'B T N']
|
Binary observation mask of shape |
required |
nan_to_num
|
bool
|
When |
False
|
Returns:
| Type | Description |
|---|---|
Float[Array, '']
|
Scalar observation cost. |
Examples:
>>> import jax.numpy as jnp
>>> from vardax import obs_cost_1d
>>> state = jnp.ones((1, 1, 4))
>>> obs = jnp.zeros((1, 1, 4))
>>> mask = jnp.ones((1, 1, 4))
>>> float(obs_cost_1d(state, obs, mask))
1.0
Source code in src/vardax/_src/costs.py
obs_cost_2d
¶
obs_cost_2d(
state: Float[Array, "B T H W"],
obs: Float[Array, "B T H W"],
mask: Float[Array, "B T H W"],
nan_to_num: bool = False,
) -> Float[Array, ""]
Observation cost for 2-D data.
Computes the masked mean-squared error between the state and observations:
where \(\Omega\) is the set of observed locations (mask == 1).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
Float[Array, 'B T H W']
|
Current state estimate of shape |
required |
obs
|
Float[Array, 'B T H W']
|
Observations of shape |
required |
mask
|
Float[Array, 'B T H W']
|
Binary observation mask of shape |
required |
nan_to_num
|
bool
|
When |
False
|
Returns:
| Type | Description |
|---|---|
Float[Array, '']
|
Scalar observation cost. |
Source code in src/vardax/_src/costs.py
prior_cost
¶
prior_cost(
state: Float[Array, ...],
prior_reconstruction: Float[Array, ...],
) -> Float[Array, ""]
Prior cost based on learned autoencoder reconstruction.
Computes the mean-squared error between the state and its reconstruction through the learned prior (autoencoder):
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
Float[Array, ...]
|
Current state estimate of arbitrary shape. |
required |
prior_reconstruction
|
Float[Array, ...]
|
Autoencoder reconstruction of the state,
same shape as |
required |
Returns:
| Type | Description |
|---|---|
Float[Array, '']
|
Scalar prior cost. |
Source code in src/vardax/_src/costs.py
decomposed_loss
¶
decomposed_loss(
x: Float[Array, ...],
batch: Batch1D,
prior_fn: Callable[..., Any],
alpha_obs: float = 0.5,
alpha_prior: float = 0.5,
) -> dict[str, Float[Array, ""]]
Compute the decomposed variational loss.
Returns individual observation and prior components alongside the
total, matching the ModelLoss pattern from the legacy codebase.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Float[Array, ...]
|
Current state estimate. |
required |
batch
|
Batch1D
|
Observed data batch. |
required |
prior_fn
|
Callable[..., Any]
|
Callable |
required |
alpha_obs
|
float
|
Weight for the observation term. |
0.5
|
alpha_prior
|
float
|
Weight for the prior term. |
0.5
|
Returns:
| Type | Description |
|---|---|
dict[str, Float[Array, '']]
|
Dictionary with keys |
Source code in src/vardax/_src/costs.py
strong_variational_cost
¶
strong_variational_cost(
x0: Float[Array, ...],
ts: Float[Array, T],
batch: Batch1D,
forward_fn: Callable[..., Any],
*,
xb: Float[Array, ...] | None = None,
alpha_obs: float = 0.5,
alpha_bg: float = 0.5,
nan_to_num: bool = False,
) -> Float[Array, ""]
Strong-constraint variational cost \(U(x_0)\).
The dynamical model is enforced as a hard constraint: the initial
state x0 is propagated through the dynamics forward_fn(x0, ts)
and only the resulting trajectory is scored against the observations.
This differs from the weak / soft-constraint
variational_cost, where the model appears
as an additive prior penalty and the whole state field is free.
Ported from mfourdvar's StrongVarCost, adapted to a functional
form that mirrors variational_cost.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x0
|
Float[Array, ...]
|
Initial state (control variable). Whatever shape |
required |
ts
|
Float[Array, T]
|
Time coordinates of shape |
required |
batch
|
Batch1D
|
Observed data batch supplying |
required |
forward_fn
|
Callable[..., Any]
|
Callable |
required |
xb
|
Float[Array, ...] | None
|
Background state for the background term. Defaults to |
None
|
alpha_obs
|
float
|
Weight for the observation term (default |
0.5
|
alpha_bg
|
float
|
Weight for the background term (default |
0.5
|
nan_to_num
|
bool
|
When |
False
|
Returns:
| Type | Description |
|---|---|
Float[Array, '']
|
Scalar strong-constraint variational cost. |
Source code in src/vardax/_src/costs.py
background_cost
¶
Background cost \(\|x_0 - x_b\|^2\).
Penalises departure of the initial state \(x_0\) (the control variable in strong-constraint 4DVar) from the background / first guess \(x_b\). Uses the same mean-squared convention as the other functional costs in this module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x0
|
Float[Array, ...]
|
Initial state estimate of arbitrary shape. |
required |
xb
|
Float[Array, ...]
|
Background state, same shape as |
required |
Returns:
| Type | Description |
|---|---|
Float[Array, '']
|
Scalar background cost. |
Source code in src/vardax/_src/costs.py
Priors¶
Implementations of the Prior Protocol. IdentityPrior
gives plain Tikhonov regularisation; L63Prior / L96Prior encode Lorenz
dynamics as a model-consistency penalty; the autoencoder priors (MLP,
convolutional, and bilinear variants in 1D, 2D, and 2D-multivariate) are
learned priors that penalise distance from a trained reconstruction
manifold.
vardax — Modular variational data assimilation with learned components.
All public symbols are re-exported from the private _src subpackage so
that user code imports from the top-level namespace:
IdentityPrior
¶
Bases: Module
Trivial identity prior: \(\varphi(x) = x\).
Zero parameters. Useful as a pure obs-driven baseline (the prior cost vanishes everywhere) and as a sanity-check building block in the linear-Gaussian agreement tests.
Examples:
>>> import jax.numpy as jnp
>>> from vardax import IdentityPrior
>>> prior = IdentityPrior()
>>> x = jnp.arange(6.0).reshape(1, 2, 3)
>>> bool(jnp.all(prior(x) == x))
True
Source code in src/vardax/_src/priors.py
L63Prior
¶
Bases: Module
Learned prior for the Lorenz-63 system.
A simple MLP autoencoder designed for the 3-dimensional Lorenz-63
attractor. The state is treated as a flat vector of length 3.
Attributes:
| Name | Type | Description |
|---|---|---|
latent_dim |
Dimensionality of the latent code (default |
|
hidden_dim |
Hidden layer width. |
|
state_dim |
Dimensionality of the state vector (default |
Source code in src/vardax/_src/priors.py
L96Prior
¶
Bases: Module
Learned prior for the Lorenz-96 system.
A simple MLP autoencoder designed for the N-dimensional Lorenz-96
attractor. The state is treated as a flat vector of length N.
Attributes:
| Name | Type | Description |
|---|---|---|
latent_dim |
Dimensionality of the latent code. |
|
hidden_dim |
Hidden layer width. |
|
state_dim |
Dimensionality of the state vector. |
Source code in src/vardax/_src/priors.py
MLPAEPrior1D
¶
Bases: Module
MLP autoencoder prior for 1-D data.
Attributes:
| Name | Type | Description |
|---|---|---|
state_dim |
Spatial size of the input ( |
|
latent_dim |
Dimensionality of the latent code. |
|
hidden_dim |
Hidden layer width. |
|
n_time |
int
|
Number of time steps ( |
Source code in src/vardax/_src/priors.py
ConvAEPrior1D
¶
Bases: Module
Convolutional autoencoder prior for 1-D spatially-structured data.
Uses circular (periodic) padding suitable for systems with periodic
boundary conditions such as Lorenz-96. Operates on inputs of shape
(B, T, N) where N is the spatial dimension.
Attributes:
| Name | Type | Description |
|---|---|---|
latent_channels |
Number of channels in the latent representation. |
|
kernel_size |
int
|
Convolution kernel size (must be a positive odd integer). |
n_time |
int
|
Number of time steps |
Source code in src/vardax/_src/priors.py
BilinAEPrior1D
¶
Bases: Module
Bilinear autoencoder prior for 1-D data.
The encoder maps the input to a low-dimensional latent code; the decoder
reconstructs the original space. The prior cost is
||x - decode(encode(x))||^2.
Attributes:
| Name | Type | Description |
|---|---|---|
state_dim |
int
|
Spatial size of the input ( |
latent_dim |
int
|
Dimensionality of the latent code. |
n_time |
int
|
Number of time steps ( |
Examples:
>>> import jax, jax.numpy as jnp
>>> from vardax import BilinAEPrior1D
>>> prior = BilinAEPrior1D(
... state_dim=4, latent_dim=2, n_time=3, key=jax.random.PRNGKey(0)
... )
>>> prior(jnp.ones((2, 3, 4))).shape
(2, 3, 4)
Source code in src/vardax/_src/priors.py
BilinAEPrior2D
¶
Bases: Module
Bilinear autoencoder prior for 2-D data.
Attributes:
| Name | Type | Description |
|---|---|---|
latent_dim |
Dimensionality of the latent code. |
|
n_time |
int
|
Number of time steps ( |
height |
int
|
Spatial height |
width |
int
|
Spatial width |
Source code in src/vardax/_src/priors.py
BilinAEPrior2DMultivar
¶
Bases: Module
Bilinear autoencoder prior for 2-D multivariate data.
Attributes:
| Name | Type | Description |
|---|---|---|
latent_dim |
Dimensionality of the latent code. |
|
n_time |
int
|
Number of time steps ( |
n_channels |
int
|
Number of channels |
height |
int
|
Spatial height |
width |
int
|
Spatial width |
Source code in src/vardax/_src/priors.py
Dynamical priors¶
ODE-based temporal priors ported from mfourdvar (Decision D18):
DynIncrements scores one-step increments, DynTrajectory scores the
full rollout from the initial state. Both satisfy the
TemporalPrior protocol; bind(ts) adapts either to
the static Prior seam, and as_forward_model(dt)
adapts the wrapped ODE to pipekit_cycle.ForwardModel.
vardax — Modular variational data assimilation with learned components.
All public symbols are re-exported from the private _src subpackage so
that user code imports from the top-level namespace:
DynamicalPrior
¶
Bases: Module
Base class for ODE-based dynamical priors.
Wraps a diffrax diffeqsolve around an ODE right-hand side with
pluggable solver, step-size controller, and adjoint strategy. The
adjoint choice trades memory against speed for reverse-mode
differentiation through the solve (relevant for long windows).
Concrete subclasses implement __call__ (the integration) and
loss (the dynamical residual). Instantiating DynamicalPrior
directly and calling it raises NotImplementedError.
Attributes:
| Name | Type | Description |
|---|---|---|
model |
Callable
|
Diffrax-compatible ODE right-hand side |
params |
PyTree | None
|
Optional default |
solver |
Solver
|
Diffrax solver (default :class: |
stepsize |
StepSizeController
|
Diffrax step-size controller. Defaults to an adaptive
:class: |
adjoint |
Adjoint
|
Diffrax adjoint strategy (default
:class: |
Source code in src/vardax/_src/priors_dynamical.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
reconstruct
¶
Dynamics-consistent reconstruction of a state sequence.
Returns an array of the same shape as x such that
||x - reconstruct(x, ts)||² is the prior's dynamical residual —
the temporal analogue of the autoencoder reconstruction used by the
static Prior seam (Decision D18).
Source code in src/vardax/_src/priors_dynamical.py
bind
¶
Bind a time grid, yielding a one-argument Prior adapter.
The returned callable satisfies the static
Prior protocol (__call__(x) -> x_prior) by
closing over ts, so a dynamical prior can be used anywhere a
static prior is expected — e.g. as the prior_fn of
variational_cost, turning the prior
term into a weak-constraint dynamical residual.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ts
|
Array
|
Time coordinates of shape |
required |
params
|
PyTree | None
|
ODE |
None
|
Returns:
| Type | Description |
|---|---|
_BoundTemporalPrior
|
A |
Examples:
>>> import jax.numpy as jnp
>>> from vardax import DynTrajectory, IdentityPrior, Prior
>>> def decay(t, y, args):
... return -y
>>> ts = jnp.linspace(0.0, 0.5, 6)
>>> bound = DynTrajectory(model=decay).bind(ts)
>>> isinstance(bound, Prior)
True
>>> traj = DynTrajectory(model=decay)(jnp.ones(3), ts)
>>> bool(jnp.allclose(bound(traj), traj, atol=1e-4))
True
Source code in src/vardax/_src/priors_dynamical.py
as_forward_model
¶
Adapt this prior's dynamics to pipekit_cycle.ForwardModel.
The returned adapter exposes step(state, dt), dt, and
state_signature, so the wrapped ODE can drive anything that
consumes the pipekit forward-model seam —
StrongFourDVar, pipekit_cycle.DACycle,
etc. (Decisions D8/D18). step integrates the ODE over
[0, dt]; the dynamics are therefore treated as autonomous
(time-shift invariant), which holds for the standard testbeds
(Lorenz-63/96) and any RHS that ignores t.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dt
|
float
|
Default integration step advertised as the adapter's |
required |
Returns:
| Type | Description |
|---|---|
_DynamicalForwardModel
|
A |
Source code in src/vardax/_src/priors_dynamical.py
DynIncrements
¶
Bases: DynamicalPrior
One-step-increment dynamical prior.
The loss integrates each state a single step forward and compares it to the next observed state, so the dynamics act locally in time:
Examples:
A consistent trajectory (produced by rolling out the same model) has (near-)zero increment loss.
>>> import jax.numpy as jnp
>>> from vardax import DynIncrements, DynTrajectory
>>> def decay(t, y, args):
... return -y
>>> ts = jnp.linspace(0.0, 0.5, 6)
>>> x0 = jnp.array([1.0, 2.0, -1.0])
>>> traj = DynTrajectory(model=decay)(x0, ts)
>>> bool(DynIncrements(model=decay).loss(traj, ts) < 1e-3)
True
Source code in src/vardax/_src/priors_dynamical.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 | |
loss
¶
One-step-increment dynamical loss.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Array
|
State sequence of shape |
required |
ts
|
Array
|
Time coordinates of shape |
required |
x_gt
|
Array | None
|
Target state sequence of shape |
None
|
params
|
PyTree | None
|
ODE |
None
|
Returns:
| Type | Description |
|---|---|
Array
|
Scalar dynamical residual |
Source code in src/vardax/_src/priors_dynamical.py
reconstruct
¶
One-step-increment reconstruction.
reconstruct(x, ts)[t+1] is the one-step propagation
\(\varphi_{\Delta t}(x_t)\) and reconstruct(x, ts)[0] = x[0], so
\(\|x - \text{reconstruct}(x, t_s)\|^2\) equals the increment
residual of :meth:loss (the \(t=0\) term vanishes).
Source code in src/vardax/_src/priors_dynamical.py
DynTrajectory
¶
Bases: DynamicalPrior
Full-rollout dynamical prior.
The loss integrates the initial state across the whole window and compares the resulting trajectory to the target sequence, enforcing the dynamics as a global (strong) constraint:
This is the propagation used by strong-constraint 4DVar — see
strong_variational_cost.
Source code in src/vardax/_src/priors_dynamical.py
loss
¶
Full-trajectory dynamical loss.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Array
|
State sequence of shape |
required |
ts
|
Array
|
Time coordinates of shape |
required |
x_gt
|
Array | None
|
Target trajectory of shape |
None
|
params
|
PyTree | None
|
ODE |
None
|
Returns:
| Type | Description |
|---|---|
Array
|
Scalar dynamical residual |
Source code in src/vardax/_src/priors_dynamical.py
reconstruct
¶
Full-rollout reconstruction: the trajectory from x[0].
\(\|x - \text{reconstruct}(x, t_s)\|^2\) equals the trajectory
residual of :meth:loss.
Source code in src/vardax/_src/priors_dynamical.py
4DVarNet inner-loop solvers¶
The unrolled (and fixed-point) inner loop of 4DVarNet, exposed as pure
functions over an explicit SolverState: initialise with
init_solver_state_*, advance one modulated-gradient step with
solver_step_* (or fp_solver_step_1d for the fixed-point formulation),
or run the whole loop with solve_4dvarnet_*. The one_step_* variants
pair with OneStepAdjoint for memory-frugal training.
vardax — Modular variational data assimilation with learned components.
All public symbols are re-exported from the private _src subpackage so
that user code imports from the top-level namespace:
SolverState1D
¶
Bases: Module
Mutable solver state for 1-D problems.
Attributes:
| Name | Type | Description |
|---|---|---|
x |
Float[Array, 'B T N']
|
Current state estimate of shape |
lstm |
LSTMState1D
|
Current LSTM hidden/cell state for the gradient modulator. |
step |
int
|
Current iteration index. |
Source code in src/vardax/_src/solver.py
SolverState2D
¶
Bases: Module
Mutable solver state for 2-D problems.
Attributes:
| Name | Type | Description |
|---|---|---|
x |
Float[Array, 'B T H W']
|
Current state estimate of shape |
lstm |
LSTMState2D
|
Current LSTM hidden/cell state for the gradient modulator. |
step |
int
|
Current iteration index. |
Source code in src/vardax/_src/solver.py
init_solver_state_1d
¶
init_solver_state_1d(
batch: Batch1D, hidden_dim: int
) -> SolverState1D
Initialise a 1-D solver state from a batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
Batch1D
|
Input batch. The initial state is set to the masked input (zeros where unobserved). |
required |
hidden_dim
|
int
|
Hidden dimension of the ConvLSTM gradient modulator. |
required |
Returns:
| Type | Description |
|---|---|
SolverState1D
|
Zero-initialised |
Source code in src/vardax/_src/solver.py
init_solver_state_2d
¶
init_solver_state_2d(
batch: Batch2D, hidden_dim: int
) -> SolverState2D
Initialise a 2-D solver state from a batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
Batch2D
|
Input batch. The initial state is set to the masked input. |
required |
hidden_dim
|
int
|
Hidden dimension of the ConvLSTM gradient modulator. |
required |
Returns:
| Type | Description |
|---|---|
SolverState2D
|
Zero-initialised |
Source code in src/vardax/_src/solver.py
solver_step_1d
¶
solver_step_1d(
solver_state: SolverState1D,
batch: Batch1D,
prior_fn: Any,
grad_mod_fn: Any,
alpha: float = 1.0,
prior_weight: float = 1.0,
) -> SolverState1D
Perform a single 1-D solver iteration.
Computes the gradient of the variational cost, then passes it through the learned gradient modulator to obtain a state update.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solver_state
|
SolverState1D
|
Current solver state. |
required |
batch
|
Batch1D
|
Observed data batch. |
required |
prior_fn
|
Any
|
Callable |
required |
grad_mod_fn
|
Any
|
Callable |
required |
alpha
|
float
|
Step-size scaling factor. |
1.0
|
prior_weight
|
float
|
Weighting factor \(\lambda\) for the prior cost term. |
1.0
|
Returns:
| Type | Description |
|---|---|
SolverState1D
|
Updated |
Source code in src/vardax/_src/solver.py
solver_step_2d
¶
solver_step_2d(
solver_state: SolverState2D,
batch: Batch2D,
prior_fn: Any,
grad_mod_fn: Any,
alpha: float = 1.0,
prior_weight: float = 1.0,
) -> SolverState2D
Perform a single 2-D solver iteration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solver_state
|
SolverState2D
|
Current solver state. |
required |
batch
|
Batch2D
|
Observed data batch. |
required |
prior_fn
|
Any
|
Callable |
required |
grad_mod_fn
|
Any
|
Callable |
required |
alpha
|
float
|
Step-size scaling factor. |
1.0
|
prior_weight
|
float
|
Weighting factor \(\lambda\) for the prior cost term. |
1.0
|
Returns:
| Type | Description |
|---|---|
SolverState2D
|
Updated |
Source code in src/vardax/_src/solver.py
fp_solver_step_1d
¶
fp_solver_step_1d(
x: Float[Array, "B T N"], batch: Batch1D, prior_fn: Any
) -> Float[Array, "B T N"]
Perform a single 1-D fixed-point projection step.
Applies the prior projection then re-inserts observations at observed locations:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Float[Array, 'B T N']
|
Current state estimate of shape |
required |
batch
|
Batch1D
|
Observed data batch containing |
required |
prior_fn
|
Any
|
Callable |
required |
Returns:
| Type | Description |
|---|---|
Float[Array, 'B T N']
|
Updated state estimate of shape |
Source code in src/vardax/_src/solver.py
solve_4dvarnet_1d
¶
solve_4dvarnet_1d(
batch: Batch1D,
prior_fn: Any,
grad_mod_fn: Any,
n_steps: int,
hidden_dim: int,
alpha: float = 1.0,
) -> Float[Array, "B T N"]
Run the full 1-D 4DVarNet solver for n_steps iterations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
Batch1D
|
Observed data batch. |
required |
prior_fn
|
Any
|
Callable |
required |
grad_mod_fn
|
Any
|
Callable |
required |
n_steps
|
int
|
Number of gradient-descent steps to unroll. |
required |
hidden_dim
|
int
|
Hidden dimension of the ConvLSTM gradient modulator. |
required |
alpha
|
float
|
Step-size scaling factor. |
1.0
|
Returns:
| Type | Description |
|---|---|
Float[Array, 'B T N']
|
Final state estimate of shape |
Source code in src/vardax/_src/solver.py
solve_4dvarnet_2d
¶
solve_4dvarnet_2d(
batch: Batch2D,
prior_fn: Any,
grad_mod_fn: Any,
n_steps: int,
hidden_dim: int,
alpha: float = 1.0,
) -> Float[Array, "B T H W"]
Run the full 2-D 4DVarNet solver for n_steps iterations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
Batch2D
|
Observed data batch. |
required |
prior_fn
|
Any
|
Callable |
required |
grad_mod_fn
|
Any
|
Callable |
required |
n_steps
|
int
|
Number of gradient-descent steps to unroll. |
required |
hidden_dim
|
int
|
Hidden dimension of the ConvLSTM gradient modulator. |
required |
alpha
|
float
|
Step-size scaling factor. |
1.0
|
Returns:
| Type | Description |
|---|---|
Float[Array, 'B T H W']
|
Final state estimate of shape |
Source code in src/vardax/_src/solver.py
solve_4dvarnet_1d_fixedpoint
¶
solve_4dvarnet_1d_fixedpoint(
batch: Batch1D, prior_fn: Any, n_fp_steps: int
) -> Float[Array, "B T N"]
Run n_fp_steps fixed-point projection steps using jax.lax.scan.
Initialises the state from the masked observations, then iterates the
fixed-point update fp_solver_step_1d for
n_fp_steps steps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
Batch1D
|
Observed data batch. |
required |
prior_fn
|
Any
|
Callable |
required |
n_fp_steps
|
int
|
Number of fixed-point iterations. |
required |
Returns:
| Type | Description |
|---|---|
Float[Array, 'B T N']
|
Final state estimate of shape |
Source code in src/vardax/_src/solver.py
one_step_solve_4dvarnet_1d
¶
one_step_solve_4dvarnet_1d(
batch: Batch1D,
prior_fn: Any,
grad_mod_fn: Any,
n_steps: int,
hidden_dim: int,
alpha: float = 1.0,
prior_weight: float = 1.0,
k: int = 1,
) -> Float[Array, "B T N"]
Solve 4DVarNet-1D using k-step differentiation (Bolte et al., 2023).
Runs n_steps - k solver iterations with jax.lax.stop_gradient
applied to the iterate, then performs k final steps through which
gradients flow. This gives O(k) memory cost (k=1 matches implicit
differentiation) while being as simple to implement as unrolled backprop.
Reference
Bolte, Pauwels & Vaiter (NeurIPS 2023). "One-step differentiation of iterative algorithms." https://arxiv.org/abs/2305.13768
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
Batch1D
|
Observed data batch. |
required |
prior_fn
|
Any
|
Callable |
required |
grad_mod_fn
|
Any
|
Callable |
required |
n_steps
|
int
|
Total number of solver iterations (warmup = n_steps - k, then k differentiable steps). |
required |
hidden_dim
|
int
|
Hidden dimension of the ConvLSTM gradient modulator. |
required |
alpha
|
float
|
Step-size scaling factor. |
1.0
|
prior_weight
|
float
|
Weighting factor \(\lambda\) for the prior cost term. |
1.0
|
k
|
int
|
Number of trailing differentiable steps (clipped to n_steps). |
1
|
Returns:
| Type | Description |
|---|---|
Float[Array, 'B T N']
|
Final state estimate of shape |
Source code in src/vardax/_src/solver.py
one_step_solve_4dvarnet_2d
¶
one_step_solve_4dvarnet_2d(
batch: Batch2D,
prior_fn: Any,
grad_mod_fn: Any,
n_steps: int,
hidden_dim: int,
alpha: float = 1.0,
prior_weight: float = 1.0,
k: int = 1,
) -> Float[Array, "B T H W"]
Solve 4DVarNet-2D using k-step differentiation (Bolte et al., 2023).
Runs n_steps - k solver iterations with jax.lax.stop_gradient
applied to the iterate, then performs k final steps through which
gradients flow. This gives O(k) memory cost (k=1 matches implicit
differentiation) while being as simple to implement as unrolled backprop.
Reference
Bolte, Pauwels & Vaiter (NeurIPS 2023). "One-step differentiation of iterative algorithms." https://arxiv.org/abs/2305.13768
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
Batch2D
|
Observed data batch. |
required |
prior_fn
|
Any
|
Callable |
required |
grad_mod_fn
|
Any
|
Callable |
required |
n_steps
|
int
|
Total number of solver iterations (warmup = n_steps - k, then k differentiable steps). |
required |
hidden_dim
|
int
|
Hidden dimension of the ConvLSTM gradient modulator. |
required |
alpha
|
float
|
Step-size scaling factor. |
1.0
|
prior_weight
|
float
|
Weighting factor \(\lambda\) for the prior cost term. |
1.0
|
k
|
int
|
Number of trailing differentiable steps (clipped to n_steps). |
1
|
Returns:
| Type | Description |
|---|---|
Float[Array, 'B T H W']
|
Final state estimate of shape |