Add PolarMACE support to MaceTorchSimModel#1441
Conversation
|
@janosh would you mind taking a look at this? Trying to get MACE Polar working here. |
|
Thanks for working on this @orionarcher!
|
7ceb41c to
ee0e3a7
Compare
Cherry-picks the polar-model functionality from #1441 without the unrelated linter/style sweep: - Auto-detect PolarMACE via isinstance and forward PolarMACE-specific inputs (rcell, volume, external_field, fermi_level, density_coefficients) with sensible defaults that match AtomicData.from_config(). - Read external_E_field from SimState extras when present. - Expose PolarMACE outputs (charges, dipole, density_coefficients, polarizability, etc.) in the results dict. - Pad the new tensors inline in _fill_padded_data, matching the existing displacement pattern, so the torch.compile path works for polar models without changing the function signature or introducing new persistent buffers. Tests: add the 6 polar-specific tests from #1441 (basic, with_extras, no_extras_vs_zero_extras, batched, batched_with_extras, matches_ase). Existing tests are untouched.
Cherry-picks the polar-model functionality from ACEsuit#1441 without the unrelated linter/style sweep: - Auto-detect PolarMACE via isinstance and forward PolarMACE-specific inputs (rcell, volume, external_field, fermi_level, density_coefficients) with sensible defaults that match AtomicData.from_config(). - Read external_E_field from SimState extras when present. - Expose PolarMACE outputs (charges, dipole, density_coefficients, polarizability, etc.) in the results dict. - Pad the new tensors inline in _fill_padded_data, matching the existing displacement pattern, so the torch.compile path works for polar models without changing the function signature or introducing new persistent buffers. Tests: add the 6 polar-specific tests from ACEsuit#1441 (basic, with_extras, no_extras_vs_zero_extras, batched, batched_with_extras, matches_ase). Existing tests are untouched.
Cherry-picks the polar-model functionality from ACEsuit#1441 without the unrelated linter/style sweep: - Auto-detect PolarMACE via isinstance and forward PolarMACE-specific inputs (rcell, volume, external_field, fermi_level, density_coefficients) with sensible defaults that match AtomicData.from_config(). - Read external_E_field from SimState extras when present. - Expose PolarMACE outputs (charges, dipole, density_coefficients, polarizability, etc.) in the results dict. - Pad the new tensors inline in _fill_padded_data, matching the existing displacement pattern, so the torch.compile path works for polar models without changing the function signature or introducing new persistent buffers. Tests: add the 6 polar-specific tests from ACEsuit#1441 (basic, with_extras, no_extras_vs_zero_extras, batched, batched_with_extras, matches_ase). Existing tests are untouched.
ee0e3a7 to
6e118a6
Compare
Summary
rcell,volume,external_field,fermi_level,density_coefficients) through the TorchSim interface with sensible defaults matchingAtomicData.from_config()isinstancecheck (matching the ASE calculator pattern) and forward additional outputs (charges,dipole,density_coefficients, etc.) in the results dicttorch.compilepathDesign decisions
isinstance(model, PolarMACE)— zero user burden, matches ASE calculator patternAtomicData.from_config(): zeros forexternal_field,0.0forfermi_level,zeros(n_atoms, 1)fordensity_coefficientsexternal_E_fieldread from TorchSimSimStateextras (viaSystemExtras.EXTERNAL_E_FIELD), mapped toexternal_fieldin MACE's data_dictprepare_graph()withcell.view(-1, 3, 3), so existing[n_systems, 3, 3]format works for bothTest plan
test_torchsim_polar_basic— forward pass with defaults (no extras)test_torchsim_polar_with_extras— forward pass with explicit extrastest_torchsim_polar_no_extras_vs_zero_extras— verify defaults match zero extrastest_torchsim_polar_batched— batched multi-system forward passtest_torchsim_polar_batched_with_extras— batched with per-system extrastest_torchsim_polar_matches_ase— compare against ASEMACECalculator(model_type="PolarMACE")test_torchsim.pytests should pass unchanged (CI verification needed)