Download conditional_v2/src/validate_t2_denim_conditional_v2.py from HaomingLuo/AgentFEM-Material-Loading-Memory: direct link, hf CLI and curl.
- Browser
- Download file 3.18 kB
-
https://huggingface.co/datasets/HaomingLuo/AgentFEM-Material-Loading-Memory/resolve/main/conditional_v2/src/validate_t2_denim_conditional_v2.py
- Command line
-
hf download hf://datasets/HaomingLuo/AgentFEM-Material-Loading-Memory/conditional_v2/src/validate_t2_denim_conditional_v2.py
-
curl -L -o validate_t2_denim_conditional_v2.py https://huggingface.co/datasets/HaomingLuo/AgentFEM-Material-Loading-Memory/resolve/main/conditional_v2/src/validate_t2_denim_conditional_v2.py
3.18 kB
| """Physical and runtime audit for the refined conditional DENIM v2.""" | |
| from __future__ import annotations | |
| import json | |
| import time | |
| from collections import defaultdict | |
| import torch | |
| from src.t2_denim_conditional import ConditionalDENIM, rollout | |
| from src.train_t2_denim_conditional_v2 import ARTIFACT_DIR, MODEL_DIR, load_all_trajectories | |
| def run() -> dict[str, object]: | |
| checkpoint = torch.load( | |
| MODEL_DIR / "denim_conditional_v2_refined.pt", | |
| map_location="cpu", | |
| weights_only=False, | |
| ) | |
| model = ConditionalDENIM() | |
| model.load_state_dict(checkpoint["state_dict"]) | |
| model.eval() | |
| trajectories = load_all_trajectories() | |
| groups: dict[str, list] = defaultdict(list) | |
| for trajectory in trajectories: | |
| groups[trajectory.evaluation].append(trajectory) | |
| selected = ( | |
| groups["hidden_frozen_test"][:8] | |
| + groups["test_path_ood"][:8] | |
| + groups["test_long_horizon"][:8] | |
| ) | |
| strain = torch.stack([item.strain for item in selected]) | |
| started = time.perf_counter() | |
| with torch.no_grad(): | |
| result = rollout( | |
| strain, | |
| torch.tensor([item.young for item in selected]), | |
| torch.tensor([item.poisson for item in selected]), | |
| torch.tensor([item.yield_stress for item in selected]), | |
| torch.stack([item.descriptor for item in selected]), | |
| model, | |
| bisection_iterations=24, | |
| ) | |
| seconds = time.perf_counter() - started | |
| reference = torch.stack([item.stress for item in selected]) | |
| error = result["stress"] - reference | |
| active = result["plastic_increment"] > 1.0e-11 | |
| report = { | |
| "model": "material-conditioned DENIM v2 refined", | |
| "parameter_count": sum(parameter.numel() for parameter in model.parameters()), | |
| "audit_trajectory_count": len(selected), | |
| "audit_state_point_count": int(strain.shape[0] * strain.shape[1]), | |
| "stress_rmse_mpa": float(torch.sqrt(error.square().mean()) / 1.0e6), | |
| "maximum_yield_residual_pa": float(result["yield_residual"][active].abs().max()), | |
| "minimum_peeq_increment": float(torch.diff(result["peeq"], dim=1).min()), | |
| "maximum_plastic_strain_trace": float( | |
| result["plastic_strain"][..., :3].sum(dim=-1).abs().max() | |
| ), | |
| "maximum_memory_trace_pa": float( | |
| result["memories"][..., :3].sum(dim=-1).abs().max() | |
| ), | |
| "all_finite": all(torch.isfinite(value).all() for value in result.values()), | |
| "inference_seconds": seconds, | |
| "state_points_per_second": float(strain.shape[0] * strain.shape[1] / seconds), | |
| "descriptor_hidden_hardening_entries_zero": bool( | |
| torch.count_nonzero(torch.stack([x.descriptor[3:10] for x in selected])) == 0 | |
| ), | |
| "scope": "material-point audit; conditional v2 is not yet an AgentFEM global provider bundle", | |
| } | |
| ARTIFACT_DIR.mkdir(parents=True, exist_ok=True) | |
| (ARTIFACT_DIR / "physical_runtime_validation.json").write_text( | |
| json.dumps(report, indent=2) + "\n", encoding="utf-8" | |
| ) | |
| print(json.dumps(report, indent=2)) | |
| return report | |
| if __name__ == "__main__": | |
| run() | |