Download hilbert_mi/utils.py from kiruluta/Hilbert-Operator-Intelligence: direct link, hf CLI and curl.
- Browser
- Download file 756 Bytes
-
https://huggingface.co/kiruluta/Hilbert-Operator-Intelligence/resolve/main/hilbert_mi/utils.py
- Command line
-
hf download hf://kiruluta/Hilbert-Operator-Intelligence/hilbert_mi/utils.py
-
curl -L -o utils.py https://huggingface.co/kiruluta/Hilbert-Operator-Intelligence/resolve/main/hilbert_mi/utils.py
756 Bytes
| """General helpers.""" | |
| from __future__ import annotations | |
| import json | |
| import os | |
| import random | |
| from pathlib import Path | |
| import numpy as np | |
| import torch | |
| def set_seed(seed: int) -> None: | |
| random.seed(seed) | |
| np.random.seed(seed) | |
| torch.manual_seed(seed) | |
| torch.cuda.manual_seed_all(seed) | |
| def ensure_dir(path: str | os.PathLike) -> Path: | |
| p = Path(path) | |
| p.mkdir(parents=True, exist_ok=True) | |
| return p | |
| def save_json(obj, path: str | os.PathLike) -> None: | |
| path = Path(path) | |
| path.parent.mkdir(parents=True, exist_ok=True) | |
| with open(path, "w", encoding="utf-8") as f: | |
| json.dump(obj, f, indent=2) | |
| def load_json(path: str | os.PathLike): | |
| with open(path, "r", encoding="utf-8") as f: | |
| return json.load(f) | |