Fmm harmonic compression - #182
Conversation
Ports the current fmmgen driver (Morton-ordered SoA arrays, runtime
variant selection between uncompressed and harmonic-compressed
operators) into fidimag's fmmlib, replacing a pre-S2M snapshot. The
compressed multipole/local arrays are (p+1)^2 coefficients instead of
C(p+3,3), which measures ~1.7x faster at the M2L kernel level for this
source_order=1 (point dipole) configuration.
- example.py: regenerate operators.{cpp,h} with compress=True alongside
the existing config (order=8, source_order=1, harmonic_derivs=True).
- fmm.pyx / demag.py: DemagFMM gains a `compressed` flag (default True)
threaded through to fmm_select(), which must run before build_tree
since it determines the coefficient array sizes.
Two bugs in fmmgen's driver were found and fixed upstream while wiring
this up (both are pre-existing, not introduced by compression):
- Tree::compute_field_* read source values from a body_S array
snapshotted once in build_tree, so a Tree reused across repeated
solves with new spin/moment data each time (this integrator's usage
pattern) kept using the values from construction. Fixed by
re-reading through the live Particle pointers every solve.
- The parallel dual-tree traversal double-counted every P2P/M2L
interaction on trees small/shallow enough to fully classify during
the breadth-first expansion phase (a few hundred particles) -- the
loop broke without swapping frontier to the now-empty next set, so
the depth-first phase re-classified and re-appended the same pairs.
fmmgen's own benchmarks only use N>=100k and never hit this.
Verified: DemagFMM (fmm and bh, compressed and uncompressed) agree with
brute-force DemagFull to ~1e-15 relative L2 error; full test suite
(187 passed) shows no regressions.
Existing tests only checked DemagFMM/DemagFull and Demag/DemagFull separately, never DemagFMM against Demag directly, and only ever at theta=0.0 (exact pairwise sum, no multipole approximation exercised). _run_comparison now takes an optional reference interaction (defaults to DemagFull, unchanged for existing tests). Three new tests compare DemagFMM against Demag: 2D and 3D at theta=0.0 (near machine precision, same as the DemagFull comparisons), plus one at theta=0.2 to actually exercise the multipole acceptance criterion, at a tolerance matched to the measured accuracy for that theta/order/ncrit combination.
|
Looks great to me. I cannot provide precise feedback as there are lots of technical details for this massive source code. Tests look fine, which are an advantage when adding/improving new features with AI. Can you provide:
I can try to add some of them if you need to |
… fix a DemagFMM order-validation bug
…trict-qualified pointers
CI failure: two bugs in fmmgen, the first hiding the secondThe build fails at Both causes are in 1. The include names the path the header was written to
#include "/tmp/fidimag_regen/operators.h"
f = open(f"{src_dir.rstrip('/')}/{name}.{fext}", "w")
...
f.write(f'#include "{name}.{hext}"\n')So generating with 2. What that was hiding:
|
Pulls in new FMM perf. improvements, should be substantially faster. Also had fixed a sign bug so it'll be more accurate too.