Skip to content

Fix planewave based jellium model#1354

Open
arettig wants to merge 5 commits into
quantumlib:mainfrom
arettig:jellium_pw
Open

Fix planewave based jellium model#1354
arettig wants to merge 5 commits into
quantumlib:mainfrom
arettig:jellium_pw

Conversation

@arettig

@arettig arettig commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

This fixes #808, accounting for the 2 issues raised there:

  1. The planewave basis set is truncated inconsistently. The planewave basis set is truncated based on Ecut as expected for the kinetic term, but in the electron-electron repulsion, only the momentum change q = G1 - G2 is truncated, allowing terms arising from planewaves that should be excluded from the basis. This has been corrected by truncating consistently with the kinetic term.
  2. The coulomb operator was hardcoded for 3-dimensional systems but allowed calculations with other numbers of dimensions (and in fact was tested on 1-dimensional systems). The coulomb kernel was generalized to allow for 1 and 2 dimensional systems as well (using a soft coulomb potential for 1D), and will crash if not using 1-3 dimensions. The reference values for several tests that utilized 1-dimensional hamiltonians were adjusted.

arettig added 2 commits June 9, 2026 20:48
The coulomb operator for jellium was hardcorded to the 3d case
for planewaves: \sim 1/G^2, which gives incorrect results for
3d systems. The correct coulomb operator is now selected based
on the dimensionality of the system.
The planewave basis set when used with an Ecut was truncated for
the kinetic operator in the Hamiltonian, while the nuclear-electronic
term was not truncated, and the electron-electron repulsion term
was truncated incorrectly. Vee and Ven have been changed to match
the kinetic planewave truncation.
@arettig arettig requested a review from mhucka June 9, 2026 21:22

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces a generalized coulomb_potential_momentum function to compute the momentum-space Coulomb potential across 1D, 2D, and 3D systems, integrating it into various Jellium and plane-wave Hamiltonian models. It also adds support for filtering plane-wave operators within an energy cutoff. Feedback on the changes points out a performance bottleneck in the newly added filter_plane_wave_operator function, where repeated calculations and incremental additions to FermionOperator result in $O(N^2)$ complexity, and suggests an $O(N)$ optimization using precomputed valid modes and bulk initialization.

Comment thread src/openfermion/hamiltonians/plane_wave_hamiltonian.py Outdated
arettig and others added 2 commits June 9, 2026 15:04
The reduces the computational cost of filtering out high energy planewaves from an operator.

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
A nonexistent constructor was used when truncating the planewave
basis of a FermionOperator.

@mhucka mhucka left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you for doing this!

I have some comments about some possible slightly optimizations, but they might be better off left to another PR.

The only other thing is a request for formatting the formula in one of the docstrings. Other than that, it looks good!

"""
if momenta_squared == 0:
return 0.0
q = numpy.sqrt(momenta_squared)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Since momenta_squared is a Python float, if the value is a non-negative scalar, it should be possible to use Python's regular math.sqrt; this would be slightly faster as it will avoid some overhead in NumPy's version.

If this is changed to a math.sqrt, it also would be better to test that the value of momenta_squared is non-negative before taking the square root. The rest of this function tests other values and uses an else to deal with everything else, but it will be too late by then.

Finally, I see that the original code in this file used numpy functions and constants instead of Python math versions. I'm not sure if there was a reason for that – it might be a historical hold-over from pre-Python 3 days, or something else. If only the new code in this PR is changed to use the math versions, then that would be a bit inconsistent. So, an option might be to leave everything in this PR as you have it now (using numpy things), and leave the type changes to a different PR.

return 0.0
q = numpy.sqrt(momenta_squared)
if dimension == 3:
return 2.0 * numpy.pi / (volume * momenta_squared)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Similar as above, it should be possible to use Python's regular math.pi here; this would be slightly faster as it will avoid some overhead in NumPy's version.

if dimension == 3:
return 2.0 * numpy.pi / (volume * momenta_squared)
elif dimension == 2:
return numpy.pi / (volume * q)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ditto for the numpy.pi here.

"""Return the momentum space Coulomb potential for a given dimension.

For 1d systems, a soft coulomb potential is used with a regularization
parameter of a_1d: v(r) = 1/sqrt(r^2 + a_1d^2)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We should probably format this equation using LaTeX notation. This will render better when the docstrings are processed for the web documentation pages.

) -> float:
"""Return the momentum space Coulomb potential for a given dimension.

For 1d systems, a soft coulomb potential is used with a regularization

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit:

Suggested change
For 1d systems, a soft coulomb potential is used with a regularization
For 1-D systems, a soft coulomb potential is used with a regularization

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.

Is the Jellium model Hamiltonian incorrect?

2 participants