Commit 2c66ccd
Fix smooth spherical-Bessel basis: build constants in float64, make the symbolic-function cache effective (#826)
SphericalBesselFunction(smooth=True) fed its cutoff BUFFER into the
symbolic builder, so cutoff**1.5 was evaluated in the ambient default
dtype: under float32 the basis prefactor is rounded once and every
generated coefficient is scaled by 1 + 2.6e-8. The basis therefore
disagreed with matgl's own spherical_bessel_smooth() (which the LAMMPS
export path substitutes as 'mathematically identical') and silently
changed with torch.set_default_dtype. Passing float(self.cutoff) fixes
both, and float32 output is bit-identical before/after (the correction is
below one float32 ULP; nothing needs retraining).
The same change makes the module-level lru_cache on _get_lambda_func
actually hit (a tensor argument hashes by identity), saving ~220 ms of
sympy.simplify per constructed module. The two method-level lru_cache
decorators are removed: keyed on self they can never hit, while pinning up
to 128 dropped modules against garbage collection.
Three regression tests: closed-form agreement, default-dtype independence,
cache reuse. All three fail on 4.0.3 and pass with this change.
Co-authored-by: Longyun Shen <longyun.shen@nus.edu>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>1 parent 161f5d9 commit 2c66ccd
2 files changed
Lines changed: 50 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
39 | 38 | | |
40 | 39 | | |
41 | 40 | | |
| |||
129 | 128 | | |
130 | 129 | | |
131 | 130 | | |
132 | | - | |
133 | 131 | | |
134 | 132 | | |
135 | 133 | | |
| |||
140 | 138 | | |
141 | 139 | | |
142 | 140 | | |
143 | | - | |
144 | 141 | | |
145 | | - | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
146 | 148 | | |
147 | 149 | | |
148 | 150 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
3 | 5 | | |
4 | 6 | | |
5 | 7 | | |
| |||
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
| 20 | + | |
18 | 21 | | |
19 | 22 | | |
20 | 23 | | |
| |||
147 | 150 | | |
148 | 151 | | |
149 | 152 | | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
0 commit comments