nablaengine 1.0.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. nablaengine/__init__.py +4 -0
  2. nablaengine/_fixtures/README.md +19 -0
  3. nablaengine/_fixtures/data/mf_s0.npz +0 -0
  4. nablaengine/_fixtures/mjlab/LICENSE +27 -0
  5. nablaengine/_fixtures/mjlab/README.md +113 -0
  6. nablaengine/_fixtures/mjlab/g1_meta.json +32 -0
  7. nablaengine/_fixtures/mjlab/g1_train.mjb +0 -0
  8. nablaengine/_optional.py +30 -0
  9. nablaengine/_paths.py +38 -0
  10. nablaengine/actuators/__init__.py +169 -0
  11. nablaengine/actuators/bam.py +306 -0
  12. nablaengine/actuators/bam_params/LICENSE +202 -0
  13. nablaengine/actuators/bam_params/xl330/m6.json +19 -0
  14. nablaengine/boxbox.py +259 -0
  15. nablaengine/ccd.py +1122 -0
  16. nablaengine/checks.py +376 -0
  17. nablaengine/cuda.py +483 -0
  18. nablaengine/dist_query.py +628 -0
  19. nablaengine/dual.py +223 -0
  20. nablaengine/dyn_query.py +685 -0
  21. nablaengine/engines.py +114 -0
  22. nablaengine/envs/__init__.py +24 -0
  23. nablaengine/envs/brax.py +165 -0
  24. nablaengine/envs/convert.py +771 -0
  25. nablaengine/envs/dmc.py +523 -0
  26. nablaengine/envs/env.py +233 -0
  27. nablaengine/envs/kin.py +371 -0
  28. nablaengine/envs/ops.py +134 -0
  29. nablaengine/envs/rewards.py +57 -0
  30. nablaengine/fixtures.py +243 -0
  31. nablaengine/forest_engine/__init__.py +0 -0
  32. nablaengine/forest_engine/adjoint.py +1726 -0
  33. nablaengine/forest_engine/adjoint_contact.py +493 -0
  34. nablaengine/forest_engine/bam_hooks.py +248 -0
  35. nablaengine/forest_engine/body_params.py +1007 -0
  36. nablaengine/forest_engine/capacity_diag.py +116 -0
  37. nablaengine/forest_engine/ccd_coop.py +250 -0
  38. nablaengine/forest_engine/chol_blk.py +80 -0
  39. nablaengine/forest_engine/contact_forces.py +142 -0
  40. nablaengine/forest_engine/contact_vjp.py +462 -0
  41. nablaengine/forest_engine/convex.py +1331 -0
  42. nablaengine/forest_engine/cylinder.py +73 -0
  43. nablaengine/forest_engine/dist_device.py +923 -0
  44. nablaengine/forest_engine/dyn_device.py +696 -0
  45. nablaengine/forest_engine/ellipsoid.py +179 -0
  46. nablaengine/forest_engine/elliptic.py +272 -0
  47. nablaengine/forest_engine/equality.py +842 -0
  48. nablaengine/forest_engine/floss.py +148 -0
  49. nablaengine/forest_engine/foot_offset.py +368 -0
  50. nablaengine/forest_engine/free_gyro.py +288 -0
  51. nablaengine/forest_engine/host.py +530 -0
  52. nablaengine/forest_engine/kdof64.py +127 -0
  53. nablaengine/forest_engine/kinematics.py +320 -0
  54. nablaengine/forest_engine/margin.py +167 -0
  55. nablaengine/forest_engine/margin_convex.py +326 -0
  56. nablaengine/forest_engine/midphase.py +439 -0
  57. nablaengine/forest_engine/model_hooks.py +913 -0
  58. nablaengine/forest_engine/motor_hooks.py +50 -0
  59. nablaengine/forest_engine/muscle.py +485 -0
  60. nablaengine/forest_engine/nb128.py +118 -0
  61. nablaengine/forest_engine/nb64.py +163 -0
  62. nablaengine/forest_engine/noslip.py +1124 -0
  63. nablaengine/forest_engine/nv128.py +1944 -0
  64. nablaengine/forest_engine/object_size.py +283 -0
  65. nablaengine/forest_engine/replay_guard.py +40 -0
  66. nablaengine/forest_engine/root_spread.py +126 -0
  67. nablaengine/forest_engine/solref.py +74 -0
  68. nablaengine/forest_engine/source.py +1464 -0
  69. nablaengine/forest_engine/sparse_pattern.py +527 -0
  70. nablaengine/forest_engine/spatial.py +1045 -0
  71. nablaengine/forest_engine/step.py +3083 -0
  72. nablaengine/forest_engine/surrogate.py +498 -0
  73. nablaengine/forest_engine/tape.py +199 -0
  74. nablaengine/forest_engine/tendon.py +845 -0
  75. nablaengine/forest_engine/terrain.py +1059 -0
  76. nablaengine/forest_engine/world_forces.py +166 -0
  77. nablaengine/forest_engine/world_params.py +230 -0
  78. nablaengine/g1_engine/__init__.py +0 -0
  79. nablaengine/g1_engine/adjoint.py +1661 -0
  80. nablaengine/g1_engine/adjoint_contact.py +577 -0
  81. nablaengine/g1_engine/bam_hooks.py +596 -0
  82. nablaengine/g1_engine/condim4.py +245 -0
  83. nablaengine/g1_engine/contact_forces.py +500 -0
  84. nablaengine/g1_engine/cylccd.py +1158 -0
  85. nablaengine/g1_engine/cylinder.py +216 -0
  86. nablaengine/g1_engine/elliptic.py +565 -0
  87. nablaengine/g1_engine/exact_replay.py +61 -0
  88. nablaengine/g1_engine/host.py +358 -0
  89. nablaengine/g1_engine/kinematics.py +320 -0
  90. nablaengine/g1_engine/mesh.py +305 -0
  91. nablaengine/g1_engine/mesh_tables.py +79 -0
  92. nablaengine/g1_engine/model_hooks.py +919 -0
  93. nablaengine/g1_engine/motor_hooks.py +70 -0
  94. nablaengine/g1_engine/replay_guard.py +55 -0
  95. nablaengine/g1_engine/source.py +1107 -0
  96. nablaengine/g1_engine/sphbox.py +93 -0
  97. nablaengine/g1_engine/step.py +3716 -0
  98. nablaengine/g1_engine/tape.py +173 -0
  99. nablaengine/g1_engine/world_params.py +447 -0
  100. nablaengine/identity.py +401 -0
  101. nablaengine/jax_ffi.py +2536 -0
  102. nablaengine/model/__init__.py +1 -0
  103. nablaengine/model/capability.py +694 -0
  104. nablaengine/model/fields.py +317 -0
  105. nablaengine/model/gravcomp.py +64 -0
  106. nablaengine/model/invweight.py +145 -0
  107. nablaengine/motor.py +143 -0
  108. nablaengine/object_geometry.py +609 -0
  109. nablaengine/params.py +258 -0
  110. nablaengine/provenance.py +196 -0
  111. nablaengine/reference/__init__.py +0 -0
  112. nablaengine/reference/adjoint_groups.py +226 -0
  113. nablaengine/reference/jax64.py +690 -0
  114. nablaengine/reference/warp_physics.py +262 -0
  115. nablaengine/sensors/__init__.py +4 -0
  116. nablaengine/sensors/cameras.py +285 -0
  117. nablaengine/sensors/data/LIVOX_MID360_LICENSE +21 -0
  118. nablaengine/sensors/data/livox_mid360.npz +0 -0
  119. nablaengine/sensors/g1.py +521 -0
  120. nablaengine/sensors/jax_rays.py +364 -0
  121. nablaengine/sensors/optix_rays.py +725 -0
  122. nablaengine/sensors/raycore.py +630 -0
  123. nablaengine/sensors/raygrad.py +374 -0
  124. nablaengine/sensors/raygrad_cuda.py +191 -0
  125. nablaengine/sensors/robot_mesh.py +273 -0
  126. nablaengine/sensors/torch_rays.py +275 -0
  127. nablaengine/terrain.py +424 -0
  128. nablaengine/torch_ffi.py +1328 -0
  129. nablaengine/workdir.py +37 -0
  130. nablaengine-1.0.2.dist-info/METADATA +236 -0
  131. nablaengine-1.0.2.dist-info/RECORD +136 -0
  132. nablaengine-1.0.2.dist-info/WHEEL +5 -0
  133. nablaengine-1.0.2.dist-info/licenses/LICENSE +202 -0
  134. nablaengine-1.0.2.dist-info/licenses/NOTICE +23 -0
  135. nablaengine-1.0.2.dist-info/licenses/THIRD_PARTY_NOTICES.md +176 -0
  136. nablaengine-1.0.2.dist-info/top_level.txt +1 -0
@@ -0,0 +1,226 @@
1
+ """State groups of the adjoint checks, labelled from MuJoCo Warp's own forward, and per-group statistics."""
2
+
3
+ import mujoco
4
+ import numpy as np
5
+
6
+ GROUPS = ("all", "G0_normal", "G1_axis_lt_5mm", "G1_axis_lt_1mm", "G2_contact_flip", "G3_kink", "G4_clamped",
7
+ "G4_near_clamp", "G5_limits", "G6_self_contact", "G7_basis_switch", "G8_near_parallel", "G9_nonconv")
8
+ OUTSIDE_G0 = ("G1_axis_lt_5mm", "G2_contact_flip", "G3_kink", "G7_basis_switch", "G9_nonconv")
9
+ SUBGROUPS = ("G4_clamped&G0", "G5_limits&G0", "G6_self_contact&G0", "G0_normal&~G4_clamped")
10
+ PLANE, SPHERE, CAPSULE = 0, 2, 3
11
+ LIMIT_JOINT = 3
12
+
13
+
14
+ def pair_table(mjm):
15
+ """{frozenset(geom1, geom2): pair index} of the model's explicit pairs."""
16
+ return {frozenset((int(mjm.pair_geom1[i]), int(mjm.pair_geom2[i]))): i for i in range(mjm.npair)}
17
+
18
+
19
+ def capsule_segments(p1, a1, hl1, p2, a2, hl2):
20
+ """Segment parameters (x1, x2) of the capsule-capsule closest points (step.py's clamp cascade, float64), det, and
21
+ the four candidates of the parallel branch."""
22
+ s1, s2 = a1 * hl1, a2 * hl2
23
+ dif = p1 - p2
24
+ ma, mb, mc, u, v = s1 @ s1, -(s1 @ s2), s2 @ s2, -(s1 @ dif), s2 @ dif
25
+ det = ma * mc - mb * mb
26
+ cand = [(1.0, np.clip((v - mb) / mc, -1, 1)), (-1.0, np.clip((v + mb) / mc, -1, 1)),
27
+ (np.clip((u - mb) / ma, -1, 1), 1.0), (np.clip((u + mb) / ma, -1, 1), -1.0)]
28
+ if abs(det) < 1e-15:
29
+ return None, None, det, cand
30
+ x1, x2 = (mc * u - mb * v) / det, (ma * v - mb * u) / det
31
+ if x1 > 1:
32
+ x1, x2 = 1.0, (v - mb) / mc
33
+ elif x1 < -1:
34
+ x1, x2 = -1.0, (v + mb) / mc
35
+ if x2 > 1:
36
+ x2, x1 = 1.0, float(np.clip((u - mb) / ma, -1, 1))
37
+ elif x2 < -1:
38
+ x2, x1 = -1.0, float(np.clip((u + mb) / ma, -1, 1))
39
+ return x1, x2, det, cand
40
+
41
+
42
+ def mjw_substep(mjm, d_in, d_out, pairs=None):
43
+ """One substep of MuJoCo Warp as numpy (see the module docstring). Returns dict with per-world lists `contacts`
44
+ (dicts: cid, pair, slot, geom (model ids, MuJoCo Warp's order), dist, pos, frame (3x3), dim, rows (efc rows),
45
+ nu (sphere / capsule self contacts), beta (plane-capsule), sin, x1, x2 (capsule-capsule)) and arrays qpos, qvel, ctrl
46
+ (inputs), qacc (a*), nefc, efc_type, efc_id, efc_pos, efc_vel, efc_D, efc_aref, efc_state, efc_force, jac_a (J a*),
47
+ clamped, near_clamp (W, nu), clamp_margin (W,), niter."""
48
+ pairs = pairs or pair_table(mjm)
49
+ W = d_in.qpos.shape[0]
50
+ g = lambda a: a.numpy().copy()
51
+ out = dict(qpos=g(d_in.qpos).astype(np.float64), qvel=g(d_in.qvel).astype(np.float64), ctrl=g(d_in.ctrl),
52
+ qacc=g(d_out.qacc), nefc=g(d_out.nefc), niter=g(d_out.solver_niter))
53
+ for k in ("type", "id", "pos", "vel", "D", "aref", "state", "force"):
54
+ out[f"efc_{k}"] = g(getattr(d_out.efc, k))
55
+ rownnz, rowadr, colind, Jv = (g(x) for x in (d_out.efc.J_rownnz, d_out.efc.J_rowadr, d_out.efc.J_colind, d_out.efc.J))
56
+ nj = out["efc_pos"].shape[1]
57
+ jac_a = np.zeros((W, nj))
58
+ for w in range(W):
59
+ for r in range(int(out["nefc"][w])):
60
+ a, n = rowadr[w, r], rownnz[w, r]
61
+ jac_a[w, r] = Jv[w, 0, a:a + n] @ out["qacc"][w, colind[w, 0, a:a + n]]
62
+ out["jac_a"] = jac_a
63
+ jid = mjm.actuator_trnid[:, 0]
64
+ dadr, qadr = mjm.jnt_dofadr[jid], mjm.jnt_qposadr[jid]
65
+ lim = np.where(mjm.jnt_actfrclimited[jid], mjm.jnt_actfrcrange[jid, 1], np.inf)
66
+ lo = np.where(mjm.jnt_actfrclimited[jid], mjm.jnt_actfrcrange[jid, 0], -np.inf)
67
+ f = g(d_out.qfrc_actuator)[:, dadr]
68
+ out["clamped"] = (f <= lo) | (f >= lim)
69
+ raw = mjm.actuator_gainprm[:, 0] * (out["ctrl"] - out["qpos"][:, qadr]) + mjm.actuator_biasprm[:, 2] * out["qvel"][:, dadr]
70
+ out["near_clamp"] = np.abs(np.abs(raw) - lim) < 0.02 * lim
71
+ margin = np.where(np.isfinite(lim), np.abs(np.abs(raw) - lim) / np.where(np.isfinite(lim), lim, 1.0), np.inf)
72
+ out["clamp_margin"] = margin.min(axis=1)
73
+ n = int(d_out.nacon.numpy()[0])
74
+ geom, wid, dist, pos, frame, dim, adr = (g(x)[:n] for x in (d_out.contact.geom, d_out.contact.worldid,
75
+ d_out.contact.dist, d_out.contact.pos, d_out.contact.frame,
76
+ d_out.contact.dim, d_out.contact.efc_address))
77
+ gx, gm = g(d_out.geom_xpos).astype(np.float64), g(d_out.geom_xmat).astype(np.float64)
78
+ con = [[] for _ in range(W)]
79
+ for c in range(n):
80
+ g1, g2 = int(geom[c, 0]), int(geom[c, 1])
81
+ t1, t2 = int(mjm.geom_type[g1]), int(mjm.geom_type[g2])
82
+ w = int(wid[c])
83
+ e = dict(cid=c, pair=pairs[frozenset((g1, g2))], slot=0, geom=(g1, g2), types=(t1, t2), dist=float(dist[c]),
84
+ pos=pos[c].astype(np.float64), frame=frame[c].astype(np.float64).reshape(3, 3), dim=int(dim[c]),
85
+ rows=[int(r) for r in adr[c] if r >= 0])
86
+ if PLANE in (t1, t2):
87
+ cg = g2 if t1 == PLANE else g1
88
+ if mjm.geom_type[cg] == CAPSULE:
89
+ ax = gm[w, cg].reshape(3, 3)[:, 2]
90
+ e["slot"] = 0 if (e["pos"] - gx[w, cg]) @ ax > 0 else 1
91
+ nrm = e["frame"][0]
92
+ e["beta"] = float(np.linalg.norm(ax - nrm * (nrm @ ax)))
93
+ else:
94
+ e["nu"] = e["dist"] + mjm.geom_size[g1, 0] + mjm.geom_size[g2, 0]
95
+ if t1 == CAPSULE and t2 == CAPSULE:
96
+ ax1, ax2 = gm[w, g1].reshape(3, 3)[:, 2], gm[w, g2].reshape(3, 3)[:, 2]
97
+ x1, x2, _, cand = capsule_segments(gx[w, g1], ax1, mjm.geom_size[g1, 1], gx[w, g2], ax2,
98
+ mjm.geom_size[g2, 1])
99
+ e["sin"] = float(np.linalg.norm(np.cross(ax1, ax2)))
100
+ if x1 is None:
101
+ mid = [0.5 * (gx[w, g1] + ax1 * mjm.geom_size[g1, 1] * a + gx[w, g2] + ax2 * mjm.geom_size[g2, 1] * b)
102
+ for a, b in cand]
103
+ e["slot"] = int(np.argmin([np.linalg.norm(p - e["pos"]) for p in mid]))
104
+ x1, x2 = cand[e["slot"]]
105
+ e["x1"], e["x2"] = float(x1), float(x2)
106
+ con[w].append(e)
107
+ for w in range(W):
108
+ con[w].sort(key=lambda e: (e["pair"], e["slot"]))
109
+ out["contacts"] = con
110
+ return out
111
+
112
+
113
+ def near_contact_distance(mjm, qpos, margin=1e-5):
114
+ """Per state (rows of qpos), the smallest |dist| over the model's pairs within `margin` of touching (MuJoCo C,
115
+ float64 collision; inf if none)."""
116
+ saved = mjm.pair_margin.copy()
117
+ try:
118
+ mjm.pair_margin[:] = margin
119
+ d = mujoco.MjData(mjm)
120
+ out = np.full(len(qpos), np.inf)
121
+ for i, q in enumerate(qpos):
122
+ d.qpos[:] = q
123
+ mujoco.mj_kinematics(mjm, d)
124
+ mujoco.mj_collision(mjm, d)
125
+ if d.ncon:
126
+ out[i] = np.min(np.abs(d.contact.dist[:d.ncon]))
127
+ return out
128
+ finally:
129
+ mjm.pair_margin[:] = saved
130
+
131
+
132
+ def labels(mjm, subs, iterations, ref_contacts=None):
133
+ """({group: bool (W,)}, {continuous label: (W,)}) from the substeps `subs` (mjw_substep dicts, in order);
134
+ ref_contacts: the `con` rows of nablaengine.fixtures.load_contacts for the same worlds (substep 0's contact set
135
+ check), or None. The
136
+ continuous labels (minima over the substeps, for attributing outliers): min_nu (m), min_abs_dist (m, as G2), min_kink
137
+ (|x_e| / (|J_e a*| + |aref_e|)), clamp_margin (| |PD force| - bound | / bound), max_niter."""
138
+ W = len(subs[0]["contacts"])
139
+ lab = {k: np.zeros(W, bool) for k in GROUPS}
140
+ cont = {k: np.full(W, np.inf) for k in ("min_nu", "min_abs_dist", "min_kink", "clamp_margin")}
141
+ cont["max_niter"] = np.zeros(W, int)
142
+ min_nu = cont["min_nu"]
143
+ for k, s in enumerate(subs):
144
+ cont["clamp_margin"] = np.minimum(cont["clamp_margin"], s["clamp_margin"])
145
+ cont["min_abs_dist"] = np.minimum(cont["min_abs_dist"], near_contact_distance(mjm, s["qpos"]))
146
+ cont["max_niter"] = np.maximum(cont["max_niter"], s["niter"])
147
+ for w in range(W):
148
+ for e in s["contacts"][w]:
149
+ cont["min_abs_dist"][w] = min(cont["min_abs_dist"][w], abs(e["dist"]))
150
+ if abs(e["dist"]) < 1e-6:
151
+ lab["G2_contact_flip"][w] = True
152
+ if "nu" in e:
153
+ lab["G6_self_contact"][w] = True
154
+ min_nu[w] = min(min_nu[w], e["nu"])
155
+ if abs(abs(e["frame"][0, 1]) - 0.5) < 0.02:
156
+ lab["G7_basis_switch"][w] = True
157
+ if "beta" in e and abs(e["beta"] - 0.5) < 0.02:
158
+ lab["G7_basis_switch"][w] = True
159
+ if "sin" in e and abs(e["x1"]) < 1 and abs(e["x2"]) < 1 and e["sin"] < 0.05:
160
+ lab["G8_near_parallel"][w] = True
161
+ ne = int(s["nefc"][w])
162
+ x = s["jac_a"][w, :ne] - s["efc_aref"][w, :ne]
163
+ scale = np.abs(s["jac_a"][w, :ne]) + np.abs(s["efc_aref"][w, :ne])
164
+ if ne:
165
+ cont["min_kink"][w] = min(cont["min_kink"][w], float(np.min(np.abs(x) / np.maximum(scale, 1e-30))))
166
+ if ne and (np.abs(x) < 1e-4 * np.maximum(scale, 1e-30)).any():
167
+ lab["G3_kink"][w] = True
168
+ if (s["efc_type"][w, :ne] == LIMIT_JOINT).any():
169
+ lab["G5_limits"][w] = True
170
+ lab["G4_clamped"] |= s["clamped"].any(1)
171
+ lab["G4_near_clamp"] |= s["near_clamp"].any(1)
172
+ lab["G9_nonconv"] |= s["niter"] >= iterations
173
+ lab["G2_contact_flip"] |= cont["min_abs_dist"] < 1e-6
174
+ if ref_contacts is not None:
175
+ for w in range(W):
176
+ ours = sorted(e["pair"] for e in subs[0]["contacts"][w] if e["dist"] < 0)
177
+ ref = sorted(int(r[0]) for r in ref_contacts[w] if r[0] >= 0)
178
+ if ours != ref:
179
+ lab["G2_contact_flip"][w] = True
180
+ lab["G1_axis_lt_5mm"] = min_nu < 5e-3
181
+ lab["G1_axis_lt_1mm"] = min_nu < 1e-3
182
+ lab["all"][:] = True
183
+ lab["G0_normal"] = ~np.any([lab[k] for k in OUTSIDE_G0], axis=0)
184
+ return lab, cont
185
+
186
+
187
+ def qpos_tangent(g, q):
188
+ """qpos-form cotangents (S, NQ) -> dof-tangent form (S, NV) at the states q: the quaternion part as
189
+ 1/2 Im(xi* (x) g) / |xi|^2 (jax64.qpos_to_dof; the left inverse of MuJoCo Warp's _dof_to_qpos)."""
190
+ xi, gq = np.asarray(q, np.float64)[:, 3:7], np.asarray(g, np.float64)[:, 3:7]
191
+ w, x, y, z = xi.T
192
+ a, b, c, d = gq.T
193
+ v = np.stack([w * b - x * a - y * d + z * c, w * c + x * d - y * a - z * b, w * d - x * c + y * b - z * a], 1)
194
+ g = np.asarray(g, np.float64)
195
+ return np.concatenate([g[:, :3], 0.5 * v / np.sum(xi * xi, 1, keepdims=True), g[:, 7:]], 1)
196
+
197
+
198
+ def world_errors(g, ref):
199
+ """Per world: relative error |g - ref| / max(|ref|, 1e-9) and cosine (both along axis 1)."""
200
+ g, ref = np.asarray(g, np.float64), np.asarray(ref, np.float64)
201
+ nr = np.linalg.norm(ref, axis=1)
202
+ e = np.linalg.norm(g - ref, axis=1) / np.maximum(nr, 1e-9)
203
+ cos = np.sum(g * ref, axis=1) / np.maximum(np.linalg.norm(g, axis=1) * nr, 1e-30)
204
+ return e, cos
205
+
206
+
207
+ def group_mask(lab, name):
208
+ """The states of a group (lab[name]) or of a subgroup 'A&B' (A and B) / 'A&~B' (A and not B), where G0 stands for
209
+ G0_normal."""
210
+ if "&" not in name:
211
+ return lab[name]
212
+ a, b = name.split("&")
213
+ full = lambda g: "G0_normal" if g == "G0" else g
214
+ return lab[full(a)] & (~lab[full(b[1:])] if b.startswith("~") else lab[full(b)])
215
+
216
+
217
+ def stats(e, cos=None):
218
+ e = np.asarray(e)
219
+ if not len(e):
220
+ return dict(n=0)
221
+ out = dict(n=int(len(e)), median=float(np.median(e)), p90=float(np.quantile(e, 0.9)),
222
+ p99=float(np.quantile(e, 0.99)), max=float(e.max()))
223
+ if cos is not None:
224
+ out["cos_p1"] = float(np.quantile(cos, 0.01))
225
+ return out
226
+