Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dinosaur/held_suarez.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def explicit_terms(
nodal_surface_pressure = jnp.exp(nodal_log_surface_pressure)

# Pressure at layer centers, with shape (levels, latitude, longitude)
pressure = self.nondim_coords.vertical.pressure_centers(
pressure = self.nondim_coords.vertical.pressure_centers( # pyrefly: ignore[missing-attribute]
nodal_surface_pressure
)

Expand Down
22 changes: 12 additions & 10 deletions dinosaur/primitive_equations.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,14 @@
class State:
"""Records the state of a system described by the primitive equations."""

vorticity: Array
divergence: Array
temperature_variation: Array
log_surface_pressure: Array
tracers: Mapping[str, Array] = dataclasses.field(default_factory=dict)
sim_time: float | None = None
vorticity: Array | jax.sharding.PartitionSpec
divergence: Array | jax.sharding.PartitionSpec
temperature_variation: Array | jax.sharding.PartitionSpec
log_surface_pressure: Array | jax.sharding.PartitionSpec
tracers: Mapping[str, Array | jax.sharding.PartitionSpec] = dataclasses.field(
default_factory=dict
)
sim_time: float | Array | jax.sharding.PartitionSpec | None = None


def _asdict(state: State) -> dict[str, Any]:
Expand Down Expand Up @@ -1567,7 +1569,7 @@ def to_nodal_fn(x):
# Hybrid vertical velocity / mass flux calculation.
nodal_surface_pressure = jnp.exp(to_nodal_fn(state.log_surface_pressure))
delta_p = coords.vertical.layer_thickness(nodal_surface_pressure) # pyrefly: ignore[missing-attribute]
delta_b = coords.vertical.sigma_thickness[:, np.newaxis, np.newaxis]
delta_b = coords.vertical.sigma_thickness[:, np.newaxis, np.newaxis] # pyrefly: ignore[missing-attribute]

# D_k = div(v * dp) = dp * div(v) + v . grad(dp)
# grad(dp) = grad(da + db * ps) = db * ps * grad(ln ps)
Expand All @@ -1582,7 +1584,7 @@ def compute_mass_flux(d_k):
cumsum_d = jax_numpy_utils.cumsum(d_k, axis=0)
# pad top with 0
cumsum_d_padded = jnp.pad(cumsum_d, ((1, 0), (0, 0), (0, 0)))
b_boundaries = coords.vertical.b_boundaries[:, np.newaxis, np.newaxis]
b_boundaries = coords.vertical.b_boundaries[:, np.newaxis, np.newaxis] # pyrefly: ignore[missing-attribute]
return -cumsum_d_padded + b_boundaries * sum_d

mass_flux_full = compute_mass_flux(d_k_full)
Expand Down Expand Up @@ -1985,11 +1987,11 @@ def __post_init__(self):
raise ValueError('`reference_surface_pressure` must be positive.')
self._nondim_reference_surface_pressure = nondim_reference_surface_pressure
nondim_a_boundaries = self.physics_specs.nondimensionalize(
self.coords.vertical.a_boundaries * self.hpa_quantity
self.coords.vertical.a_boundaries * self.hpa_quantity # pyrefly: ignore[missing-attribute]
)
self.nondim_levels = hybrid_coordinates.HybridCoordinates(
a_boundaries=nondim_a_boundaries, # pyrefly: ignore[bad-argument-type]
b_boundaries=self.coords.vertical.b_boundaries,
b_boundaries=self.coords.vertical.b_boundaries, # pyrefly: ignore[missing-attribute]
)
nondim_coords = dataclasses.replace(
self.coords,
Expand Down
2 changes: 1 addition & 1 deletion dinosaur/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class RandomnessState:
nodal_value: Pytree | None = None
modal_value: Pytree | None = None
prng_key: PRNGKeyArray | None = None
prng_step: int | None = None
prng_step: int | Array | None = None


@tree_math.struct
Expand Down
3 changes: 2 additions & 1 deletion dinosaur/weatherbench_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import dataclasses

from dinosaur import typing
import jax
import tree_math


Expand All @@ -27,6 +28,6 @@ class State:
v: typing.Array
t: typing.Array
z: typing.Array
sim_time: float
sim_time: float | typing.Array | jax.sharding.PartitionSpec | None
tracers: dict[str, typing.Array] = dataclasses.field(default_factory=dict)
diagnostics: dict[str, typing.Array] = dataclasses.field(default_factory=dict)
Loading