auto-sync 2026-07-03T18:45:41Z workspace (part 4)
Browse files- workspace/tests/test_ctt.py +34 -0
workspace/tests/test_ctt.py
CHANGED
|
@@ -13,8 +13,10 @@ from scripts.eval_ctt_generated_rollout import (
|
|
| 13 |
_action_bound_diagnostics_4d,
|
| 14 |
_clip_to_action_space_4d,
|
| 15 |
_measured_row_from_rollout,
|
|
|
|
| 16 |
_scale_actions_4d,
|
| 17 |
_source_pool_for_target,
|
|
|
|
| 18 |
)
|
| 19 |
|
| 20 |
|
|
@@ -140,6 +142,34 @@ def test_execution_action_scale_applies_before_bound_diagnostics():
|
|
| 140 |
assert diagnostics["violation"].tolist() == [[False]]
|
| 141 |
|
| 142 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
def test_measured_rollout_row_records_action_bound_safety_source():
|
| 144 |
target = ChartItem(
|
| 145 |
chart_id="chart_a",
|
|
@@ -175,9 +205,13 @@ def test_measured_rollout_row_records_action_bound_safety_source():
|
|
| 175 |
action_clip_max_abs=[0.0, 0.2],
|
| 176 |
restore_error=0.0,
|
| 177 |
execution_action_scale=0.25,
|
|
|
|
|
|
|
| 178 |
)
|
| 179 |
|
| 180 |
assert row["execution_action_scale"] == pytest.approx(0.25)
|
|
|
|
|
|
|
| 181 |
assert row["base_outcome"]["safety_violation"] is False
|
| 182 |
assert row["base_outcome"]["safety_violation_source"] == "action_bounds"
|
| 183 |
assert row["candidate_outcomes"][0]["safety_violation"] is True
|
|
|
|
| 13 |
_action_bound_diagnostics_4d,
|
| 14 |
_clip_to_action_space_4d,
|
| 15 |
_measured_row_from_rollout,
|
| 16 |
+
_parse_execution_action_scale_vector,
|
| 17 |
_scale_actions_4d,
|
| 18 |
_source_pool_for_target,
|
| 19 |
+
_transform_actions_4d,
|
| 20 |
)
|
| 21 |
|
| 22 |
|
|
|
|
| 142 |
assert diagnostics["violation"].tolist() == [[False]]
|
| 143 |
|
| 144 |
|
| 145 |
+
def test_execution_action_scale_vector_is_dimension_wise():
|
| 146 |
+
actions = np.asarray([[[[2.0, -4.0, 3.0]]]], dtype=np.float32)
|
| 147 |
+
vector = _parse_execution_action_scale_vector("0.5,0.25,2.0")
|
| 148 |
+
|
| 149 |
+
scaled = _scale_actions_4d(actions, 0.5, scale_vector=vector)
|
| 150 |
+
|
| 151 |
+
assert vector is not None
|
| 152 |
+
assert scaled.tolist() == [[[[0.5, -0.5, 3.0]]]]
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
def test_tanh_execution_transform_maps_to_env_bounds():
|
| 156 |
+
env = SimpleNamespace(
|
| 157 |
+
single_action_space=SimpleNamespace(
|
| 158 |
+
low=np.asarray([-1.0, -2.0], dtype=np.float32),
|
| 159 |
+
high=np.asarray([1.0, 2.0], dtype=np.float32),
|
| 160 |
+
)
|
| 161 |
+
)
|
| 162 |
+
actions = np.asarray([[[[10.0, -10.0]]]], dtype=np.float32)
|
| 163 |
+
|
| 164 |
+
transformed = _transform_actions_4d(actions, env, "tanh")
|
| 165 |
+
diagnostics = _action_bound_diagnostics_4d(transformed, env)
|
| 166 |
+
|
| 167 |
+
assert transformed[0, 0, 0, 0] <= 1.0
|
| 168 |
+
assert transformed[0, 0, 0, 1] >= -2.0
|
| 169 |
+
assert diagnostics is not None
|
| 170 |
+
assert diagnostics["violation"].tolist() == [[False]]
|
| 171 |
+
|
| 172 |
+
|
| 173 |
def test_measured_rollout_row_records_action_bound_safety_source():
|
| 174 |
target = ChartItem(
|
| 175 |
chart_id="chart_a",
|
|
|
|
| 205 |
action_clip_max_abs=[0.0, 0.2],
|
| 206 |
restore_error=0.0,
|
| 207 |
execution_action_scale=0.25,
|
| 208 |
+
execution_action_scale_vector=np.asarray([0.5, 2.0], dtype=np.float32),
|
| 209 |
+
execution_action_transform="tanh",
|
| 210 |
)
|
| 211 |
|
| 212 |
assert row["execution_action_scale"] == pytest.approx(0.25)
|
| 213 |
+
assert row["execution_action_scale_vector"] == [0.5, 2.0]
|
| 214 |
+
assert row["execution_action_transform"] == "tanh"
|
| 215 |
assert row["base_outcome"]["safety_violation"] is False
|
| 216 |
assert row["base_outcome"]["safety_violation_source"] == "action_bounds"
|
| 217 |
assert row["candidate_outcomes"][0]["safety_violation"] is True
|