Add lattice rules for (hyper)cubic grid integration - #293
Conversation
- Implement Lattice class with rank-1 lattice rules - Support embedded lattice rules (powers of 2) - Include tabulated generating vectors from UNSW (Order-2 weights) - Add comprehensive test suite (25 tests, all passing) - Support arbitrary parallelepipeds via affine transformation - Addresses issue theochem#241
|
@marco-2023 we should maybe talk about this next week? |
…ts, change tolerance,override __getitem__
|
The Windows CI failure (
|
… add tests, change tolerance,override __getitem__" This reverts commit 8a27314.
|
After looking into it more the CI failure was actually caused by the additional tests I added in that commit specifically |
There was a problem hiding this comment.
Pull request overview
Adds rank-1 lattice-rule integration for affine-transformed hypercubic domains.
Changes:
- Adds embedded lattice point generation and equal-volume weights.
- Adds multidimensional interpolation and persistence support.
- Adds validation and integration tests.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
src/grid/lattice.py |
Implements the Lattice grid. |
src/grid/tests/test_lattice.py |
Tests lattice construction and behavior. |
src/grid/__init__.py |
Exports the lattice API. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| def __init__( | ||
| self, | ||
| n_points, | ||
| dimension, | ||
| generating_vector=None, | ||
| rule="order2", | ||
| origin=None, | ||
| axes=None, | ||
| ): |
| generating_vector = np.asarray(generating_vector, dtype=np.int64) | ||
| if generating_vector.shape != (dimension,): | ||
| raise ValueError( | ||
| f"generating_vector must have shape ({dimension},), " | ||
| f"got {generating_vector.shape}" | ||
| ) |
| # Use LinearNDInterpolator from scipy | ||
| interpolator = LinearNDInterpolator(self.points, values) | ||
| return interpolator(new_points) |
| if np.abs(np.linalg.det(axes)) < 1e-10: | ||
| raise ValueError( | ||
| f"axes must be linearly independent, got det(axes)={np.linalg.det(axes)}" | ||
| ) |
|
|
||
|
|
||
| # Tabulated generating vectors from UNSW (https://web.maths.unsw.edu.au/~fkuo/lattice/) | ||
| # Truncated to first 100 dimensions for practical use |

This PR implements lattice rules for efficient numerical integration over (hyper)cubic grids, addressing issue #241 .
Following the references provided in the issue (Sloan's paper and the UNSW lattice rules database), I've implemented rank-1 lattice rules as a new integration method.
Implementation :
scipy.interpolate.LinearNDInterpolatorTesting: