manual-sync 2026-07-02T20:50:21Z local-atlas-guided-flow tests
Browse files
workspace/tests/test_tangent_local_atlas.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from dovla_cil.generation.tangent_local_atlas import LocalAtlasConfig
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def test_local_atlas_config_validates_retrieval_parameters() -> None:
|
| 7 |
+
LocalAtlasConfig(neighbor_pool=16, utility_weight=0.0, diversity_weight=0.1)
|
| 8 |
+
|
| 9 |
+
try:
|
| 10 |
+
LocalAtlasConfig(neighbor_pool=0)
|
| 11 |
+
except ValueError as exc:
|
| 12 |
+
assert "neighbor_pool" in str(exc)
|
| 13 |
+
else: # pragma: no cover
|
| 14 |
+
raise AssertionError("neighbor_pool must be positive")
|
| 15 |
+
|
| 16 |
+
try:
|
| 17 |
+
LocalAtlasConfig(utility_weight=-0.1)
|
| 18 |
+
except ValueError as exc:
|
| 19 |
+
assert "utility_weight" in str(exc)
|
| 20 |
+
else: # pragma: no cover
|
| 21 |
+
raise AssertionError("utility_weight must be non-negative")
|
| 22 |
+
|
| 23 |
+
try:
|
| 24 |
+
LocalAtlasConfig(diversity_weight=-0.1)
|
| 25 |
+
except ValueError as exc:
|
| 26 |
+
assert "diversity_weight" in str(exc)
|
| 27 |
+
else: # pragma: no cover
|
| 28 |
+
raise AssertionError("diversity_weight must be non-negative")
|
workspace/tests/test_tangent_spline_cvae.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from dovla_cil.generation.tangent_spline_cvae import (
|
| 4 |
+
build_spline_tangent_rows,
|
| 5 |
+
decode_keyframe_spline,
|
| 6 |
+
)
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def _target(value: float) -> dict:
|
| 10 |
+
matrix = [
|
| 11 |
+
[0.0, 0.0],
|
| 12 |
+
[value, 0.0],
|
| 13 |
+
[2.0 * value, 0.0],
|
| 14 |
+
]
|
| 15 |
+
return {
|
| 16 |
+
"group_id": f"g-{value}",
|
| 17 |
+
"task_id": "PickCube-v1",
|
| 18 |
+
"instruction": "Pick up the cube.",
|
| 19 |
+
"observation_inline": {"features": [0.1, 0.2]},
|
| 20 |
+
"candidate_type": "near_miss",
|
| 21 |
+
"tangent_label": "positive",
|
| 22 |
+
"delta_utility": 1.0,
|
| 23 |
+
"delta_action": matrix,
|
| 24 |
+
"tangent_summary": {
|
| 25 |
+
"start_delta": matrix[0],
|
| 26 |
+
"midpoint_delta": matrix[1],
|
| 27 |
+
"endpoint_delta": matrix[2],
|
| 28 |
+
},
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def test_decode_keyframe_spline_preserves_keyframes() -> None:
|
| 33 |
+
code = [0.0, 0.0, 1.0, 0.0, 2.0, 0.0]
|
| 34 |
+
decoded = decode_keyframe_spline(code, horizon=3, action_dim=2)
|
| 35 |
+
|
| 36 |
+
assert decoded == [0.0, 0.0, 1.0, 0.0, 2.0, 0.0]
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def test_build_spline_tangent_rows_uses_start_mid_end_code() -> None:
|
| 40 |
+
rows, tasks, code_dim, horizon, action_dim = build_spline_tangent_rows(
|
| 41 |
+
[_target(0.5)],
|
| 42 |
+
obs_dim=4,
|
| 43 |
+
text_dim=8,
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
assert tasks == ["PickCube-v1"]
|
| 47 |
+
assert code_dim == 6
|
| 48 |
+
assert horizon == 3
|
| 49 |
+
assert action_dim == 2
|
| 50 |
+
assert rows[0].code == [0.0, 0.0, 0.5, 0.0, 1.0, 0.0]
|
workspace/tests/test_tangent_spline_flow.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from dovla_cil.generation.tangent_spline_flow import SplineFlowConfig
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def test_spline_flow_config_validates_sampling_parameters() -> None:
|
| 7 |
+
SplineFlowConfig(sample_steps=4, noise_scale=0.5)
|
| 8 |
+
|
| 9 |
+
try:
|
| 10 |
+
SplineFlowConfig(sample_steps=0)
|
| 11 |
+
except ValueError as exc:
|
| 12 |
+
assert "sample_steps" in str(exc)
|
| 13 |
+
else: # pragma: no cover
|
| 14 |
+
raise AssertionError("sample_steps must be positive")
|
| 15 |
+
|
| 16 |
+
try:
|
| 17 |
+
SplineFlowConfig(noise_scale=0.0)
|
| 18 |
+
except ValueError as exc:
|
| 19 |
+
assert "noise_scale" in str(exc)
|
| 20 |
+
else: # pragma: no cover
|
| 21 |
+
raise AssertionError("noise_scale must be positive")
|
workspace/tests/test_tangent_spline_guided_flow.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from dovla_cil.generation.tangent_spline_guided_flow import GuidedSplineFlowConfig
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def test_guided_spline_flow_config_validates_guidance_parameters() -> None:
|
| 7 |
+
GuidedSplineFlowConfig(
|
| 8 |
+
sample_steps=4,
|
| 9 |
+
noise_scale=0.5,
|
| 10 |
+
guidance_scale=0.5,
|
| 11 |
+
guidance_grad_clip=0.25,
|
| 12 |
+
proposal_pool_multiplier=2,
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
try:
|
| 16 |
+
GuidedSplineFlowConfig(guidance_scale=-0.1)
|
| 17 |
+
except ValueError as exc:
|
| 18 |
+
assert "guidance_scale" in str(exc)
|
| 19 |
+
else: # pragma: no cover
|
| 20 |
+
raise AssertionError("guidance_scale must be non-negative")
|
| 21 |
+
|
| 22 |
+
try:
|
| 23 |
+
GuidedSplineFlowConfig(guidance_grad_clip=0.0)
|
| 24 |
+
except ValueError as exc:
|
| 25 |
+
assert "guidance_grad_clip" in str(exc)
|
| 26 |
+
else: # pragma: no cover
|
| 27 |
+
raise AssertionError("guidance_grad_clip must be positive")
|
| 28 |
+
|
| 29 |
+
try:
|
| 30 |
+
GuidedSplineFlowConfig(proposal_pool_multiplier=0)
|
| 31 |
+
except ValueError as exc:
|
| 32 |
+
assert "proposal_pool_multiplier" in str(exc)
|
| 33 |
+
else: # pragma: no cover
|
| 34 |
+
raise AssertionError("proposal_pool_multiplier must be positive")
|