Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

freeze_orbitals reflects the prune flag #803

Merged
merged 5 commits into from
Aug 7, 2023
Merged
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
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