Upload folder using huggingface_hub
Browse files1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586from __future__ import annotations
import numpy as npimport h5pyimport json
from hpace.data_loader import segment_progress, smooth_progressfrom hpace.mjx_evaluator import phase_failure_ratesfrom hpace.router import build_expensive_maskfrom hpace.value_fusion import stable_softmaxfrom hpace.weighted_sampler import WeightedTrajectorySamplerfrom hpace.config import load_configfrom hpace.pipeline import run_curationfrom hpace.experiments import generate_baseline_weights, generate_ablation_weights
def test_progress_smoothing_and_valid_phases(): smoothed = smooth_progress(np.array([0.0, 0.4, 0.8, 1.0, 1.0]), 3) labels, valid = segment_progress(smoothed) assert np.all((labels >= 0) & (labels <= 3)) assert valid == (0, 1, 2, 3)
def test_router_requires_both_conditions(): mask = build_expensive_mask(np.array([0.1, 0.9, 0.8]), [(0,), (0, 1), (2,)], {"phase0": 0.1, "phase1": 0.0, "phase2": 0.4, "phase3": 0.0}) assert mask.tolist() == [False, False, True]
def test_fusion_and_sampler(): probabilities = stable_softmax(np.array([0.0, 1.0]), 0.5) assert np.isclose(probabilities.sum(), 1.0) sampler = WeightedTrajectorySampler(["a", "b"], [np.array([0.1, 0.2]), np.array([0.7])], seed=42) demo, frame = sampler.sample() assert demo in {"a", "b"} assert frame >= 0
def test_failure_rate_handles_unreached_phase(): rates = phase_failure_rates([np.array([0.0, 0.2]), np.array([0.0, 0.9])]) assert set(rates) == {"phase0", "phase1", "phase2", "phase3"} assert all(0.0 <= value <= 1.0 for value in rates.values())
def test_failure_rate_uses_ground_truth_completion_for_last_phase(): # Progress saturates for both rollouts, but only one actually succeeded: # the final phase rate must follow the environment flag, not the proxy. curves = [np.array([0.0, 0.9, 1.0]), np.array([0.0, 0.8, 1.0])] rates_with_flag = phase_failure_rates(curves, [True, False]) assert rates_with_flag["phase3"] == 0.5 rates_without_flag = phase_failure_rates(curves) assert rates_without_flag["phase3"] == 0.0
def test_curation_pipeline_end_to_end(tmp_path): dataset = tmp_path / "image.hdf5" progress_path = tmp_path / "progress.npz" embeddings_path = tmp_path / "embeddings.npz" fail_path = tmp_path / "fail.json" expensive_path = tmp_path / "expensive.npz" progress = {} embeddings = {} with h5py.File(dataset, "w") as handle: data = handle.create_group("data") for index in range(5): demo = data.create_group(f"demo_{index}") obs = demo.create_group("obs") obs.create_dataset("agentview_image", data=np.zeros((6, 8, 8, 3), dtype=np.uint8)) actions = np.zeros((6, 7), dtype=np.float32) actions[3, -1] = 1.0 demo.create_dataset("actions", data=actions) progress[f"demo_{index}"] = np.linspace(0, 0.5 + index * 0.1, 6, dtype=np.float32) rng = np.random.default_rng(index) embeddings[f"demo_{index}"] = rng.normal(size=(6, 4)).astype(np.float32) np.savez(progress_path, **progress) np.savez(embeddings_path, **embeddings) fail_path.write_text(json.dumps({"phase0": 0.1, "phase1": 0.4, "phase2": 0.4, "phase3": 0.1}), encoding="utf-8") np.savez(expensive_path, q_policy=np.linspace(0.1, 0.9, 4), q_perf=np.linspace(0.2, 0.8, 4)) config = load_config(overrides={"paths": {"cache_dir": str(tmp_path / "cache"), "checkpoint_dir": str(tmp_path / "ckpt"), "results_dir": str(tmp_path / "results"), "videos_dir": str(tmp_path / "videos")}}) output = run_curation(dataset, progress_path, embeddings_path, fail_path, expensive_path, config) values = np.load(output, allow_pickle=False) assert np.isclose(values["trajectory_probabilities"].sum(), 1.0) assert len(values["demo_ids"]) == 4 baselines = generate_baseline_weights(tmp_path / "cache/q_quality_scores.npz", tmp_path / "cache/full_scores.npz", tmp_path / "baselines") assert set(baselines) == {"full", "random", "scizor", "qoq", "cupid"} ablation = generate_ablation_weights("no-diversity", tmp_path / "cache/q_quality_scores.npz", tmp_path / "cache/full_scores.npz", embeddings_path, tmp_path / "ablation.npz", config["fusion"]) assert ablation.is_file().rsi/laneC/tests/test_core.pyAdded+86