Download fair-comparison/flow-v1/code/lim/smoke.py from OpenGHz/keypose-vs-dense: direct link, hf CLI and curl.
- Browser
- Download file 2.7 kB
-
https://huggingface.co/datasets/OpenGHz/keypose-vs-dense/resolve/main/fair-comparison/flow-v1/code/lim/smoke.py
- Command line
-
hf download hf://datasets/OpenGHz/keypose-vs-dense/fair-comparison/flow-v1/code/lim/smoke.py
-
curl -L -o smoke.py https://huggingface.co/datasets/OpenGHz/keypose-vs-dense/resolve/main/fair-comparison/flow-v1/code/lim/smoke.py
2.7 kB
| """Exercise CUDA, physical stepping, and measured camera observations.""" | |
| import json | |
| from pathlib import Path | |
| import gymnasium as gym | |
| import imageio.v3 as iio | |
| import mani_skill.envs # noqa: F401 | |
| import torch | |
| from pydantic import BaseModel, ConfigDict | |
| from pydantic_settings import CliApp | |
| class SmokeConfig(BaseModel, frozen=True): | |
| model_config = ConfigDict(extra="forbid", use_attribute_docstrings=True) | |
| output_dir: Path = Path("artifacts/smoke") | |
| """Directory for a rendered scene and the observed environment witness.""" | |
| device: str = "cuda:0" | |
| """CUDA device used for the seeded kernel witness.""" | |
| seed: int = 0 | |
| """Seed for both the kernel and environment reset.""" | |
| def run_smoke(config: SmokeConfig) -> dict: | |
| torch.manual_seed(config.seed) | |
| x = torch.randn(32, 32, device=config.device) | |
| witness = (x @ x.T).diagonal().sum().item() | |
| assert witness > 0 and torch.isfinite(x).all() | |
| env = gym.make( | |
| "StackCube-v1", | |
| obs_mode="pointcloud", | |
| control_mode="pd_ee_delta_pose", | |
| sim_backend="cpu", | |
| render_mode="rgb_array", | |
| robot_uids="panda", | |
| max_episode_steps=200, | |
| ) | |
| try: | |
| obs, _ = env.reset(seed=config.seed) | |
| cloud = obs["pointcloud"] | |
| valid = cloud["xyzw"][..., 3] > 0 | |
| assert valid.any() and torch.isfinite(cloud["xyzw"]).all() | |
| action = env.action_space.sample() * 0 | |
| _, _, _, _, info = env.step(action) | |
| frame = env.render() | |
| if hasattr(frame, "cpu"): | |
| frame = frame.cpu().numpy() | |
| if frame.ndim == 4: | |
| frame = frame[0] | |
| assert frame.ndim == 3 and frame.shape[-1] == 3 and frame.max() > 0 | |
| config.output_dir.mkdir(parents=True, exist_ok=True) | |
| iio.imwrite(config.output_dir / "stackcube.png", frame) | |
| result = { | |
| "status": "PASS", | |
| "scope": "CUDA, physical stepping, and rendering only; no learned policy", | |
| "gpu": torch.cuda.get_device_name(config.device), | |
| "torch": torch.__version__, | |
| "cuda": torch.version.cuda, | |
| "seed": config.seed, | |
| "kernel_witness": witness, | |
| "valid_depth_points": int(valid.sum()), | |
| "image_shape": list(frame.shape), | |
| "initial_step_success": info["success"].tolist(), | |
| "available_extra_keys": sorted(obs["extra"]), | |
| } | |
| (config.output_dir / "witness.json").write_text( | |
| json.dumps(result, indent=2) + "\n" | |
| ) | |
| print("ENV_WITNESS", json.dumps(result), flush=True) | |
| return result | |
| finally: | |
| env.close() | |
| if __name__ == "__main__": | |
| run_smoke(CliApp.run(SmokeConfig)) | |