Datasets:
Download code/test_v3.py from tchaudha/heat-seekers-protostar: direct link, hf CLI and curl.
- Browser
- Download file 2.27 kB
-
https://huggingface.co/datasets/tchaudha/heat-seekers-protostar/resolve/main/code/test_v3.py
- Command line
-
hf download hf://datasets/tchaudha/heat-seekers-protostar/code/test_v3.py
-
curl -L -o test_v3.py https://huggingface.co/datasets/tchaudha/heat-seekers-protostar/resolve/main/code/test_v3.py
2.27 kB
| """Offline tests for v3 ablations: leakage, protocol freeze, harness parity with v2, submission validity.""" | |
| import ast, io, hashlib, json, sys, unittest | |
| import numpy as np, pandas as pd | |
| sys.path.insert(0, str(__import__('pathlib').Path(__file__).resolve().parent)) | |
| from v3lib import * | |
| import make_submission_v3 as ms3 | |
| P = attach(Panel()); OFF = ROOT / 'research/official/protostar-challenge-climate-risk-intelligence' | |
| class V3(unittest.TestCase): | |
| def test_poisoned_future_does_not_change_any_candidate(self): | |
| for o in (1990, 2008): | |
| a = v3_block(P, o); b = v3_block(cut(P, o), o) | |
| pd.testing.assert_frame_equal(a, b) | |
| def test_protocol_frozen(self): | |
| h = hashlib.sha256((ROOT / 'research/V3_PROTOCOL.md').read_bytes()).hexdigest() | |
| self.assertEqual(h, (ROOT / 'results/v3_protocol_hash.txt').read_text().split()[0]) | |
| def test_reference_methods_match_v2(self): | |
| o = 2004; f3 = v3_block(P, o); f2 = forecast_block(P, o, configs=[(15, 0.0, 'national')]) | |
| for m3, m2, met in (('v2', 'LT_L15_a0_national', 'annual_avg_temp'), ('v2b', 'SHmean_L15_a0_national', 'cdd'), ('exp10', 'exp10', 'cdd')): | |
| a = f3[(f3.method == m3) & (f3.metric == met)].predicted_value.to_numpy(); b = f2[(f2.method == m2) & (f2.metric == met)].predicted_value.to_numpy() | |
| np.testing.assert_allclose(a, b, rtol=0, atol=1e-9) | |
| def test_submission_valid_and_deterministic(self): | |
| tree = ast.parse((OFF / 'utils.py').read_text(encoding='utf-8')) | |
| pure = [n for n in tree.body if isinstance(n, ast.FunctionDef) and n.name == 'check_forecasts'] | |
| ns = dict(pd=pd, io=io, CITY_IDS=set((OFF / 'data/city_ids.txt').read_text().split()), YEARS=set(range(2019, 2026)), | |
| METRICS=set(METRICS), COLUMNS=KEY + ['predicted_value']) | |
| exec(compile(ast.Module(body=pure, type_ignores=[]), 'utils.py', 'exec'), ns) | |
| out, _ = ms3.build(P); buf = out.to_csv(index=False, float_format='%.6f').encode() | |
| self.assertIsNone(ns['check_forecasts'](buf)); self.assertEqual(len(out), 5880) | |
| self.assertEqual(hashlib.sha256(buf).hexdigest(), json.loads((ROOT / 'results/submission_v3.json').read_text())['sha256']) | |
| if __name__ == '__main__': unittest.main(verbosity=2) | |