From 63c5bc1eabeae962856dfeb55b2676da7a3dbe8f Mon Sep 17 00:00:00 2001 From: Igor Morozov Date: Sun, 29 Mar 2026 18:00:15 +0300 Subject: [PATCH] Fix numpy 2.x compatibility: replace np.math.factorial with math.factorial 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) --- mattergen/common/gemnet/layers/basis_utils.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mattergen/common/gemnet/layers/basis_utils.py b/mattergen/common/gemnet/layers/basis_utils.py index 9f06d45c..6a9ff85a 100644 --- a/mattergen/common/gemnet/layers/basis_utils.py +++ b/mattergen/common/gemnet/layers/basis_utils.py @@ -5,6 +5,7 @@ Adapted from https://github.com/FAIR-Chem/fairchem/blob/main/src/fairchem/core/models/gemnet/layers/basis_utils.py. """ +import math from typing import Any, List import numpy as np @@ -106,8 +107,8 @@ def sph_harm_prefactor(l_degree: int, m_order: int) -> float: return ( (2 * l_degree + 1) / (4 * np.pi) - * np.math.factorial(l_degree - abs(m_order)) - / np.math.factorial(l_degree + abs(m_order)) + * math.factorial(l_degree - abs(m_order)) + / math.factorial(l_degree + abs(m_order)) ) ** 0.5 @@ -177,8 +178,8 @@ def associated_legendre_polynomials( for m_order in range(1, l_degree + 1): # P_1(-1), P_2(-1) P_2(-2) P_l_m[l_degree][-m_order] = sym.simplify( (-1) ** m_order - * np.math.factorial(l_degree - m_order) - / np.math.factorial(l_degree + m_order) + * math.factorial(l_degree - m_order) + / math.factorial(l_degree + m_order) * P_l_m[l_degree][m_order] )