Skip to content

fix(sso): make LottMillerSso work on any horizontal layout - #589

Merged
duncanwp merged 1 commit into
climate-analytics-lab:devfrom
JOhnsonKC201:fix/lott-miller-sso-broadcasting
Aug 6, 2026
Merged

duncanwp merged 1 commit into
climate-analytics-lab:devfrom
JOhnsonKC201:fix/lott-miller-sso-broadcasting

Conversation

@JOhnsonKC201

Copy link
Copy Markdown
Contributor

LottMillerSso opened with

nlev, ncols = state.temperature.shape

then vmapped over axis 1 and transposed its output, so it only ran on a column-vectorized (nlev, ncols) host and raised on a whole (nlev, nlon, nlat) grid:

ValueError: too many values to unpack (expected 2)

The drag itself is a per-column scheme, so it has no reason to care how the host lays out the horizontal.

ComposablePhysics(vectorize_columns=True) is not a workaround here. __add__ inherits that flag from its left operand, and a grid-based package cannot simply switch: speedy_shortwave.get_zonal_average_fields computes zonal averages and needs a real longitude axis, which flattening destroys. So composing LottMillerSso with SPEEDY was not possible in either configuration.

Fixed by flattening whatever trailing axes the host uses into one column axis, running the existing vmap unchanged, and restoring the shape on the way out. No branching on rank, and the column-vectorized path is unchanged.

Test plan

New lott_miller_host_test.py builds the pressure and height diagnostics directly rather than going through MoistAirColumnState, so it exercises this term alone:

  • grid (nlev, nlon, nlat) and column (nlev, ncols) hosts both return correctly shaped tendencies
  • the two layouts agree column for column
  • tendencies are finite

It uses the real T30 orography deliberately. With flat orography the scheme returns identically zero and every comparison passes without testing anything, so there is an explicit assertion that the drag is non-zero.

Results:

  • 4 of the 5 new tests fail without the fix; all pass with it. The survivor is test_column_host_returns_column_shaped_tendencies, the layout that already worked.
  • pytest jcm/physics/gravity_waves/ — 70 passed.
  • ruff check jcm/physics/gravity_waves/sso/ clean.

Verified beyond unit tests by composing speedy_physics() + MoistAirColumnState() + LottMillerSso() and running 450 simulated days at T31, finite throughout.

This is a shape fix only. It makes no claim that the scheme's parameters or its nktopg/ntop level indices are appropriate for any particular host resolution.

Related: #587 fixes the same class of issue in MoistAirColumnState. The two are independent and this PR does not depend on it.

🤖 Generated with Claude Code

LottMillerSso unpacked `nlev, ncols = state.temperature.shape`, vmapped over
axis 1 and transposed its output, so it only ran on a column-vectorized
(nlev, ncols) host and raised on a whole (nlev, nlon, nlat) grid:

    ValueError: too many values to unpack (expected 2)

The drag is a per-column scheme, so it has no reason to care how the host lays
out the horizontal.

ComposablePhysics(vectorize_columns=True) does not help: __add__ inherits that
flag from its left operand, and a grid-based package cannot switch to it
because speedy_shortwave.get_zonal_average_fields computes zonal averages and
needs a real longitude axis. So composing this term with SPEEDY was impossible
in either configuration.

Flatten whatever trailing axes the host uses into one column axis, run the
existing vmap unchanged, and restore the shape on the way out. No branching on
rank; the column-vectorized path is unchanged.

Adds lott_miller_host_test.py, which builds the pressure diagnostics directly
so it exercises this term alone. It uses real T30 orography deliberately, since
flat orography gives identically zero drag and every comparison would pass
vacuously. Four of the five fail without the fix.
@duncanwp

duncanwp commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

LGTM, thanks!

@duncanwp
duncanwp merged commit 71fae02 into climate-analytics-lab:dev Aug 6, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants