Skip to content

Commit ca60afc

Browse files
freeze_orbitals reflects the prune flag (#803)
* 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 <74077940+MafaldaRA@users.noreply.github.com> Co-authored-by: Matthew Harrigan <mpharrigan@google.com>
1 parent f1dfe9d commit ca60afc

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

src/openfermion/transforms/repconversions/operator_tapering.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,18 @@
2121
def freeze_orbitals(fermion_operator, occupied, unoccupied=None, prune=True):
2222
"""Fix some orbitals to be occupied and others unoccupied.
2323
24-
Removes all operators acting on the specified orbitals, and renumbers the
25-
remaining orbitals to eliminate unused indices. The sign of each term
26-
is modified according to the ladder uperator anti-commutation relations in
27-
order to preserve the expectation value of the operator.
24+
Removes all operators acting on the specified orbitals, and optionally
25+
renumbers the remaining orbitals to eliminate unused indices. The sign of
26+
each term is modified according to the ladder operator anti-commutation
27+
relations in order to preserve the expectation value of the operator.
2828
2929
Args:
3030
occupied: A list containing the indices of the orbitals that are to be
3131
assumed to be occupied.
3232
unoccupied: A list containing the indices of the orbitals that are to
3333
be assumed to be unoccupied.
34+
prune: A flag that determines whether the orbitals will be renumbered to
35+
eliminate unused indices.
3436
"""
3537
new_operator = fermion_operator
3638
frozen = [(index, 1) for index in occupied]
@@ -81,8 +83,9 @@ def freeze_orbitals(fermion_operator, occupied, unoccupied=None, prune=True):
8183
if op[0] > index:
8284
new_operator.terms[term] *= -1
8385

84-
# Renumber indices to remove frozen orbitals
85-
new_operator = prune_unused_indices(new_operator)
86+
if prune:
87+
# Renumber indices to remove frozen orbitals
88+
new_operator = prune_unused_indices(new_operator)
8689

8790
return new_operator
8891

0 commit comments

Comments
 (0)