Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/openfermion/chem/reduced_hamiltonian.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from itertools import product
import numpy
from openfermion.ops.representations import InteractionOperator
Expand All @@ -6,6 +6,10 @@
def make_reduced_hamiltonian(
molecular_hamiltonian: InteractionOperator, n_electrons: int
) -> InteractionOperator:
if n_electrons < 2:
raise ValueError(
'n_electrons must be at least 2 to avoid division by zero.'
)
Comment on lines +9 to +12

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.

high

In Python, a function's docstring must be the very first statement in the function body. Placing the if n_electrons < 2: validation check before the docstring prevents Python from recognizing it as a docstring, which breaks documentation generation and tools. Please move this validation block to be after the docstring (after line 39).

r"""
Construct the reduced Hamiltonian.

Expand Down
4 changes: 4 additions & 0 deletions src/openfermion/linalg/rdm_reconstruction.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import numpy as np
from openfermion.linalg.wedge_product import wedge

Expand All @@ -16,6 +16,10 @@
Returns:
six-tensor reprsenting the three-RDM
"""
if n_electrons < 2:
raise ValueError(
'n_electrons must be at least 2 to avoid division by zero.'
)
opdm = (2 / (n_electrons - 1)) * np.einsum('ijjk', tpdm)
unconnected_tpdm = wedge(opdm, opdm, (1, 1), (1, 1))
unconnected_d3 = wedge(opdm, unconnected_tpdm, (1, 1), (2, 2))
Expand Down
Loading