Skip to content

Commit

Permalink
freeze_orbitals reflects the prune flag (#803)
Browse files Browse the repository at this point in the history
* Update operator_tapering.py

Make the call to prune_unused_indices in freeze_orbitals conditional on the 'prune' kwarg

* Update operator_tapering.py

Updated description for freeze_orbitals

* Update operator_tapering.py

remove trailing whitespace

---------

Co-authored-by: Mafalda Ramôa Alves <[email protected]>
Co-authored-by: Matthew Harrigan <[email protected]>
  • Loading branch information
3 people authored Aug 7, 2023
1 parent f1dfe9d commit ca60afc
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/openfermion/transforms/repconversions/operator_tapering.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@
def freeze_orbitals(fermion_operator, occupied, unoccupied=None, prune=True):
"""Fix some orbitals to be occupied and others unoccupied.
Removes all operators acting on the specified orbitals, and renumbers the
remaining orbitals to eliminate unused indices. The sign of each term
is modified according to the ladder uperator anti-commutation relations in
order to preserve the expectation value of the operator.
Removes all operators acting on the specified orbitals, and optionally
renumbers the remaining orbitals to eliminate unused indices. The sign of
each term is modified according to the ladder operator anti-commutation
relations in order to preserve the expectation value of the operator.
Args:
occupied: A list containing the indices of the orbitals that are to be
assumed to be occupied.
unoccupied: A list containing the indices of the orbitals that are to
be assumed to be unoccupied.
prune: A flag that determines whether the orbitals will be renumbered to
eliminate unused indices.
"""
new_operator = fermion_operator
frozen = [(index, 1) for index in occupied]
Expand Down Expand Up @@ -81,8 +83,9 @@ def freeze_orbitals(fermion_operator, occupied, unoccupied=None, prune=True):
if op[0] > index:
new_operator.terms[term] *= -1

# Renumber indices to remove frozen orbitals
new_operator = prune_unused_indices(new_operator)
if prune:
# Renumber indices to remove frozen orbitals
new_operator = prune_unused_indices(new_operator)

return new_operator

Expand Down

0 comments on commit ca60afc

Please sign in to comment.