Skip to content

chore: pin numpy only where pymatgen needs it, and declare scipy for the core - #299

Merged
timurbazhirov merged 1 commit into
mainfrom
chore/numpy-pin-only-for-tools
Sep 12, 2026
Merged

timurbazhirov merged 1 commit into
mainfrom
chore/numpy-pin-only-for-tools

Conversation

@timurbazhirov

Copy link
Copy Markdown
Member

Why

numpy<=1.26.4 sits in the core dependencies on pymatgen's behalf, but only the tools extra imports pymatgen. So every downstream package that uses made's core alone — Lattice, ReciprocalLattice, symmetry points, k-paths — is forced down to numpy 1.26, whether or not it touches tools.

It is worse than a cap. When a downstream environment also wants numpy 2 (anything pulling the newest scipy does), pip resolves the conflict by silently backtracking made rather than failing. mat3ra/q3's pip install -e ".[test,relax,build]" landed on mat3ra-made 2024.6.12 — two years old, predating mat3ra.made.reciprocal — installed cleanly, and failed at import time in CI. The only workaround downstream is to cap numpy at 1.26.4 for the whole project.

Change

  1. numpy<=1.26.4 moves from the core dependencies into [tools], next to pymatgen==2024.4.13, which is the thing that needs it. Core keeps numpy unpinned.
  2. A second declaration bug found while verifying: basis/__init__.py imports scipy.spatial at load time and material.py imports basis, but scipy was declared only in [tools] — so a core-only install could not import Material. scipy moves to the core dependencies. That is the only scipy import outside tools/.

Verified

Core on numpy 2.5.3 (scipy 1.18.1), in a clean venv with only core + test deps:

tests/py/unit/test_cell.py test_lattice.py test_lattice_type_extended.py
test_reciprocal_lattice.py test_symmetry_points.py test_reciprocal_paths.py
76 passed

Material.create, its basis, cell volume and to_dict also work there. A scan of the 14 core modules for the APIs numpy 2.0 removed (np.float_, np.product, np.in1d, np.trapz, …) finds none. test_material.py and test_primitive_cell.py were left out because they import tools (ASE) transitively.

[tools] is unaffected — it still resolves numpy 1.26.4:

pip install --dry-run ".[tools]"
-> numpy 1.26.4, pymatgen 2024.4.13, pymatgen-analysis-defects 2024.4.23, scipy 1.17.1, ase 3.29.0

The existing CI installs [tests], which includes mat3ra-made[tools], so the Python test matrix keeps running on numpy 1.26.4 exactly as before.

Downstream

mat3ra/q3#175 currently carries numpy>=1.24,<=1.26.4 and mat3ra-made>=2026.8.26.post0 to keep pip from choosing the 2024 release. Once this merges and publishes, both bounds there can go.

🤖 Generated with Claude Code

…the core

numpy<=1.26.4 sat in the core dependencies on pymatgen's behalf, but only the
tools extra imports pymatgen. Every downstream package that used made's core
alone -- lattices, reciprocal lattices, symmetry points -- was forced down to
numpy 1.26 regardless. Worse, pip resolves the conflict with any package that
wants numpy 2 by silently backtracking made rather than failing: q3's
`pip install -e .[test,relax,build]` landed on mat3ra-made 2024.6.12, two years
old and without mat3ra.made.reciprocal, and failed at import time.

The pin moves into [tools], next to pymatgen.

Verifying that turned up a second declaration bug: basis/__init__.py imports
scipy.spatial at load time and material.py imports basis, but scipy was
declared only in [tools], so a core install could not import Material. scipy
moves to the core dependencies.

Checked:
- core on numpy 2.5.3 (scipy 1.18): test_cell, test_lattice,
  test_lattice_type_extended, test_reciprocal_lattice, test_symmetry_points,
  test_reciprocal_paths -- 76 passed; Material.create, its basis, cell volume
  and to_dict also work there.
- [tools] still resolves numpy 1.26.4 with pymatgen 2024.4.13 and scipy 1.17.1,
  so pymatgen users are unaffected.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Signed-off-by: Timur Bazhirov <timur@mat3ra.com>
@timurbazhirov
timurbazhirov merged commit 2019f5d into main Sep 12, 2026
9 checks passed
@timurbazhirov
timurbazhirov deleted the chore/numpy-pin-only-for-tools branch September 12, 2026 21:19
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.

2 participants