zoomy_core.model.fields

zoomy_core.model.fields#

Symbols as the user-facing names of state fields and parameters.

FieldSymbols holds the state symbols of a model (Model.state(...), sm.fields) with named groups (.momentum) and optional user aliases. Parameters is the parameter vector of a solver, read and set by symbol, and a pytree for JAX. A symbol is identified by its name; the model’s own symbols carry its assumptions, symbols made elsewhere with the same name refer to the same field.

Module Contents#

Classes#

FieldGroup

A named group of state symbols, e.g. fields.momentum (all momentum components).

FieldSymbols

The state symbols of a model by name, its groups and optional aliases.

Parameters

The parameter vector of a solver, read and set by symbol: p[n], p.set({n: 0.04}).

Functions#

symbol_name

The name of a symbol; anything else raises TypeError.

momentum_symbols

The momentum components among symbols: the family q (q_0, q_x_1, …).

parameter_vector

The vector for run(..., parameters=...): None gives default (a Parameters), a Parameters its vector, a mapping {symbol: value} default with those replaced, a vector passes through.

Data#

API#

zoomy_core.model.fields.RunResult#

‘namedtuple(…)’

zoomy_core.model.fields.symbol_name(s, what='field')#

The name of a symbol; anything else raises TypeError.

class zoomy_core.model.fields.FieldGroup#

Bases: tuple

A named group of state symbols, e.g. fields.momentum (all momentum components).

Initialization

Initialize self. See help(type(self)) for accurate signature.

zoomy_core.model.fields.momentum_symbols(symbols)#

The momentum components among symbols: the family q (q_0, q_x_1, …).

class zoomy_core.model.fields.FieldSymbols(symbols, groups=None, names=None)#

The state symbols of a model by name, its groups and optional aliases.

fields.h is the depth symbol, fields.momentum the group of momentum components, and with names=("b", "h", "hu", "hv") also fields.hu (the same symbol as fields.q_x_0).

Initialization

Hold symbols (the state in model order), groups {name: symbols} and the user names (one per state field, in model order) as aliases.

names()#

The field names in model order.

slot(s)#

The row of field s (a symbol of this state) in Q: Q[fields.slot(fields.h)].

class zoomy_core.model.fields.Parameters(names, values)#

The parameter vector of a solver, read and set by symbol: p[n], p.set({n: 0.04}).

A pytree for JAX (registered by zoomy_jax), so jax.grad with respect to all parameters returns a Parameters of gradients: dJ[n]. np.asarray(p) and jnp.asarray(p) give the vector.

Initialization

Hold the parameter names (vector order) and the values vector.

set(mapping)#

A copy with the parameters in mapping {symbol: value} replaced.

vector(mapping=None)#

The vector, with the parameters in mapping {symbol: value} replaced.

names()#

The parameter names in vector order.

zoomy_core.model.fields.parameter_vector(default, parameters)#

The vector for run(..., parameters=...): None gives default (a Parameters), a Parameters its vector, a mapping {symbol: value} default with those replaced, a vector passes through.