Fix silent failure modes surfaced by extensive code review
- energy_simplex_encode: warn when clipping post_E to pre_E discards recorded edep/e_sec instead of silently zeroing them - local/inv_local_frame_rotation: validate and normalize pre_dir instead of silently assuming unit norm; raise on near-zero-norm rows - train(): make --lr authoritative on resume instead of being silently overwritten by the checkpoint's optimizer/scheduler state; print and exit cleanly instead of silently training zero epochs when the checkpoint already meets --epochs; truncate metrics.csv on a fresh run instead of always appending - dwarf update-manifest: check file existence for every manifest line, not just ones whose gen/schema actually changed - pyproject.toml: dev extra now pulls in convert+analysis so the documented `uv sync --extra cpu --extra dev` + `pytest` actually passes collection Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import numpy as np
|
||||
import pytest
|
||||
from giant.data.transforms import (
|
||||
energy_simplex_decode,
|
||||
energy_simplex_encode,
|
||||
inv_local_frame_rotation,
|
||||
inv_log_transform,
|
||||
local_frame_rotation,
|
||||
log_transform,
|
||||
@@ -53,6 +55,35 @@ def test_local_frame_rotation_preserves_norm():
|
||||
np.testing.assert_allclose(np.linalg.norm(result, axis=1), 1.0, atol=1e-5)
|
||||
|
||||
|
||||
def test_local_frame_rotation_rejects_near_zero_pre_dir():
|
||||
"""A degenerate (near-zero-norm) pre_dir has no well-defined frame — must
|
||||
raise instead of silently falling back to an arbitrary rotation axis."""
|
||||
pre_dir = np.array([[0.0, 0.0, 0.0], [0.0, 0.0, 1.0]], dtype=np.float32)
|
||||
post_dir = np.array([[1.0, 0.0, 0.0], [0.0, 1.0, 0.0]], dtype=np.float32)
|
||||
with pytest.raises(ValueError, match="near-zero norm"):
|
||||
local_frame_rotation(pre_dir, post_dir)
|
||||
with pytest.raises(ValueError, match="near-zero norm"):
|
||||
inv_local_frame_rotation(pre_dir, post_dir)
|
||||
|
||||
|
||||
def test_local_frame_rotation_normalizes_non_unit_pre_dir():
|
||||
"""A pre_dir with float32-drift norm (not exactly 1) must still produce the
|
||||
same result as its exactly-normalized counterpart, not a skewed frame."""
|
||||
rng = np.random.default_rng(9)
|
||||
N = 50
|
||||
pre_dir_unit = rng.standard_normal((N, 3)).astype(np.float32)
|
||||
pre_dir_unit /= np.linalg.norm(pre_dir_unit, axis=1, keepdims=True)
|
||||
post_dir = rng.standard_normal((N, 3)).astype(np.float32)
|
||||
post_dir /= np.linalg.norm(post_dir, axis=1, keepdims=True)
|
||||
|
||||
pre_dir_scaled = pre_dir_unit * rng.uniform(0.9, 1.1, size=(N, 1)).astype(
|
||||
np.float32
|
||||
)
|
||||
expected = local_frame_rotation(pre_dir_unit, post_dir)
|
||||
result = local_frame_rotation(pre_dir_scaled, post_dir)
|
||||
np.testing.assert_allclose(result, expected, atol=1e-4)
|
||||
|
||||
|
||||
def test_travel_direction_is_unit_norm():
|
||||
rng = np.random.default_rng(5)
|
||||
N = 50
|
||||
|
||||
Reference in New Issue
Block a user