Make the material-memory example a lightweight reproducible starter
Browse files- MEMORY_EXAMPLE.md +17 -5
- show_material_memory.py +34 -17
MEMORY_EXAMPLE.md
CHANGED
|
@@ -10,19 +10,30 @@ parameters cannot distinguish them.
|
|
| 10 |
## Run it
|
| 11 |
|
| 12 |
```sh
|
| 13 |
-
pip install numpy
|
| 14 |
python show_material_memory.py
|
| 15 |
```
|
| 16 |
|
| 17 |
-
Download [the script](show_material_memory.py) first. It fetches
|
| 18 |
-
|
| 19 |
containing all 121 states, and a JSON evidence record. The figure displays
|
| 20 |
states 0–60 so the two returns are easy to follow. No solver, GPU, model weights
|
| 21 |
or paid service is required.
|
| 22 |
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
```sh
|
|
|
|
| 26 |
python show_material_memory.py --shard data/t2_material_loading_memory_v1/shards/part-00002.h5
|
| 27 |
```
|
| 28 |
|
|
@@ -51,7 +62,8 @@ or stress of the opposite sign? Then inspect the CSV to trace how it got there.
|
|
| 51 |
不足以确定此刻的应力,还需要加载历史或内部状态。
|
| 52 |
|
| 53 |
这是合成材料点数据中的一个训练样本,不是实测数据,也不是 DENIM 的预测结果。
|
| 54 |
-
运行脚本即可生成图、完整历程表和校验记录。
|
|
|
|
| 55 |
不是实际时间。没有读取封存测试集,也没有修改训练、验证或测试划分。
|
| 56 |
|
| 57 |
[Explore the interactive lab](https://lab.haoming-luo.com/material-memory/) ·
|
|
|
|
| 10 |
## Run it
|
| 11 |
|
| 12 |
```sh
|
| 13 |
+
pip install numpy matplotlib huggingface_hub
|
| 14 |
python show_material_memory.py
|
| 15 |
```
|
| 16 |
|
| 17 |
+
Download [the script](show_material_memory.py) first. It fetches a **4.5 KB training
|
| 18 |
+
excerpt**, checks its SHA-256, and produces a PNG, a CSV
|
| 19 |
containing all 121 states, and a JSON evidence record. The figure displays
|
| 20 |
states 0–60 so the two returns are easy to follow. No solver, GPU, model weights
|
| 21 |
or paid service is required.
|
| 22 |
|
| 23 |
+
The excerpt contains the four unchanged arrays used here, including the complete
|
| 24 |
+
strain tensors. It is a lossless copy from the pinned original shard, not a new
|
| 25 |
+
simulation or an extra dataset sample. Source provenance stays in the output.
|
| 26 |
+
|
| 27 |
+
For offline use, also download [the small excerpt](example/training-history-00252.npz):
|
| 28 |
+
|
| 29 |
+
```sh
|
| 30 |
+
python show_material_memory.py --sample training-history-00252.npz
|
| 31 |
+
```
|
| 32 |
+
|
| 33 |
+
Already have the original data? Install `h5py` to read its HDF5 shard:
|
| 34 |
|
| 35 |
```sh
|
| 36 |
+
pip install h5py
|
| 37 |
python show_material_memory.py --shard data/t2_material_loading_memory_v1/shards/part-00002.h5
|
| 38 |
```
|
| 39 |
|
|
|
|
| 62 |
不足以确定此刻的应力,还需要加载历史或内部状态。
|
| 63 |
|
| 64 |
这是合成材料点数据中的一个训练样本,不是实测数据,也不是 DENIM 的预测结果。
|
| 65 |
+
运行脚本只需下载 4.5 KB 的训练样本摘录,即可生成图、完整历程表和校验记录。
|
| 66 |
+
摘录与原数据逐项一致,不新增样本。图中使用有符号等效应力;加载步
|
| 67 |
不是实际时间。没有读取封存测试集,也没有修改训练、验证或测试划分。
|
| 68 |
|
| 69 |
[Explore the interactive lab](https://lab.haoming-luo.com/material-memory/) ·
|
show_material_memory.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
"""Show two zero-strain states with different stresses in published train data.
|
| 3 |
|
| 4 |
-
Install: pip install numpy
|
| 5 |
Run: python show_material_memory.py
|
| 6 |
Offline: python show_material_memory.py --shard /path/to/part-00002.h5
|
| 7 |
Code: Apache-2.0; source data: CC BY 4.0, Haoming Luo / AgentFEM.
|
|
@@ -12,7 +12,6 @@ import hashlib
|
|
| 12 |
import json
|
| 13 |
from pathlib import Path
|
| 14 |
|
| 15 |
-
import h5py
|
| 16 |
import numpy as np
|
| 17 |
|
| 18 |
REPO = "HaomingLuo/AgentFEM-Material-Loading-Memory"
|
|
@@ -20,20 +19,32 @@ REVISION = "cc9644aa5b51ac4f0ff5cccc9a42452de0d220a3"
|
|
| 20 |
FILE = "data/t2_material_loading_memory_v1/shards/part-00002.h5"
|
| 21 |
SHA256 = "952b90eed1ce3ac288487cf31180384fc12f79aa03d95e4885bfd73b85c9a46d"
|
| 22 |
SAMPLE = "00252" # First training trajectory in the symmetric-cyclic J2 cohort.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
|
| 25 |
-
def read_sample(path):
|
| 26 |
digest = hashlib.sha256(Path(path).read_bytes()).hexdigest()
|
| 27 |
-
if digest != SHA256:
|
| 28 |
-
raise ValueError("
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
if not all(np.isfinite(a).all() for a in arrays.values()):
|
| 38 |
raise ValueError("Non-finite trajectory.")
|
| 39 |
# First two returns to zero after the virgin state, not maximum-gap selection.
|
|
@@ -49,16 +60,22 @@ def read_sample(path):
|
|
| 49 |
|
| 50 |
def main():
|
| 51 |
parser = argparse.ArgumentParser(description=__doc__)
|
| 52 |
-
parser.
|
|
|
|
|
|
|
| 53 |
parser.add_argument("--out", type=Path, default=Path("memory-example"))
|
| 54 |
args = parser.parse_args()
|
| 55 |
-
if args.shard is None:
|
| 56 |
from huggingface_hub import hf_hub_download
|
| 57 |
-
args.
|
| 58 |
-
|
|
|
|
| 59 |
strain = d["signed_equivalent_strain"] * 100
|
| 60 |
stress = d["signed_equivalent_stress_pa"] / 1e6
|
| 61 |
report = {"repository": REPO, "revision": REVISION, "shard_sha256": SHA256,
|
|
|
|
|
|
|
|
|
|
| 62 |
"sample_id": SAMPLE, "case_id": case_id, "split": "train",
|
| 63 |
"selection": "First two noninitial returns to zero strain; no interpolation",
|
| 64 |
"states": [{"index": i, "signed_equivalent_strain": float(strain[i]/100),
|
|
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
"""Show two zero-strain states with different stresses in published train data.
|
| 3 |
|
| 4 |
+
Install: pip install numpy matplotlib huggingface_hub
|
| 5 |
Run: python show_material_memory.py
|
| 6 |
Offline: python show_material_memory.py --shard /path/to/part-00002.h5
|
| 7 |
Code: Apache-2.0; source data: CC BY 4.0, Haoming Luo / AgentFEM.
|
|
|
|
| 12 |
import json
|
| 13 |
from pathlib import Path
|
| 14 |
|
|
|
|
| 15 |
import numpy as np
|
| 16 |
|
| 17 |
REPO = "HaomingLuo/AgentFEM-Material-Loading-Memory"
|
|
|
|
| 19 |
FILE = "data/t2_material_loading_memory_v1/shards/part-00002.h5"
|
| 20 |
SHA256 = "952b90eed1ce3ac288487cf31180384fc12f79aa03d95e4885bfd73b85c9a46d"
|
| 21 |
SAMPLE = "00252" # First training trajectory in the symmetric-cyclic J2 cohort.
|
| 22 |
+
EXCERPT_REVISION = "62cedc709b159c9faa652e0aff34ff48771b3f07"
|
| 23 |
+
EXCERPT_FILE = "example/training-history-00252.npz"
|
| 24 |
+
EXCERPT_SHA256 = "c16bd5da346dd6926d32c730ad9ad040c5bd9a51dccba92b1f8c4ae1dce8717f"
|
| 25 |
+
ARRAY_NAMES = ("total_strain", "signed_equivalent_strain",
|
| 26 |
+
"signed_equivalent_stress_pa", "equivalent_plastic_strain")
|
| 27 |
|
| 28 |
|
| 29 |
+
def read_sample(path, excerpt=False):
|
| 30 |
digest = hashlib.sha256(Path(path).read_bytes()).hexdigest()
|
| 31 |
+
if digest != (EXCERPT_SHA256 if excerpt else SHA256):
|
| 32 |
+
raise ValueError("Input checksum mismatch; use the pinned published file.")
|
| 33 |
+
if excerpt:
|
| 34 |
+
with np.load(path, allow_pickle=False) as packed:
|
| 35 |
+
if (str(packed["split"]) != "train" or str(packed["sample_id"]) != SAMPLE
|
| 36 |
+
or str(packed["source_sha256"]) != SHA256):
|
| 37 |
+
raise ValueError("Unexpected excerpt provenance.")
|
| 38 |
+
arrays = {name: packed[name] for name in ARRAY_NAMES}
|
| 39 |
+
case_id = str(packed["case_id"])
|
| 40 |
+
else:
|
| 41 |
+
import h5py # Only needed when inspecting the complete source shard.
|
| 42 |
+
with h5py.File(path, "r") as f:
|
| 43 |
+
g = f[SAMPLE]
|
| 44 |
+
if str(g.attrs["split"]) != "train":
|
| 45 |
+
raise ValueError("Illustration must use training data only.")
|
| 46 |
+
arrays = {name: g[name][:] for name in ARRAY_NAMES}
|
| 47 |
+
case_id = str(g.attrs["case_id"])
|
| 48 |
if not all(np.isfinite(a).all() for a in arrays.values()):
|
| 49 |
raise ValueError("Non-finite trajectory.")
|
| 50 |
# First two returns to zero after the virgin state, not maximum-gap selection.
|
|
|
|
| 60 |
|
| 61 |
def main():
|
| 62 |
parser = argparse.ArgumentParser(description=__doc__)
|
| 63 |
+
inputs = parser.add_mutually_exclusive_group()
|
| 64 |
+
inputs.add_argument("--shard", type=Path, help="Original HDF5 shard (requires h5py)")
|
| 65 |
+
inputs.add_argument("--sample", type=Path, help="Local 4.5 KB NPZ training excerpt")
|
| 66 |
parser.add_argument("--out", type=Path, default=Path("memory-example"))
|
| 67 |
args = parser.parse_args()
|
| 68 |
+
if args.shard is None and args.sample is None:
|
| 69 |
from huggingface_hub import hf_hub_download
|
| 70 |
+
args.sample = Path(hf_hub_download(REPO, EXCERPT_FILE, repo_type="dataset", revision=EXCERPT_REVISION))
|
| 71 |
+
using_excerpt = args.sample is not None
|
| 72 |
+
d, a, b, case_id = read_sample(args.sample if using_excerpt else args.shard, excerpt=using_excerpt)
|
| 73 |
strain = d["signed_equivalent_strain"] * 100
|
| 74 |
stress = d["signed_equivalent_stress_pa"] / 1e6
|
| 75 |
report = {"repository": REPO, "revision": REVISION, "shard_sha256": SHA256,
|
| 76 |
+
"input_kind": "lossless_training_excerpt" if using_excerpt else "original_shard",
|
| 77 |
+
"input_sha256": EXCERPT_SHA256 if using_excerpt else SHA256,
|
| 78 |
+
"excerpt_revision": EXCERPT_REVISION if using_excerpt else None,
|
| 79 |
"sample_id": SAMPLE, "case_id": case_id, "split": "train",
|
| 80 |
"selection": "First two noninitial returns to zero strain; no interpolation",
|
| 81 |
"states": [{"index": i, "signed_equivalent_strain": float(strain[i]/100),
|