Download src/package_t2_material_loading_memory_v1.py from HaomingLuo/AgentFEM-Material-Loading-Memory: direct link, hf CLI and curl.
- Browser
- Download file 5.88 kB
-
https://huggingface.co/datasets/HaomingLuo/AgentFEM-Material-Loading-Memory/resolve/main/src/package_t2_material_loading_memory_v1.py
- Command line
-
hf download hf://datasets/HaomingLuo/AgentFEM-Material-Loading-Memory/src/package_t2_material_loading_memory_v1.py
-
curl -L -o package_t2_material_loading_memory_v1.py https://huggingface.co/datasets/HaomingLuo/AgentFEM-Material-Loading-Memory/resolve/main/src/package_t2_material_loading_memory_v1.py
5.88 kB
| """Create and verify the public whitelist package for T2 v1.""" | |
| from __future__ import annotations | |
| import hashlib | |
| import json | |
| import shutil | |
| from pathlib import Path | |
| import h5py | |
| import numpy as np | |
| ROOT = Path(__file__).resolve().parents[1] | |
| DATA_DIR = ROOT / "data" / "t2_material_loading_memory_v1" | |
| ARTIFACT_DIR = ROOT / "artifacts" / "t2_material_loading_memory_v1" | |
| RELEASE_DIR = ROOT / "releases" / "t2_material_loading_memory_v1" | |
| UPLOAD_DIR = RELEASE_DIR / "upload" | |
| def _sha256(path: Path) -> str: | |
| digest = hashlib.sha256() | |
| with path.open("rb") as stream: | |
| for block in iter(lambda: stream.read(1024 * 1024), b""): | |
| digest.update(block) | |
| return digest.hexdigest() | |
| def _copy(relative_source: str, relative_destination: str | None = None) -> Path: | |
| source = ROOT / relative_source | |
| destination = UPLOAD_DIR / (relative_destination or relative_source) | |
| destination.parent.mkdir(parents=True, exist_ok=True) | |
| shutil.copy2(source, destination) | |
| return destination | |
| def build() -> dict[str, object]: | |
| manifest = json.loads((DATA_DIR / "manifest.json").read_text(encoding="utf-8")) | |
| quality = json.loads((ARTIFACT_DIR / "quality.json").read_text(encoding="utf-8")) | |
| baseline = json.loads( | |
| (ARTIFACT_DIR / "baseline_metrics.json").read_text(encoding="utf-8") | |
| ) | |
| if quality["status"] != "accepted" or quality["quality_failure_count"] != 0: | |
| raise RuntimeError("Refusing to package a dataset that did not pass quality gates.") | |
| if baseline["status"] != "completed": | |
| raise RuntimeError("Baseline is incomplete.") | |
| if UPLOAD_DIR.exists(): | |
| shutil.rmtree(UPLOAD_DIR) | |
| UPLOAD_DIR.mkdir(parents=True) | |
| copied = [ | |
| _copy("data/t2_material_loading_memory_v1/README.md", "README.md"), | |
| _copy("data/t2_material_loading_memory_v1/design.jsonl"), | |
| _copy("data/t2_material_loading_memory_v1/index.jsonl"), | |
| _copy("data/t2_material_loading_memory_v1/manifest.json"), | |
| _copy("artifacts/t2_material_loading_memory_v1/QUALITY_REPORT.md"), | |
| _copy("artifacts/t2_material_loading_memory_v1/quality.json"), | |
| _copy("artifacts/t2_material_loading_memory_v1/hysteresis_preview.png"), | |
| _copy("artifacts/t2_material_loading_memory_v1/baseline_metrics.json"), | |
| _copy("artifacts/t2_material_loading_memory_v1/baseline_predictions.png"), | |
| _copy("artifacts/t2_material_loading_memory_v1/baseline_models.pt"), | |
| _copy("configs/t2_material_loading_memory_pilot.json"), | |
| _copy("configs/t2_material_loading_memory_v1.json"), | |
| _copy("src/t2_material_loading_memory.py"), | |
| _copy("src/t2_material_loading_memory_v1.py"), | |
| _copy("src/load_t2_material_loading_memory.py"), | |
| _copy("src/baseline_t2_material_loading_memory.py"), | |
| _copy("src/verify_t2_download.py"), | |
| _copy("src/package_t2_material_loading_memory_v1.py"), | |
| _copy("tests/test_t2_material_loading_memory.py"), | |
| _copy("tests/test_t2_material_loading_memory_v1.py"), | |
| _copy("handoff/t2_material_loading_memory_v1/START_HERE.md", "START_HERE.md"), | |
| _copy("handoff/t2_material_loading_memory_v1/REPRODUCE.md", "REPRODUCE.md"), | |
| _copy("handoff/t2_material_loading_memory_v1/PAPER_ROADMAP.md", "PAPER_ROADMAP.md"), | |
| _copy("handoff/t2_material_loading_memory_v1/KNOWN_LIMITATIONS.md", "KNOWN_LIMITATIONS.md"), | |
| _copy("handoff/t2_material_loading_memory_v1/environment-use.yml", "environment-use.yml"), | |
| _copy( | |
| "handoff/t2_material_loading_memory_v1/environment-reproduce.yml", | |
| "environment-reproduce.yml", | |
| ), | |
| _copy( | |
| "handoff/t2_material_loading_memory_v1/reproduce_t2_v1.sh", | |
| "reproduce_t2_v1.sh", | |
| ), | |
| _copy("releases/t1_layered_thermoelastic_v1/upload/DATA_LICENSE.md", "DATA_LICENSE.md"), | |
| _copy("releases/t1_layered_thermoelastic_v1/upload/CODE_LICENSE", "CODE_LICENSE"), | |
| ] | |
| for shard in manifest["shards"]: | |
| copied.append(_copy(shard["path"])) | |
| readme = UPLOAD_DIR / "README.md" | |
| readme.write_text( | |
| readme.read_text(encoding="utf-8").replace("../../artifacts/", "artifacts/"), | |
| encoding="utf-8", | |
| ) | |
| sums_path = UPLOAD_DIR / "SHA256SUMS" | |
| lines = [] | |
| for path in sorted(copied): | |
| relative = path.relative_to(UPLOAD_DIR) | |
| lines.append(f"{_sha256(path)} {relative}") | |
| sums_path.write_text("\n".join(lines) + "\n", encoding="utf-8") | |
| expected_ids = [f"{index:05d}" for index in range(manifest["sample_count"])] | |
| observed_ids: list[str] = [] | |
| for shard in manifest["shards"]: | |
| packaged = UPLOAD_DIR / shard["path"] | |
| if _sha256(packaged) != shard["sha256"]: | |
| raise RuntimeError(f"Packaged shard hash mismatch: {shard['path']}") | |
| with h5py.File(packaged, "r") as h5: | |
| observed_ids.extend(sorted(h5.keys())) | |
| for group in h5.values(): | |
| if not all(np.isfinite(group[name][:]).all() for name in group.keys()): | |
| raise RuntimeError("Packaged shard contains non-finite values.") | |
| if observed_ids != expected_ids: | |
| raise RuntimeError("Packaged sample IDs are incomplete or out of order.") | |
| result = { | |
| "status": "verified", | |
| "sample_count": manifest["sample_count"], | |
| "shard_count": len(manifest["shards"]), | |
| "file_count_including_sha256sums": len(copied) + 1, | |
| "bytes_excluding_sha256sums": sum(path.stat().st_size for path in copied), | |
| "upload_directory": str(UPLOAD_DIR), | |
| } | |
| RELEASE_DIR.mkdir(parents=True, exist_ok=True) | |
| (RELEASE_DIR / "release_check.json").write_text( | |
| json.dumps(result, indent=2, sort_keys=True) + "\n", encoding="utf-8" | |
| ) | |
| print(json.dumps(result, indent=2, sort_keys=True)) | |
| return result | |
| if __name__ == "__main__": | |
| build() | |