Skip to content

Commit e8f0856

Browse files
committed
rm new unit tests, better covered by the integration test.
1 parent 57a3ba7 commit e8f0856

1 file changed

Lines changed: 1 addition & 71 deletions

File tree

tests/test_encoder.py

Lines changed: 1 addition & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import pytest
21
import torch
32
from perceiver_pytorch import Perceiver
43

54
from ocean_emulators.constants import Lat, Lon
6-
from ocean_emulators.models.modules.encoder import PerceiverEncoder, patch_from
5+
from ocean_emulators.models.modules.encoder import PerceiverEncoder
76

87
LATENT_DIM = 4
98

@@ -85,72 +84,3 @@ def test_makes_patches__more_variables():
8584
patches = encoder(prog, boundary, make_resolution(prog))
8685

8786
assert patches.shape == (1, embed_dim, 1, 2)
88-
89-
90-
def test_cross_resolution_token_fuse():
91-
"""Prog at 1/4 degree (8x16) and boundary at 1 degree (2x4) produce the same latent grid."""
92-
embed_dim = 4
93-
prog = torch.randn(1, 7, 8, 16)
94-
boundary = torch.randn(1, 3, 2, 4)
95-
96-
encoder = make_encoder(7, 3, embed_dim, (90, 90))
97-
98-
prog_res = (
99-
torch.linspace(-90, 90, 8),
100-
torch.linspace(0, 360, 16),
101-
)
102-
patches = encoder(prog, boundary, prog_res)
103-
104-
# Both grids with 90-degree patches → 2 lat patches, 4 lon patches
105-
assert patches.shape == (1, embed_dim, 2, 4)
106-
assert torch.isfinite(patches).all(), "Output contains NaN or Inf."
107-
108-
109-
def test_latent_grid_mismatch_raises():
110-
"""Misaligned latent grids between prog and boundary should raise."""
111-
112-
embed_dim = 4
113-
# prog: 8x16 with patch_extent=(90,90) → ph=4,pw=4 → latent 2x4
114-
# boundary: 4x6 with same extent → ph=2,pw=2 → latent 2x3 (mismatch on lon)
115-
prog = torch.randn(1, 7, 8, 16)
116-
boundary = torch.randn(1, 3, 4, 6)
117-
118-
encoder = make_encoder(7, 3, embed_dim, (90, 90))
119-
prog_res = (torch.linspace(-90, 90, 8), torch.linspace(0, 360, 16))
120-
121-
with pytest.raises(AssertionError, match="Latent grid mismatch"):
122-
encoder(prog, boundary, prog_res)
123-
124-
125-
def test_gradients_flow_to_both_streams():
126-
"""Gradients flow from the output back to both prognostic and boundary inputs."""
127-
embed_dim = 4
128-
prog = torch.randn(1, 7, 4, 8, requires_grad=True)
129-
boundary = torch.randn(1, 3, 4, 8, requires_grad=True)
130-
131-
encoder = make_encoder(7, 3, embed_dim, (180, 180))
132-
out = encoder(prog, boundary, make_resolution(prog))
133-
out.sum().backward()
134-
135-
assert prog.grad is not None and prog.grad.abs().sum() > 0, (
136-
"Gradients must flow to prognostic input."
137-
)
138-
assert boundary.grad is not None and boundary.grad.abs().sum() > 0, (
139-
"Gradients must flow to boundary input."
140-
)
141-
142-
143-
def test_patch_from__full_globe():
144-
patch_h, patch_w = patch_from(
145-
patch_extent=(180.0, 360.0), input_height=4, input_width=8
146-
)
147-
assert patch_h == 4
148-
assert patch_w == 8
149-
150-
151-
def test_patch_from__half_extent():
152-
patch_h, patch_w = patch_from(
153-
patch_extent=(90.0, 180.0), input_height=4, input_width=8
154-
)
155-
assert patch_h == 2
156-
assert patch_w == 4

0 commit comments

Comments
 (0)