HaomingLuo commited on
Commit
fa4cdcf
·
verified ·
1 Parent(s): a32a979

Add 4080 grouped multi-zone states and independent mesh checks

Browse files
README.md CHANGED
@@ -16,6 +16,16 @@ tags:
16
  - scientific-machine-learning
17
  pretty_name: AgentFEM Programmable Soft Rods
18
  configs:
 
 
 
 
 
 
 
 
 
 
19
  - config_name: equilibria
20
  data_files:
21
  - split: train
@@ -30,6 +40,8 @@ configs:
30
 
31
  # AgentFEM · Programmable Soft Rods
32
 
 
 
33
  **Learn shapes. Distinguish branches. Design actuation.**
34
 
35
  ![Three families of computed flexible-rod shapes](assets/overview.png)
 
16
  - scientific-machine-learning
17
  pretty_name: AgentFEM Programmable Soft Rods
18
  configs:
19
+ - config_name: multizone_v02
20
+ data_files:
21
+ - split: train
22
+ path: multizone-v02/train.jsonl.gz
23
+ - split: validation
24
+ path: multizone-v02/validation.jsonl.gz
25
+ - split: test
26
+ path: multizone-v02/test.jsonl.gz
27
+ - split: zone_ood
28
+ path: multizone-v02/zone_ood.jsonl.gz
29
  - config_name: equilibria
30
  data_files:
31
  - split: train
 
40
 
41
  # AgentFEM · Programmable Soft Rods
42
 
43
+ **New: [multi-zone actuation supplement](multizone-v02/README.md)** — 4,080 additional states; 3/6/12 zones, with 8-zone holdout and mesh checks. The original 16,200-state collection remains available as `equilibria`.
44
+
45
  **Learn shapes. Distinguish branches. Design actuation.**
46
 
47
  ![Three families of computed flexible-rod shapes](assets/overview.png)
multizone-v02/README.md ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Multi-zone actuation · v0.2 supplement
2
+
3
+ 4,080 equilibrium states in 680 independent control scenarios. This supplement adds 3, 6 and 12 actuation regions to one continuous, planar extensible rod. Eight-region scenarios are a held-out zone-count test. It does not represent connected robots, contact or physical-time dynamics.
4
+
5
+ ## Protocol
6
+
7
+ - 200 scenarios each at 3, 6 and 12 zones; 80 additional scenarios at 8 zones.
8
+ - Each scenario has six loading levels t=0,0.2,...,1; all six stay in the same split.
9
+ - Train: 2,520 states; validation: 540; test: 540; zone-count OOD: 480.
10
+ - Curvature controls sampled uniformly in [-2.4,2.4]; chi log-uniform in [1e-4,10^-2.5]. Final fx/chi in [0,0.6], fy/chi in [-0.6,0.6]. Curvature and forces ramp together with t. L=EA=1, zero end moment and zero microforce h.
11
+ - A 48-element angle-FE model generates locally stable equilibrium states. 34 final states are checked against 96 elements. Maximum checked endpoint difference: 4.604e-5 L.
12
+ - Zero-loading states are repeated across scenarios by construction; they are not evidence of generalization. Evaluation reports both all-state and nonzero-loading errors. Grouping prevents a nonzero loading path from crossing splits.
13
+ - Eight-zone OOD is a limited zone-count shift, not arbitrary-geometry or load extrapolation.
14
+
15
+ Each compressed JSONL record contains scene and split IDs, zone count, controls, loading parameter, angle DOFs, a 65-point reference-coordinate centerline, strain, endpoint, residual, local eigenvalue and Newton trace. Rejected samples are retained in rejected.json (none in this release). Full metrics and mesh checks accompany the data.
16
+
17
+ Reproduce with `OPENBLAS_NUM_THREADS=1 python multizone.py` from the original project layout. Source files are supplied in `source/`; they resolve the project root as their parent directory's parent. Dependencies: NumPy, SciPy, PyTorch and safetensors. Generation and training use seed 20261015.
18
+
19
+ ## 中文
20
+
21
+ 新增 680 组驱动工况、4,080 个平衡状态。3、6、12 分区用于训练与同分布测试;8 分区全部留作测试。同一工况的加载状态不跨数据划分。数据描述连续柔性杆的理想化曲率驱动,不是实物机器人实验数据。
22
+
23
+ Data: CC BY 4.0. Source code: Apache-2.0. Original v0.1 files remain unchanged.
multizone-v02/mesh-checks.json ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "id": "z3_000_5",
4
+ "tip_difference_over_L": 4.603976254440725e-05,
5
+ "centerline_rmse_over_L": 6.361763189918143e-05
6
+ },
7
+ {
8
+ "id": "z3_020_5",
9
+ "tip_difference_over_L": 9.028800757149764e-06,
10
+ "centerline_rmse_over_L": 2.7482932927981872e-05
11
+ },
12
+ {
13
+ "id": "z3_040_5",
14
+ "tip_difference_over_L": 2.735908106962287e-05,
15
+ "centerline_rmse_over_L": 4.98418357228845e-05
16
+ },
17
+ {
18
+ "id": "z3_060_5",
19
+ "tip_difference_over_L": 1.6067726115273442e-05,
20
+ "centerline_rmse_over_L": 3.7085958702185335e-05
21
+ },
22
+ {
23
+ "id": "z3_080_5",
24
+ "tip_difference_over_L": 3.0206619534396127e-05,
25
+ "centerline_rmse_over_L": 5.133563955006805e-05
26
+ },
27
+ {
28
+ "id": "z3_100_5",
29
+ "tip_difference_over_L": 2.146966129776038e-05,
30
+ "centerline_rmse_over_L": 3.865407210995892e-05
31
+ },
32
+ {
33
+ "id": "z3_120_5",
34
+ "tip_difference_over_L": 2.2504350087581327e-05,
35
+ "centerline_rmse_over_L": 3.839696637125274e-05
36
+ },
37
+ {
38
+ "id": "z3_140_5",
39
+ "tip_difference_over_L": 2.061080227363198e-05,
40
+ "centerline_rmse_over_L": 3.5543909425014484e-05
41
+ },
42
+ {
43
+ "id": "z3_160_5",
44
+ "tip_difference_over_L": 1.692271647763019e-05,
45
+ "centerline_rmse_over_L": 2.3776689029657916e-05
46
+ },
47
+ {
48
+ "id": "z3_180_5",
49
+ "tip_difference_over_L": 5.545476164713359e-06,
50
+ "centerline_rmse_over_L": 2.0527130425934408e-05
51
+ },
52
+ {
53
+ "id": "z6_000_5",
54
+ "tip_difference_over_L": 2.4046436395802937e-05,
55
+ "centerline_rmse_over_L": 4.627011521342771e-05
56
+ },
57
+ {
58
+ "id": "z6_020_5",
59
+ "tip_difference_over_L": 3.182910759435842e-05,
60
+ "centerline_rmse_over_L": 5.040611871120139e-05
61
+ },
62
+ {
63
+ "id": "z6_040_5",
64
+ "tip_difference_over_L": 3.0365175570780548e-05,
65
+ "centerline_rmse_over_L": 5.245915743265558e-05
66
+ },
67
+ {
68
+ "id": "z6_060_5",
69
+ "tip_difference_over_L": 1.9946935631083388e-05,
70
+ "centerline_rmse_over_L": 2.8849621955517115e-05
71
+ },
72
+ {
73
+ "id": "z6_080_5",
74
+ "tip_difference_over_L": 2.136773352088528e-05,
75
+ "centerline_rmse_over_L": 4.1115534402941165e-05
76
+ },
77
+ {
78
+ "id": "z6_100_5",
79
+ "tip_difference_over_L": 1.207107300827187e-05,
80
+ "centerline_rmse_over_L": 2.9171732842140974e-05
81
+ },
82
+ {
83
+ "id": "z6_120_5",
84
+ "tip_difference_over_L": 2.115380868145924e-05,
85
+ "centerline_rmse_over_L": 4.204016199001519e-05
86
+ },
87
+ {
88
+ "id": "z6_140_5",
89
+ "tip_difference_over_L": 2.1235057070129793e-05,
90
+ "centerline_rmse_over_L": 4.234916959919376e-05
91
+ },
92
+ {
93
+ "id": "z6_160_5",
94
+ "tip_difference_over_L": 3.7047364022135785e-05,
95
+ "centerline_rmse_over_L": 5.7604509364778207e-05
96
+ },
97
+ {
98
+ "id": "z6_180_5",
99
+ "tip_difference_over_L": 3.4749230003974724e-05,
100
+ "centerline_rmse_over_L": 5.713599594208783e-05
101
+ },
102
+ {
103
+ "id": "z12_000_5",
104
+ "tip_difference_over_L": 1.8314703263704387e-05,
105
+ "centerline_rmse_over_L": 3.744023097267619e-05
106
+ },
107
+ {
108
+ "id": "z12_020_5",
109
+ "tip_difference_over_L": 1.8696165026924934e-05,
110
+ "centerline_rmse_over_L": 4.314786135595779e-05
111
+ },
112
+ {
113
+ "id": "z12_040_5",
114
+ "tip_difference_over_L": 3.660754042481668e-05,
115
+ "centerline_rmse_over_L": 5.734715362801281e-05
116
+ },
117
+ {
118
+ "id": "z12_060_5",
119
+ "tip_difference_over_L": 2.772976736349974e-05,
120
+ "centerline_rmse_over_L": 4.799696174019728e-05
121
+ },
122
+ {
123
+ "id": "z12_080_5",
124
+ "tip_difference_over_L": 2.6830417405048573e-05,
125
+ "centerline_rmse_over_L": 4.9781697237358266e-05
126
+ },
127
+ {
128
+ "id": "z12_100_5",
129
+ "tip_difference_over_L": 2.5053092492319243e-05,
130
+ "centerline_rmse_over_L": 4.6486272645130724e-05
131
+ },
132
+ {
133
+ "id": "z12_120_5",
134
+ "tip_difference_over_L": 2.880915971215596e-05,
135
+ "centerline_rmse_over_L": 4.896360116246912e-05
136
+ },
137
+ {
138
+ "id": "z12_140_5",
139
+ "tip_difference_over_L": 2.791571360083178e-05,
140
+ "centerline_rmse_over_L": 4.713340498375442e-05
141
+ },
142
+ {
143
+ "id": "z12_160_5",
144
+ "tip_difference_over_L": 2.7966535682978217e-05,
145
+ "centerline_rmse_over_L": 4.9353373253418014e-05
146
+ },
147
+ {
148
+ "id": "z12_180_5",
149
+ "tip_difference_over_L": 1.79296883293744e-05,
150
+ "centerline_rmse_over_L": 3.8050289749949345e-05
151
+ },
152
+ {
153
+ "id": "z8_000_5",
154
+ "tip_difference_over_L": 2.391581307196624e-05,
155
+ "centerline_rmse_over_L": 4.4834920749881116e-05
156
+ },
157
+ {
158
+ "id": "z8_020_5",
159
+ "tip_difference_over_L": 3.0930859539508996e-05,
160
+ "centerline_rmse_over_L": 5.10187863809428e-05
161
+ },
162
+ {
163
+ "id": "z8_040_5",
164
+ "tip_difference_over_L": 1.9119874215879227e-05,
165
+ "centerline_rmse_over_L": 3.49128210367896e-05
166
+ },
167
+ {
168
+ "id": "z8_060_5",
169
+ "tip_difference_over_L": 4.0496683844125254e-05,
170
+ "centerline_rmse_over_L": 6.214737261975e-05
171
+ }
172
+ ]
multizone-v02/rejected.json ADDED
@@ -0,0 +1 @@
 
 
1
+ []
multizone-v02/source/multizone.py ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Reproducible v0.2 multi-zone supplement; preserves v0.1 artifacts."""
2
+ import os
3
+ os.environ.setdefault('OPENBLAS_NUM_THREADS','1')
4
+ os.environ.setdefault('OMP_NUM_THREADS','1')
5
+ from pathlib import Path
6
+ import json,gzip,time
7
+ import numpy as np
8
+ import torch
9
+ from torch import nn
10
+ from safetensors.torch import save_file,load_file
11
+ from rod import Rod,Controls,serial
12
+
13
+ ROOT=Path(__file__).resolve().parents[1]
14
+ OUT=ROOT/'release/dataset/multizone-v02'
15
+ MODEL=ROOT/'release/model/multizone-v02'
16
+ def features(ks,chi,fx,fy):
17
+ field=np.asarray(ks)[np.floor((np.arange(48)+.5)*len(ks)/48).astype(int)]
18
+ return np.r_[field,fx/chi,fy/chi,np.log10(chi)],np.cumsum(field)/48
19
+ def network():
20
+ return nn.Sequential(nn.Linear(51,96),nn.Tanh(),nn.Linear(96,96),nn.Tanh(),nn.Linear(96,48))
21
+ def xy(z,fx,fy):
22
+ angle=(np.c_[np.zeros(len(z)),z[:,:-1]]+z)/2
23
+ stretch=1+fx[:,None]*np.cos(angle)+fy[:,None]*np.sin(angle)
24
+ ds=stretch[:,:,None]*np.stack([np.cos(angle),np.sin(angle)],axis=2)/48
25
+ return np.concatenate([np.zeros((len(z),1,2)),np.cumsum(ds,axis=1)],axis=1)
26
+ def main():
27
+ start=time.time();OUT.mkdir(parents=True,exist_ok=True);MODEL.mkdir(parents=True,exist_ok=True)
28
+ rng=np.random.default_rng(20261015);rod=Rod(48);fine=Rod(96);rows=[];mesh=[];rejected=[]
29
+ for m in [3,6,12,8]:
30
+ total=200 if m!=8 else 80
31
+ order=rng.permutation(total);splits={int(j):('train' if i<140 else 'validation' if i<170 else 'test') for i,j in enumerate(order)}
32
+ for j in range(total):
33
+ split=splits[j] if m!=8 else 'zone_ood';ks=rng.uniform(-2.4,2.4,m);chi=float(10**rng.uniform(-4,-2.5));fx=float(chi*rng.uniform(0,.6));fy=float(chi*rng.uniform(-.6,.6))
34
+ for step,t in enumerate(np.linspace(0,1,6)):
35
+ k=ks*t;c=Controls(chi=chi,fx=fx*t,fy=fy*t,curvatures=tuple(k));_,seed=features(k,chi,c.fx,c.fy);s=rod.solve(c,seed)
36
+ row=dict(id=f'z{m}_{j:03d}_{step}',scene_id=f'z{m}_{j:03d}',split=split,zones=m,t=float(t),chi=chi,fx=c.fx,fy=c.fy,curvatures=k.tolist(),**serial(s))
37
+ if not s['accepted'] or s['stability']!='stable':rejected.append(row);continue
38
+ rows.append(row)
39
+ if step==5 and j%20==0:
40
+ field=k[np.floor((np.arange(96)+.5)*m/96).astype(int)];f=fine.solve(c,np.cumsum(field)/96)
41
+ assert f['accepted'] and f['stability']=='stable'
42
+ mesh.append(dict(id=row['id'],tip_difference_over_L=float(np.linalg.norm(f['tip']-s['tip'])),centerline_rmse_over_L=float(np.sqrt(np.mean(np.sum((f['centerline']-s['centerline'])**2,axis=1))))))
43
+ print('Generated zones',m,'states',len(rows),flush=True)
44
+ for split in ['train','validation','test','zone_ood']:
45
+ with gzip.open(OUT/f'{split}.jsonl.gz','wt') as f:
46
+ for row in rows:
47
+ if row['split']==split:f.write(json.dumps(row)+'\n')
48
+ (OUT/'rejected.json').write_text(json.dumps(rejected))
49
+ (OUT/'mesh-checks.json').write_text(json.dumps(mesh,indent=2))
50
+ items=[features(r['curvatures'],r['chi'],r['fx'],r['fy']) for r in rows]
51
+ x=np.array([a for a,b in items],np.float32);seed=np.array([b for a,b in items],np.float32);z=np.array([r['z'] for r in rows],np.float32)
52
+ ix={s:np.array([i for i,r in enumerate(rows) if r['split']==s]) for s in ['train','validation','test','zone_ood']}
53
+ mean=x[ix['train']].mean(0);std=x[ix['train']].std(0);std[std<1e-6]=1
54
+ X=torch.from_numpy((x-mean)/std);Y=torch.from_numpy((z-seed)/.1)
55
+ torch.set_num_threads(2);torch.manual_seed(15);net=network();opt=torch.optim.Adam(net.parameters(),lr=.0015);best=float('inf');best_epoch=0
56
+ for epoch in range(201):
57
+ net.train()
58
+ for batch in np.array_split(rng.permutation(ix['train']),12):
59
+ opt.zero_grad();loss=(net(X[batch])-Y[batch]).square().mean();loss.backward();opt.step()
60
+ net.eval()
61
+ with torch.no_grad():val=float((net(X[ix['validation']])-Y[ix['validation']]).square().mean())
62
+ if val<best:best=val;best_epoch=epoch;weights={k:v.clone().contiguous() for k,v in net.state_dict().items()}
63
+ if epoch%50==0:print('Epoch',epoch,'validation',val,flush=True)
64
+ save_file(weights,str(MODEL/'residual.safetensors'));net.load_state_dict(load_file(str(MODEL/'residual.safetensors')))
65
+ with torch.no_grad():pred=seed+.1*net(X).numpy()
66
+ fx=np.array([r['fx'] for r in rows]);fy=np.array([r['fy'] for r in rows]);truth=xy(z,fx,fy)
67
+ metrics={}
68
+ for split,idx in ix.items():
69
+ metrics[split]={}
70
+ for name,zz in [('intrinsic_shape',seed),('learned_residual',pred)]:
71
+ err=np.linalg.norm(xy(zz,fx,fy)[idx]-truth[idx],axis=2)
72
+ metrics[split][name]={'centerline_rmse_over_L':float(np.sqrt(np.mean(err**2))),'tip_mean_over_L':float(err[:,-1].mean()),'tip_p95_over_L':float(np.quantile(err[:,-1],.95))}
73
+ nonzero=np.array([rows[i]['t']>0 for i in idx]);metrics[split][name]['nonzero_loading_rmse_over_L']=float(np.sqrt(np.mean(err[nonzero]**2)))
74
+ correction=[]
75
+ for i in ix['test'][5::36]:
76
+ r=rows[i];c=Controls(chi=r['chi'],fx=r['fx'],fy=r['fy'],curvatures=tuple(r['curvatures']))
77
+ corrected=rod.solve(c,pred[i]);assert corrected['accepted']
78
+ correction.append(dict(id=r['id'],residual=corrected['residual'],tip_error_over_L=float(np.linalg.norm(corrected['tip']-r['tip']))))
79
+ report=dict(version='0.2',states=len(rows),scenes=len(set(r['scene_id'] for r in rows)),counts={s:len(i) for s,i in ix.items()},zones_id=[3,6,12],zones_ood=[8],rejected=len(rejected),mesh_checks=len(mesh),max_mesh_tip_difference_over_L=max(r['tip_difference_over_L'] for r in mesh),best_epoch=best_epoch,metrics=metrics,seconds=time.time()-start)
80
+ report['mechanics_correction_checks']=correction
81
+ (MODEL/'config.json').write_text(json.dumps(dict(mean=mean.tolist(),std=std.tolist(),output_scale=.1,n=48,architecture=[51,96,96,48],features='48 piecewise intrinsic curvatures, fx/chi, fy/chi, log10(chi)',prediction='cumulative intrinsic angle + output_scale * network(standardized features)'),indent=2))
82
+ for p in [MODEL/'evaluation.json',OUT/'validation.json',ROOT/'reports/multizone-v02.json']:p.write_text(json.dumps(report,indent=2))
83
+ print(json.dumps(report,indent=2),flush=True)
84
+ if __name__=='__main__':main()
multizone-v02/source/rod.py ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Conservative planar extensible rod. L=EA=1; chi=EI/(EA L^2).
2
+
3
+ Rod: linear angle FE, midpoint axial elimination. Chain: Ye et al. (2026)
4
+ cell rotations, first cell clamped; kr=chi*n. Independent implementations
5
+ share ONLY the reduced local energy density. No contact or dynamics.
6
+ SPDX-License-Identifier: Apache-2.0
7
+ """
8
+ from dataclasses import dataclass, asdict
9
+ import numpy as np
10
+ from scipy.linalg import solve, eigh
11
+ from scipy.optimize import root
12
+
13
+ @dataclass
14
+ class Controls:
15
+ chi: float = .001
16
+ fx: float = 0.
17
+ fy: float = 0.
18
+ moment: float = 0.
19
+ h: float = 0.
20
+ delta: float = .1
21
+ k1: float = 0.
22
+ k2: float = 0.
23
+ k3: float = 0.
24
+ curvatures: tuple | None = None
25
+
26
+ class Rod:
27
+ def __init__(self, n=48, kind="rod"):
28
+ self.n, self.kind, self.ds = n, kind, 1/n
29
+ if kind == "rod":
30
+ self.d = n
31
+ A = np.zeros((n,n+1)); B = A.copy()
32
+ for i in range(n):
33
+ A[i,i:i+2] = .5
34
+ B[i,i:i+2] = [-n,n]
35
+ self.A,self.B = A[:,1:],B[:,1:]
36
+ self.mass = (A[:,1:].T@A[:,1:])/n
37
+ elif kind == "chain":
38
+ self.d = n-1
39
+ self.A = np.eye(n)[:,1:]
40
+ self.B = np.diff(np.eye(n),axis=0)[:,1:]*n
41
+ self.mass = np.eye(n-1)/n
42
+ else: raise ValueError(kind)
43
+ self.s = (np.arange(n)+.5)/n
44
+
45
+ def terms(self, z, c):
46
+ angle=self.A@z
47
+ ks=np.asarray(c.curvatures if c.curvatures is not None else [c.k1,c.k2,c.k3])
48
+ intrinsic=ks[np.minimum((np.arange(self.B.shape[0])+.5)*len(ks)/self.B.shape[0],len(ks)-1).astype(int)]
49
+ curvature=self.B@z-intrinsic
50
+ a=c.fx+2*c.h
51
+ f=a*np.cos(angle)+c.fy*np.sin(angle)
52
+ fp=-a*np.sin(angle)+c.fy*np.cos(angle)
53
+ g=4*c.h*c.delta
54
+ density=-f-.5*f*f+g*np.cos(angle)
55
+ energy=self.ds*(.5*c.chi*(curvature@curvature)+density.sum())-c.moment*z[-1]
56
+ local_g=-(1+f)*fp-g*np.sin(angle)
57
+ local_h=(1+f)*f-fp*fp-g*np.cos(angle)
58
+ grad=self.ds*(c.chi*self.B.T@curvature+self.A.T@local_g)
59
+ grad[-1]-=c.moment
60
+ tangent=self.ds*(c.chi*self.B.T@self.B+self.A.T@(local_h[:,None]*self.A))
61
+ return energy,grad,tangent
62
+
63
+ def solve(self,c,seed=None):
64
+ z=np.zeros(self.d) if seed is None else np.array(seed,dtype=float).copy()
65
+ it=0; trace=[]; fallback_nfev=0
66
+ for it in range(60):
67
+ _,r,K=self.terms(z,c)
68
+ trace.append(dict(iteration=it,residual_inf=float(np.max(np.abs(r)))))
69
+ if np.max(np.abs(r))<1e-10: break
70
+ try: dz=solve(K,-r,assume_a='sym')
71
+ except Exception: break
72
+ old=np.linalg.norm(r)
73
+ step=1.
74
+ for _ in range(16):
75
+ trial=z+step*dz
76
+ if np.linalg.norm(self.terms(trial,c)[1])<old: break
77
+ step*=.5
78
+ else: break
79
+ z=trial
80
+ trace[-1]['accepted_step_scale']=step
81
+ residual=float(np.max(np.abs(self.terms(z,c)[1])))
82
+ if residual>1e-9:
83
+ sol=root(lambda v:self.terms(v,c)[1],z,jac=lambda v:self.terms(v,c)[2],tol=1e-10)
84
+ z=sol.x; fallback_nfev=sol.nfev
85
+ energy,r,K=self.terms(z,c)
86
+ residual=float(np.max(np.abs(r)))
87
+ angle=self.A@z
88
+ stretch=1+(c.fx+2*c.h)*np.cos(angle)+c.fy*np.sin(angle)
89
+ admissible=bool(np.min(stretch)>(2*c.delta if c.h!=0 else 0))
90
+ good=bool(residual<1e-9 and admissible and np.all(np.isfinite(z)))
91
+ eig=float(eigh(K,self.mass,subset_by_index=[0,0],eigvals_only=True)[0]/c.chi) if good else None
92
+ stability='unknown' if eig is None else ('stable' if eig>1e-4 else 'unstable' if eig< -1e-4 else 'critical')
93
+ segments=self.ds*stretch[:,None]*np.column_stack([np.cos(angle),np.sin(angle)])
94
+ xy=np.vstack([np.zeros(2),np.cumsum(segments,axis=0)])
95
+ # Output resampled on reference coordinate, not current arc length.
96
+ center=np.column_stack([np.interp(np.linspace(0,1,65),np.linspace(0,1,self.n+1),xy[:,j]) for j in range(2)])
97
+ return dict(z=z,centerline=center,angle=angle,strain=stretch-1,energy=float(energy),residual=residual,
98
+ iterations=it+1,accepted=good,lambda_min_over_chi=eig,stability=stability,
99
+ tip=center[-1],min_stretch=float(stretch.min()),solver_trace=trace,fallback_nfev=fallback_nfev)
100
+
101
+ def mode_seed(self,amplitude):
102
+ s=np.arange(1,self.d+1)/self.n
103
+ return amplitude*np.sin(np.pi*s/2)
104
+
105
+ def serial(result):
106
+ return {k:(v.tolist() if isinstance(v,np.ndarray) else v) for k,v in result.items()}
multizone-v02/test.jsonl.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:20c12879c220c45fce0b36c1ada62ba22caf204dff634f087d67eabe8ec5357c
3
+ size 1289276
multizone-v02/train.jsonl.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:42b9b863586e2606b378ad0de245650d6dd1cc11b5a600ef2ec355a33c865e3e
3
+ size 6023427
multizone-v02/validation.json ADDED
@@ -0,0 +1,159 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "version": "0.2",
3
+ "states": 4080,
4
+ "scenes": 680,
5
+ "counts": {
6
+ "train": 2520,
7
+ "validation": 540,
8
+ "test": 540,
9
+ "zone_ood": 480
10
+ },
11
+ "zones_id": [
12
+ 3,
13
+ 6,
14
+ 12
15
+ ],
16
+ "zones_ood": [
17
+ 8
18
+ ],
19
+ "rejected": 0,
20
+ "mesh_checks": 34,
21
+ "max_mesh_tip_difference_over_L": 4.603976254440725e-05,
22
+ "best_epoch": 189,
23
+ "metrics": {
24
+ "train": {
25
+ "intrinsic_shape": {
26
+ "centerline_rmse_over_L": 0.03217696650573636,
27
+ "tip_mean_over_L": 0.04703082547593874,
28
+ "tip_p95_over_L": 0.1389949922209111,
29
+ "nonzero_loading_rmse_over_L": 0.035248100774559976
30
+ },
31
+ "learned_residual": {
32
+ "centerline_rmse_over_L": 0.0007707721406115093,
33
+ "tip_mean_over_L": 0.0010672698493170232,
34
+ "tip_p95_over_L": 0.0032114897744955654,
35
+ "nonzero_loading_rmse_over_L": 0.0008432933805167641
36
+ }
37
+ },
38
+ "validation": {
39
+ "intrinsic_shape": {
40
+ "centerline_rmse_over_L": 0.030841632665898296,
41
+ "tip_mean_over_L": 0.04443062956595426,
42
+ "tip_p95_over_L": 0.13412200027231663,
43
+ "nonzero_loading_rmse_over_L": 0.03378531584280138
44
+ },
45
+ "learned_residual": {
46
+ "centerline_rmse_over_L": 0.002139143213742544,
47
+ "tip_mean_over_L": 0.0023906575722607896,
48
+ "tip_p95_over_L": 0.00985920275845111,
49
+ "nonzero_loading_rmse_over_L": 0.002342985905624226
50
+ }
51
+ },
52
+ "test": {
53
+ "intrinsic_shape": {
54
+ "centerline_rmse_over_L": 0.03449966638469762,
55
+ "tip_mean_over_L": 0.04949992729501256,
56
+ "tip_p95_over_L": 0.15202171303892403,
57
+ "nonzero_loading_rmse_over_L": 0.037792491010603176
58
+ },
59
+ "learned_residual": {
60
+ "centerline_rmse_over_L": 0.0022550218060435672,
61
+ "tip_mean_over_L": 0.0025461652398190942,
62
+ "tip_p95_over_L": 0.010101520708292833,
63
+ "nonzero_loading_rmse_over_L": 0.002469874665768664
64
+ }
65
+ },
66
+ "zone_ood": {
67
+ "intrinsic_shape": {
68
+ "centerline_rmse_over_L": 0.03387460541227201,
69
+ "tip_mean_over_L": 0.05124979340575448,
70
+ "tip_p95_over_L": 0.1401572788163453,
71
+ "nonzero_loading_rmse_over_L": 0.03710777102177594
72
+ },
73
+ "learned_residual": {
74
+ "centerline_rmse_over_L": 0.009062882912828973,
75
+ "tip_mean_over_L": 0.012180452320820882,
76
+ "tip_p95_over_L": 0.040638126307767204,
77
+ "nonzero_loading_rmse_over_L": 0.009927801522037316
78
+ }
79
+ }
80
+ },
81
+ "seconds": 4.511781215667725,
82
+ "mechanics_correction_checks": [
83
+ {
84
+ "id": "z3_008_5",
85
+ "residual": 5.312265384527226e-15,
86
+ "tip_error_over_L": 2.5286101803848858e-11
87
+ },
88
+ {
89
+ "id": "z3_051_5",
90
+ "residual": 4.446925569975155e-11,
91
+ "tip_error_over_L": 2.999757286531255e-08
92
+ },
93
+ {
94
+ "id": "z3_097_5",
95
+ "residual": 7.789608621038927e-16,
96
+ "tip_error_over_L": 4.949868572479711e-13
97
+ },
98
+ {
99
+ "id": "z3_144_5",
100
+ "residual": 1.3740308793209865e-11,
101
+ "tip_error_over_L": 2.148295597082969e-08
102
+ },
103
+ {
104
+ "id": "z3_176_5",
105
+ "residual": 5.722921340540243e-12,
106
+ "tip_error_over_L": 2.746265069278408e-07
107
+ },
108
+ {
109
+ "id": "z6_014_5",
110
+ "residual": 6.901285641049137e-17,
111
+ "tip_error_over_L": 7.371685286925458e-13
112
+ },
113
+ {
114
+ "id": "z6_044_5",
115
+ "residual": 2.206625380615194e-11,
116
+ "tip_error_over_L": 1.0975236022566359e-06
117
+ },
118
+ {
119
+ "id": "z6_077_5",
120
+ "residual": 1.4517147984741103e-11,
121
+ "tip_error_over_L": 8.451519429810074e-07
122
+ },
123
+ {
124
+ "id": "z6_138_5",
125
+ "residual": 4.744584467966025e-17,
126
+ "tip_error_over_L": 3.519878195556559e-08
127
+ },
128
+ {
129
+ "id": "z6_156_5",
130
+ "residual": 3.385439432791542e-11,
131
+ "tip_error_over_L": 1.3208994208734372e-07
132
+ },
133
+ {
134
+ "id": "z12_002_5",
135
+ "residual": 4.696980651641702e-15,
136
+ "tip_error_over_L": 5.641037807459418e-07
137
+ },
138
+ {
139
+ "id": "z12_037_5",
140
+ "residual": 2.122790464208461e-12,
141
+ "tip_error_over_L": 1.8782719327230075e-09
142
+ },
143
+ {
144
+ "id": "z12_083_5",
145
+ "residual": 6.979108458062555e-11,
146
+ "tip_error_over_L": 4.442049511326813e-06
147
+ },
148
+ {
149
+ "id": "z12_111_5",
150
+ "residual": 7.040594326440894e-17,
151
+ "tip_error_over_L": 5.582728434790076e-10
152
+ },
153
+ {
154
+ "id": "z12_172_5",
155
+ "residual": 2.369698582393759e-12,
156
+ "tip_error_over_L": 2.2341706552832602e-07
157
+ }
158
+ ]
159
+ }
multizone-v02/validation.jsonl.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:768634891c2ccad7bb0ee91d483da0dd1940a6cb91b19906e9289f92b9574f20
3
+ size 1291826
multizone-v02/zone_ood.jsonl.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d94584b2bf4f8e42df3a95de4bb47ac4edffd00297b09f25feedf3c74ec689d6
3
+ size 1151389