anhtld commited on
Commit
da692c5
·
verified ·
1 Parent(s): 0c096c5

manual-sync chart-synthesis 2026-07-02T22:45:08Z workspace/tests/test_tangent_chart_synthesis.py

Browse files
workspace/tests/test_tangent_chart_synthesis.py ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ from dovla_cil.generation.tangent_chart_synthesis import (
4
+ ChartSynthesisConfig,
5
+ _select_chart_proposals,
6
+ )
7
+ from dovla_cil.generation.tangent_memory import TangentExample
8
+ from dovla_cil.generation.tangent_spline_cvae import SplineTangentRow
9
+
10
+
11
+ def test_chart_synthesis_config_validates_parameters() -> None:
12
+ ChartSynthesisConfig(
13
+ neighbor_pool=8,
14
+ direct_count=2,
15
+ barycentric_windows=(2, 4),
16
+ barycentric_temperature=0.5,
17
+ utility_weight=0.1,
18
+ order="interleave",
19
+ )
20
+
21
+ for kwargs, expected in [
22
+ ({"neighbor_pool": 0}, "neighbor_pool"),
23
+ ({"direct_count": -1}, "direct_count"),
24
+ ({"barycentric_windows": (0,)}, "barycentric_windows"),
25
+ ({"barycentric_temperature": 0.0}, "barycentric_temperature"),
26
+ ({"utility_weight": -0.1}, "utility_weight"),
27
+ ({"order": "bad"}, "order"),
28
+ ]:
29
+ try:
30
+ ChartSynthesisConfig(**kwargs)
31
+ except ValueError as exc:
32
+ assert expected in str(exc)
33
+ else: # pragma: no cover
34
+ raise AssertionError(f"{expected} should be validated")
35
+
36
+
37
+ def test_chart_synthesis_interleaves_direct_and_barycentric_proposals() -> None:
38
+ query = _row("query", [0.0, 0.0], [0.0, 0.0])
39
+ train = [
40
+ _row("a", [0.0, 0.0], [1.0, 0.0]),
41
+ _row("b", [0.1, 0.0], [3.0, 0.0]),
42
+ _row("c", [1.0, 0.0], [9.0, 0.0]),
43
+ ]
44
+ config = ChartSynthesisConfig(
45
+ neighbor_pool=3,
46
+ direct_count=1,
47
+ barycentric_windows=(2,),
48
+ barycentric_temperature=1.0,
49
+ order="interleave",
50
+ )
51
+
52
+ proposals = _select_chart_proposals(
53
+ query,
54
+ train_positive=train,
55
+ train_positive_by_task={"task": train},
56
+ config=config,
57
+ max_k=3,
58
+ )
59
+
60
+ assert proposals[0] == [1.0, 0.0]
61
+ assert 1.0 < proposals[1][0] < 3.0
62
+ assert proposals[2] == [3.0, 0.0]
63
+
64
+
65
+ def _row(group_id: str, condition: list[float], delta: list[float]) -> SplineTangentRow:
66
+ return SplineTangentRow(
67
+ example=TangentExample(
68
+ group_id=group_id,
69
+ task_id="task",
70
+ candidate_type="candidate",
71
+ tangent_label="positive",
72
+ delta_utility=1.0,
73
+ delta_action=[delta],
74
+ ),
75
+ condition=condition,
76
+ code=delta,
77
+ full_delta=delta,
78
+ horizon=1,
79
+ action_dim=len(delta),
80
+ )