Skip to content

Filter out grid points with negligible weights in horton3 adapter#36

Open
Ao-chuba wants to merge 4 commits intotheochem:mainfrom
Ao-chuba:fix-horton3-weights
Open

Filter out grid points with negligible weights in horton3 adapter#36
Ao-chuba wants to merge 4 commits intotheochem:mainfrom
Ao-chuba:fix-horton3-weights

Conversation

@Ao-chuba
Copy link

@Ao-chuba Ao-chuba commented Jan 25, 2026

This PR modifies the horton3 adapter to filter out grid points with negligible weights (< 1e-15) during grid setup, ensuring cleaner data for density partitioning.
Changes

  • File: src/denspart/adapters/horton3.py
  • Action: Added a boolean mask to filter grid.points and grid.weights where weights are below the threshold of 1e-15.
    Motivation

Grid points with essentially zero weight do not contribute to the density partitioning and can cause numerical noise or inefficiency. Filtering them out ensures the grid contains only significant points.

Verification

  • Test Suite: Ran pytest locally; all tests passed.
  • Manual Testing: Verified that the code runs correctly on example data (density-water.npz) and that negligible weights are effectively ignored (confirmed via check_weights.py analysis before cleanup).

closes #35

@PaulWAyers
Copy link
Member

This might be something that should be handled at the grid level (in the grid package) directly. Thoughts @tovrstra and @FarnazH ?

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements a performance optimization by filtering out grid points with negligible weights (< 1e-15) in the horton3 adapter during grid setup, addressing a TODO comment that was present in the code.

Changes:

  • Added import of Grid from grid.basegrid to enable creation of filtered grid objects
  • Implemented filtering logic to remove grid points with weights below 1e-15 when store_atgrids=False
  • Removed the TODO comment about removing zero-weight grid points

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Ao-chuba
Copy link
Author

@PaulWAyers
You're right ,handling this in grid would be cleaner for the whole ecosystem. I went with this approach mainly because it was simpler and directly addressed the existing TODO in this file. It gets the job done for denspart right now without requiring changes to external dependencies.

@Ao-chuba Ao-chuba force-pushed the fix-horton3-weights branch from 99f8d95 to a85f4d7 Compare February 7, 2026 19:47
@Ao-chuba
Copy link
Author

Ao-chuba commented Feb 7, 2026

@tovrstra This is same CI failure we saw in PR issue . The failures were due to scipy 1.15 removing functions required by denspart's dependencies. I have applied the same fix here:

  • Pinned scipy < 1.15 in pyproject.toml.
  • Updated tests/test_properties.py to be compatible with this version.

@Ao-chuba Ao-chuba force-pushed the fix-horton3-weights branch from e58c6a5 to 5be88d8 Compare February 9, 2026 13:57
@Ao-chuba
Copy link
Author

Ao-chuba commented Feb 9, 2026

@tovrstra @FarnazH
To clarify the timeline for this PR as well:

  • Original Issue: This PR addresses horton3 integration by filtering negligible grid weights. However, the CI tests were failing due to the unrelated scipy import error in the grid dependency.
  • Intermediate Fix: I temporarily pinned scipy<1.15 and added a compatibility wrapper to bypass that dependency failure, allowing us to verify the horton3 changes.
  • Current State: Now that grid PR #291 has been merged upstream, the scipy issue is resolved.
  1. I have reverted the temporary scipy pinning and compatibility wrappers.
  2. The PR now contains only the intended changes: the fix for filtering negligible grid weights in src/denspart/adapters/horton3.py.

@Ao-chuba
Copy link
Author

@tovrstra @FarnazH , I’ve updated the PR. When you have some time, could you please review it? I’d really appreciate your feedback. Thank you !

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.

Optimization: Prune zero weight grid points in horton3 adapter

3 participants