Skip to content

Fix numpy 2.x compatibility: replace np.math.factorial with math.factorial#241

Open
exopoiesis wants to merge 1 commit intomicrosoft:mainfrom
exopoiesis:fix/numpy2-math-factorial
Open

Fix numpy 2.x compatibility: replace np.math.factorial with math.factorial#241
exopoiesis wants to merge 1 commit intomicrosoft:mainfrom
exopoiesis:fix/numpy2-math-factorial

Conversation

@exopoiesis
Copy link
Copy Markdown

Summary

numpy.math was deprecated in numpy 1.25 and removed in numpy 2.0 (release notes).

This causes AttributeError: module 'numpy' has no attribute 'math' when using any checkpoint that triggers GemNetTCtrl with condition_on_adapt — specifically in basis_utils.py:sph_harm_prefactor() and associated_legendre_polynomials().

Fix

Replace np.math.factorial with math.factorial from the standard library (identical behavior, zero additional dependencies). 4 occurrences in 1 file.

Affected checkpoints

Broken (with numpy >= 2.0): space_group, dft_band_gap, dft_mag_density, ml_bulk_modulus, dft_mag_density_hhi_score

Unaffected (don't trigger the code path): chemical_system, chemical_system_energy_above_hull

Reproduction

from mattergen.generator import CrystalGenerator
from mattergen.common.utils.data_classes import MatterGenCheckpointInfo

info = MatterGenCheckpointInfo.from_hf_hub("space_group")
gen = CrystalGenerator(checkpoint_info=info, batch_size=1, num_batches=1,
                        properties_to_condition_on={"space_group": 225})
gen.generate()  # → AttributeError: module 'numpy' has no attribute 'math'

Verified

Generated 192 structures with space_group checkpoint after applying this fix (RTX 4070, numpy 2.1.3, PyTorch 2.4.1).

🤖 Generated with Claude Code

…orial

numpy.math was deprecated in numpy 1.25 and removed in numpy 2.0.
This causes AttributeError when using any checkpoint that triggers
GemNetTCtrl with condition_on_adapt (space_group, dft_band_gap, etc.).

Replace np.math.factorial with math.factorial from the standard library
(identical behavior, zero additional dependencies).

Affected checkpoints: space_group, dft_band_gap, dft_mag_density,
ml_bulk_modulus, dft_mag_density_hhi_score. The chemical_system and
chemical_system_energy_above_hull checkpoints work because they don't
trigger the affected code path.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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