Download tests/test_t2_material_loading_memory_v1.py from HaomingLuo/AgentFEM-Material-Loading-Memory: direct link, hf CLI and curl.
- Browser
- Download file 2.88 kB
-
https://huggingface.co/datasets/HaomingLuo/AgentFEM-Material-Loading-Memory/resolve/main/tests/test_t2_material_loading_memory_v1.py
- Command line
-
hf download hf://datasets/HaomingLuo/AgentFEM-Material-Loading-Memory/tests/test_t2_material_loading_memory_v1.py
-
curl -L -o test_t2_material_loading_memory_v1.py https://huggingface.co/datasets/HaomingLuo/AgentFEM-Material-Loading-Memory/resolve/main/tests/test_t2_material_loading_memory_v1.py
2.88 kB
| import json | |
| import numpy as np | |
| from src.load_t2_material_loading_memory import load_trajectory | |
| from src.t2_material_loading_memory import prescribed_history | |
| from src.t2_material_loading_memory_v1 import ( | |
| DATA_DIR, | |
| MATERIAL_MODELS, | |
| PATH_FAMILIES, | |
| case_identity, | |
| design_parameters, | |
| split_assignments, | |
| ) | |
| def test_v1_design_is_unique_balanced_and_stratified(): | |
| rows = design_parameters() | |
| split = split_assignments(rows) | |
| assert len(rows) == 1008 | |
| assert len({case_identity(row) for row in rows}) == 1008 | |
| assert sum(value == "train" for value in split.values()) == 768 | |
| assert sum(value == "validation" for value in split.values()) == 120 | |
| assert sum(value == "test" for value in split.values()) == 120 | |
| for model in MATERIAL_MODELS: | |
| assert sum(row["material_model"] == model for row in rows) == 504 | |
| for family in PATH_FAMILIES: | |
| indices = [ | |
| index | |
| for index, row in enumerate(rows) | |
| if row["material_model"] == model and row["path_family"] == family | |
| ] | |
| assert len(indices) == 84 | |
| assert sum(split[index] == "train" for index in indices) == 64 | |
| assert sum(split[index] == "validation" for index in indices) == 10 | |
| assert sum(split[index] == "test" for index in indices) == 10 | |
| def test_v1_parameter_ranges_and_model_labels_are_explicit(): | |
| rows = design_parameters() | |
| for row in rows: | |
| assert 150.0e9 <= row["young_pa"] <= 230.0e9 | |
| assert 0.25 <= row["poisson"] <= 0.34 | |
| assert 180.0e6 <= row["yield_stress_pa"] <= 450.0e6 | |
| assert 0.003 <= row["maximum_equivalent_strain"] <= 0.012 | |
| if row["material_model"] == "j2_linear_isotropic": | |
| assert row["backstress_c1_pa"] == 0.0 | |
| assert row["isotropic_saturation_pa"] == 0.0 | |
| else: | |
| assert row["hardening_modulus_pa"] == 0.0 | |
| assert row["backstress_c1_pa"] > 0.0 | |
| def test_v1_histories_preserve_reversals_under_refinement(): | |
| for row in design_parameters()[::83]: | |
| _, coarse, anchors = prescribed_history(row, points=121) | |
| _, fine, _ = prescribed_history(row, points=241) | |
| np.testing.assert_allclose(coarse, fine[::2], rtol=0.0, atol=1.0e-15) | |
| for anchor in anchors: | |
| assert np.any(np.isclose(coarse, anchor, rtol=0.0, atol=1.0e-15)) | |
| def test_v1_packaged_data_and_lightweight_reader_when_present(): | |
| manifest_path = DATA_DIR / "manifest.json" | |
| if not manifest_path.exists(): | |
| return | |
| manifest = json.loads(manifest_path.read_text(encoding="utf-8")) | |
| assert manifest["sample_count"] == 1008 | |
| assert len(manifest["shards"]) == 8 | |
| sample = load_trajectory(DATA_DIR, 0) | |
| assert sample["history"]["stress_pa"].shape == (121, 3, 3) | |
| assert np.isfinite(sample["history"]["stress_pa"]).all() | |