From ca60afc1bc05763554e8deedc628feaca37f3ff8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mafalda=20Ram=C3=B4a?= <74077940+mafaldaramoa@users.noreply.github.com> Date: Mon, 7 Aug 2023 19:13:33 +0100 Subject: [PATCH] `freeze_orbitals` reflects the `prune` flag (#803) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- .../repconversions/operator_tapering.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/openfermion/transforms/repconversions/operator_tapering.py b/src/openfermion/transforms/repconversions/operator_tapering.py index 595b4b2dc..edda67102 100644 --- a/src/openfermion/transforms/repconversions/operator_tapering.py +++ b/src/openfermion/transforms/repconversions/operator_tapering.py @@ -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] @@ -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