Skip to content

Dev - #52

Open
HatPdotS wants to merge 14 commits into
mainfrom
dev
Open

Dev#52
HatPdotS wants to merge 14 commits into
mainfrom
dev

Conversation

@HatPdotS

Copy link
Copy Markdown
Owner
  • Fixed crash in difference refinement with mismatched reflection files: HKL reindexing (validate_hkl/remap/reduce_to_spacegroup) now carries all per-reflection fields (including the anomalous bookkeeping read by hkl_for_sf()) instead of a hardcoded subset.
  • Added a metal shader for structure factor calculation

HatPdotS and others added 14 commits July 24, 2026 14:34
The Metal splat's test suite could pass while the kernel was dead code.
_add_isotropic/_add_anisotropic swallowed any dispatch exception with
`except Exception: pass`, so Engine.AUTO fell back to the same
add_isotropic_plain_var that Engine.EAGER selects — every comparison then
trivially agreed. The CUDA tests are safe from this only because
Engine.TRITON re-raises; there was no equivalent for Metal.

Engine.METAL + should_use_metal()
- Fourth Engine member mirroring TRITON: forces the Metal path and raises
  rather than degrading (wrong device/dtype, uncompiled shader, or a
  dispatch failure).
- should_use_metal() owns device, dtype and shader availability together.
  Folding availability in is what makes the force strict: as a nested `if`
  at the dispatch site, an unavailable shader slipped past the gate onto
  the portable splat even under a forced engine.
- should_use_triton()'s implicit-AUTO tail is now explicit, with a
  ValueError fallthrough — that tail is why any new member silently
  selected Triton.
- compile.last_error() is exported and consumed, so the raised message
  carries the compile diagnosis instead of being dead code.

Kernel test coverage (both backends)
- Cells, atom sets and metrics move to tests/helpers/kernel_cases.py; the
  two files had byte-identical private copies, which is how two gaps
  survived in both at once: unit occupancies hid the grad/occ rescaling,
  and zero off-diagonal U left every ellipsoid axis-aligned, so the
  cross-terms and the 4*pi^2 off-diagonal U gradients were never run.
- Gradients now check magnitude, not just direction: assert_grads_agree
  moves to tests/helpers/grad_asserts.py. A bare cosine passes a kernel
  that returns 2*grad.
- Dispatch provenance uses a call recorder, not map comparison: the
  portable splat's scatter_add is not order-reproducible on MPS (~1e-7
  run to run), so torch.equal against it proves nothing either way.
- Aniso now also runs on the sheared cell; only iso did before.
- MPS forward tolerances re-measured (iso 5.9e-3, aniso 1.0e-3) and set
  from the measurements. CUDA tolerances left alone — retightening needs
  a CUDA host to measure on.

Backend gating is the marker's job alone
- --run-cuda/--run-mps warn and let the marked tests run, so they error
  with the real backend error. A collection-time UsageError aborted the
  whole session and said nothing about which call failed.
- Removed 13 redundant availability checks (in-body skips and skipif
  decorators) sitting inside already-marked tests; a second layer can
  only mask a forgotten marker, turning "this host cannot run it" into a
  silent pass. Added cuda_device/mps_device fixtures that do no checking.
- Promoted two tests mismarked @pytest.mark.gpu while hardcoding CUDA.

ReflectionData: exempt non-per-reflection fields by name
_reindex_per_reflection and __select__ decided "is this per-reflection?"
by shape[0] == n_hkl. That collides when the dataset has exactly as many
reflections as the field is long — U_aniso is (6,), so a 6-reflection
dataset had it gathered and reordered as per-reflection data.
_assert_per_reflection_consistent and reduce_to_spacegroup already
exempted by name; all four are consistent now.

epsilon_from_hkl: answer on hkl's device
apply_to_hkl moves its input onto the symmetry matrices' device, so a
spacegroup built elsewhere than the reflection data made the Hs == h0
comparison raise. Build h on the symmetry device, return on hkl's.
… and than used to confirm the the respective kernels.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant