Skip to content

Add lattice rules for (hyper)cubic grid integration - #293

Open
Ao-chuba wants to merge 3 commits into
theochem:masterfrom
Ao-chuba:feature/lattice-rules
Open

Add lattice rules for (hyper)cubic grid integration#293
Ao-chuba wants to merge 3 commits into
theochem:masterfrom
Ao-chuba:feature/lattice-rules

Conversation

@Ao-chuba

Copy link
Copy Markdown
Member

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 :

  • New Lattice class using tabulated generating vectors from UNSW database
  • Supports embedded lattice rules (powers of 2, up to 2²⁰ points)
  • Equal-weight integration with formula: $\mathbf{x}_k = { \frac{k \cdot \mathbf{z}}{n} }$
  • Works with arbitrary parallelepipeds via affine transformation
  • Supports up to 50 dimensions (extensible to 3600+ if needed)
  • Includes basic interpolation via scipy.interpolate.LinearNDInterpolator

Testing:

  • Input validation, point generation, integration accuracy
  • Embedded property verification, interpolation, file I/O
Screenshot 2026-02-11 023415 closes #241

- 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
@PaulWAyers

Copy link
Copy Markdown
Member

@marco-2023 we should maybe talk about this next week?

@Ao-chuba

Copy link
Copy Markdown
Member Author

The Windows CI failure (Python 3.12 on OS windows-latest) is not caused by this PR.
its failing in test_angular.py::test_orthogonality_of_spherical_harmonic_at_high_degrees the cause being The test sets degree = 88 * 2, calling generate_real_spherical_harmonics(l_max=88) with 15,756 grid points. At utils.py:655:

spherical_harm = np.zeros(((l_max + 1) ** 2, numb_pts), dtype=np.longdouble)`

as for lattice test all pass.
image

@PaulWAyers @marco-2023

… add tests, change tolerance,override __getitem__"

This reverts commit 8a27314.
@Ao-chuba

Ao-chuba commented Apr 24, 2026

Copy link
Copy Markdown
Member Author

After looking into it more the CI failure was actually caused by the additional tests I added in that commit specifically test_error_convergence which created large grids consuming extra memory on the Windows runner. The angular test was right at the memory boundary, and the additional tests tipped it over. After reverting, the CI is green again.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/grid/lattice.py
Comment on lines +110 to +118
def __init__(
self,
n_points,
dimension,
generating_vector=None,
rule="order2",
origin=None,
axes=None,
):
Comment thread src/grid/lattice.py
Comment on lines +175 to +180
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}"
)
Comment thread src/grid/lattice.py
Comment on lines +305 to +307
# Use LinearNDInterpolator from scipy
interpolator = LinearNDInterpolator(self.points, values)
return interpolator(new_points)
Comment thread src/grid/lattice.py
Comment on lines +200 to +203
if np.abs(np.linalg.det(axes)) < 1e-10:
raise ValueError(
f"axes must be linearly independent, got det(axes)={np.linalg.det(axes)}"
)
Comment thread src/grid/lattice.py


# Tabulated generating vectors from UNSW (https://web.maths.unsw.edu.au/~fkuo/lattice/)
# Truncated to first 100 dimensions for practical use
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.

Lattice rules for (hyper)cubic grids

3 participants