Add MaxDeterminantGrid with full AngularGrid and AtomGrid integration#297
Add MaxDeterminantGrid with full AngularGrid and AtomGrid integration#297alok-108 wants to merge 7 commits intotheochem:masterfrom
Conversation
|
Hi @PaulWAyers, Would really appreciate your review whenever you get time. Happy to make any changes if needed! |
1 similar comment
|
Hi @PaulWAyers, Would really appreciate your review whenever you get time. Happy to make any changes if needed! |
There was a problem hiding this comment.
Pull request overview
Adds a new maximum-determinant (Fekete) spherical quadrature (MaxDeterminantGrid) and wires it into AngularGrid/AtomGrid, with bundled precomputed datasets and docs/examples.
Changes:
- Introduces
MaxDeterminantGridwith loading of packaged.npzpoint/weight datasets and a convenienceintegrate()API. - Extends
AngularGrid/AtomGridto supportmethod="maxdet"and updates related tests. - Adds packaged maxdet datasets, a fetch script, and documentation/notebook integration.
Reviewed changes
Copilot reviewed 13 out of 26 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/grid/max_det.py | New MaxDeterminantGrid implementation and dataset loader. |
| src/grid/angular.py | Adds method="maxdet" support and routes loading/degree-size mapping accordingly. |
| src/grid/atomgrid.py | Updates docstrings to include maxdet as an available angular method. |
| src/grid/init.py | Re-exports maxdet module from package root. |
| src/grid/tests/test_maxdet.py | New unit tests for maxdet weights and integration behavior. |
| src/grid/tests/test_atomgrid.py | Extends existing AtomGrid tests to run with method="maxdet". |
| src/grid/tests/test_angular.py | Fixes/adjusts spherical harmonic indexing and assertions in tests. |
| src/grid/data/max_det/init.py | Marks maxdet data directory as a package. |
| src/grid/data/max_det/maxdet_1_4.npz | Adds precomputed maxdet dataset (degree 1). |
| src/grid/data/max_det/maxdet_2_9.npz | Adds precomputed maxdet dataset (degree 2). |
| src/grid/data/max_det/maxdet_3_16.npz | Adds precomputed maxdet dataset (degree 3). |
| src/grid/data/max_det/maxdet_4_25.npz | Adds precomputed maxdet dataset (degree 4). |
| src/grid/data/max_det/maxdet_5_36.npz | Adds precomputed maxdet dataset (degree 5). |
| src/grid/data/max_det/maxdet_10_121.npz | Adds precomputed maxdet dataset (degree 10). |
| src/grid/data/max_det/maxdet_20_441.npz | Adds precomputed maxdet dataset (degree 20). |
| src/grid/data/max_det/maxdet_30_961.npz | Adds precomputed maxdet dataset (degree 30). |
| src/grid/data/max_det/maxdet_40_1681.npz | Adds precomputed maxdet dataset (degree 40). |
| scripts/fetch_maxdet_data.py | Script to download and convert upstream maxdet datasets into .npz. |
| examples/max_det_integration.ipynb | Example notebook demonstrating maxdet spherical integration. |
| doc/notebooks/max_det_integration.nblink | Links the example notebook into the Sphinx docs build. |
| doc/index.rst | Adds the maxdet notebook to the documentation toctree. |
| MANIFEST.in | Ensures maxdet .npz files are included in source distributions. |
| .gitignore | Ignores debug/output artifacts and autogenerated version file. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| The integral of the function/arrays over the unit sphere. | ||
| """ | ||
| if len(args) == 1 and callable(args[0]): | ||
| return 4 * np.pi * np.sum(args[0](self.points) * self.weights) |
There was a problem hiding this comment.
In the callable branch, integrate() bypasses Grid.integrate()'s shape/type checks and uses np.sum(args[0](self.points) * self.weights). If the callable returns a scalar or an array with shape (N,1)/(1,N), NumPy broadcasting can produce an incorrect result without raising. Consider coercing the result to np.asarray, validating it is 1-D with shape (self.size,), and then using the same einsum/integration path as Grid.integrate().
| return 4 * np.pi * np.sum(args[0](self.points) * self.weights) | |
| values = np.asarray(args[0](self.points)) | |
| if values.ndim != 1 or values.shape != (self.size,): | |
| raise ValueError( | |
| f"Callable passed to integrate must return a 1-D array with shape {(self.size,)}, " | |
| f"got shape {values.shape}." | |
| ) | |
| return 4 * np.pi * super().integrate(values) |
| import numpy as np | ||
| import pytest | ||
| from grid.max_det import MaxDeterminantGrid | ||
| from grid.utils import generate_real_spherical_harmonics, convert_cart_to_sph |
There was a problem hiding this comment.
convert_cart_to_sph is imported but never used in this test file. Removing the unused import will keep the test module clean and avoid linting issues in stricter environments.
| from grid.utils import generate_real_spherical_harmonics, convert_cart_to_sph | |
| from grid.utils import generate_real_spherical_harmonics |
|
@PaulWAyers @marco-2023 @FarnazH I fixed the three things the Copilot code review pointed out. Here’s what I changed:
All the tests in test_angular.py and test_maxdet.py still pass on my computer. The changes are in commit 7cc7b95 and should show up here now. |
Implemented MaxDeterminantGrid using maximum determinant (Fekete) points for spherical integration with positive weights and improved numerical stability.
Key Features
Validation
Fixes
Notes
All tests and documentation build successfully in a clean environment.
Updates (pre-review cleanup):
results.txt,output.txt) and auto-generated_version.pyfrom tracked filesfetch_maxdet_data.py__all__tomax_det.py, removed deadMAXDET_CACHEfromangular.py_get_available_degrees()method4pifactor applied consistently atAngularGridlevel