Implement coefficient thresholding in Hamiltonian generation - #69
Implement coefficient thresholding in Hamiltonian generation#69AlbertLee125 wants to merge 21 commits into
Conversation
- Introduced `hamiltonian.coefficient_threshold` to control the absolute cutoff for spin-orbital and final Pauli coefficients. - Updated relevant functions to utilize the new threshold setting, allowing for disabling magnitude-based pruning. - Documented changes in README and added a detailed hotfix explanation in THRESHOLDING_HOTFIX.md.
- Introduced `coefficient_threshold` in configuration with a default of 1e-8. - Updated README to document the coefficient cutoff behavior. - Modified `hamgen.py` to apply the coefficient threshold during Hamiltonian construction. - Enhanced metadata logging to include threshold statistics.
There was a problem hiding this comment.
Pull request overview
Introduces a configurable absolute coefficient cutoff for Hamiltonian generation, so users can reproduce historical OpenFermion-style pruning (default 1e-8) or disable magnitude-based pruning (0.0) while preserving provenance in outputs and cache behavior.
Changes:
- Added a local thresholding implementation for (1) spatial→spin-orbital tensor expansion and (2) JW/BK mapping that applies cutoff only after Pauli-term aggregation.
- Plumbed
hamiltonian.coefficient_thresholdthrough configuration, active-space building, cache validation, metadata, and tensor.npzoutputs. - Documented behavior, caveats, and cache implications in
README.mdandTHRESHOLDING_HOTFIX.md.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| hamiltonian_generator/thresholding.py | Implements threshold validation, tensor thresholding, and mapping that defers cutoff until after Pauli aggregation. |
| hamiltonian_generator/THRESHOLDING_HOTFIX.md | Hotfix write-up explaining motivation, cache behavior, and validation notes. |
| hamiltonian_generator/README.md | Documents the new hamiltonian.coefficient_threshold setting and its semantics. |
| hamiltonian_generator/hamgen.py | Uses the new thresholding path, records provenance, and enforces cache compatibility. |
| hamiltonian_generator/hamgen_types.py | Exposes and validates coefficient_threshold in the configuration object. |
| hamiltonian_generator/config.py | Adds the example configuration knob for the coefficient threshold. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
After reviewing the current implementation, I am concerned that this hotfix changes too much of The current PR combines several changes:
I think it would be safer to restore My proposed first step is:
There is still an important question about OpenFermion applying another effective cutoff while constructing the final Pauli Hamiltonian. I think that issue should be tested and discussed separately rather than replacing the entire mapping path as part of the initial hotfix. This would make the first change easier to review, reduce the risk of changing existing behavior, and clearly separate the tensor-threshold issue from the later Pauli-mapping issue. |
|
The PR has been narrowed to configurable thresholding during spatial-to-spin-orbital tensor construction. The original JW/BK mapping, cache workflow, and I updated the PR description, resolved the Copilot review threads, completed the Li₂ regression checks for the historical behavior, explicit |
AlbertLee125
left a comment
There was a problem hiding this comment.
Blocking issues
- Threshold-independent active-space caching can produce tensors under one cutoff while metadata reports another.
- No committed test or CI path exercises the new converter or its cache interaction.
Nonblocking issues
- Clarify units, strict boundary behavior, and the exact active-space cache filename in the README.
- Consider exposing the setting through
build_config.pyandbuild_config_L_sweep.py, since bond-length sweeps are the motivating workflow.
Questions
- Is this intended as only the tensor-construction portion of Issue #31? For Li₂,
1e-8and0.0produce different tensors but identical final JW/BK operators (156 terms), so Issue #31’s final Hamiltonian term-count question remains open.
Tests run and outcomes
git diff --check main...Threshold: passed.- Hamiltonian-generator smoke command: passed after using the checkout on
PYTHONPATH; it loaded the tracked active-space cache and did not exercise the changed path. - Targeted threshold parity, zero, boundary, and validation checks: passed.
- Cache-provenance reproduction: failed the expected invariant (requested
0.0, historical14/436cached tensors, metadata0.0). pytest hamiltonian_generator: 2 unrelated tests passed.pytest common/tests: 190 passed.pytest analysis/tests: 270 passed.- GitHub Actions is green, but the hamgen job bypasses the new converter through the tracked cache.
Merge verdict
No. I would not merge this until the blocking issues above are addressed.
|
Pushed commits
Main changes
Tests run
Comments intentionally not addressed
Remaining risks
|
|
Following the feedback to include thresholding at the qubit-operator stage, I added a second coefficient threshold on top of the existing configurable spin-orbital tensor threshold. The two thresholds now apply at different stages:
The Pauli-string threshold is intentionally kept internal and non-configurable for this baseline implementation. Making it configurable can be considered in a follow-up change. The applied Pauli-string threshold is also recorded in the generated |
AlbertLee125
left a comment
There was a problem hiding this comment.
Blocking issues
- The newly added fixed post-mapping cutoff changes final JW/BK Hamiltonians independently of the documented configuration and contradicts the stated tensor-only scope.
Nonblocking issues
- The ground-energy comparison script is not reproducible as committed because all inputs are hard-coded and the required archives are untracked.
Questions
None.
Tests run and outcomes
PYTHONPATH=.. python -m pytest hamiltonian_generator/tests/test_thresholding.py -v: 17 passed.git diff --check upstream/main...HEAD: passed.- Latest GitHub Actions checks: all reported checks passed, including hamgen, hamgen unit tests, common unit tests, and analysis unit tests.
- Broader local
pytestcollection forhamiltonian_generator/tests common/tests analysis/tests: could not run to completion because this environment lacksqualtran,pyLIQTR, andnumba; collection stopped with 13 import errors. The targeted changed-code suite completed successfully. - Initial root-level targeted invocation without
PYTHONPATH: could not importqhatbecause the checkout is not installed in the active environment; rerunning against the checkout viaPYTHONPATH=..passed.
Merge verdict
No. I would not merge this until the blocking issues above are addressed.
GitHub does not permit the PR author to submit REQUEST_CHANGES, so this is submitted as COMMENT.
|
Pushed commit
Main changes
Tests run
Comments intentionally not addressed
Remaining risks and follow-up items
|
|
@reuben-tate, could you please review this PR when you have a chance? The latest review feedback has been addressed, the intended tensor- and Pauli-stage threshold behavior is documented, and the targeted Hamiltonian-generator test suite passes. I believe it is ready for review. |
|
We decided to remove the additional fixed Pauli-string threshold from this PR. The configurable tensor threshold directly addresses the original issue at the spin-orbital tensor-construction stage. Applying the same A fixed QHAT post-mapping cutoff could therefore silently discard valid mapped terms and could not be disabled when users request a zero tensor threshold. If Pauli-level truncation is useful, it should be introduced separately as an explicit, configurable QHAT feature with clearly defined behavior and error implications. |
Summary
Adds configurable coefficient filtering while expanding active-space spatial integrals into spin-orbital tensors. This addresses the tensor-stage threshold identified in #31 while retaining the historical
1e-8default and allowing0.0at that stage.Threshold behavior
hamiltonian.coefficient_thresholdcontrols tensor construction, defaults to1e-8Hartree, and accepts finite non-negative values.0.0disables magnitude filtering during tensor construction.1e-8Hartree cutoff to final Pauli-string coefficients. This second cutoff is not currently configurable..datmetadata.Cache compatibility
Active-space pickles record the tensor threshold. QHAT rejects a cache whose stored threshold differs from the requested value; legacy caches are interpreted as using the historical
1e-8cutoff. The.tensors.npzformat remains unchanged.Tests
Regression coverage verifies validation, OpenFermion default parity, zero-threshold tensor behavior, strict cutoff boundaries, active-space construction, cache compatibility, JW/BK Pauli filtering, and threshold metadata.