From 731fb31dc266b76e4f6f9ff7a9335507713d60a8 Mon Sep 17 00:00:00 2001 From: mhucka Date: Tue, 28 Apr 2026 00:35:37 +0000 Subject: [PATCH 1/5] Mark more tests as slow Some of the tests are extremely time-consuming on even a fast parallel Linux VM. The two tests marked in this commit clocked in at **20 minutes** each. The following numbers are from using the pytest `--durations` option: 1288.49s call src/openfermion/ops/representations/doci_hamiltonian_test.py::IntegralTransformsTest::test_fermionic_hamiltonian_from_integrals 1208.20s call src/openfermion/transforms/opconversions/remove_symmetry_qubits_test.py::ReduceSymmetryQubitsTest::test_energy_reduce_symmetry_qubits --- .../ops/representations/doci_hamiltonian_test.py | 15 ++++++++------- .../opconversions/remove_symmetry_qubits_test.py | 10 ++++++---- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/openfermion/ops/representations/doci_hamiltonian_test.py b/src/openfermion/ops/representations/doci_hamiltonian_test.py index 86cdb0de3..b80ab2d58 100644 --- a/src/openfermion/ops/representations/doci_hamiltonian_test.py +++ b/src/openfermion/ops/representations/doci_hamiltonian_test.py @@ -11,24 +11,24 @@ # limitations under the License. """Tests for doci_hamiltonian.py.""" -import sys import os +import sys import unittest import numpy +import pytest -from openfermion.config import EQ_TOLERANCE +from openfermion import InteractionOperator, get_fermion_operator, normal_ordered from openfermion.chem.molecular_data import MolecularData -from openfermion.config import DATA_DIRECTORY -from openfermion.transforms import jordan_wigner +from openfermion.config import DATA_DIRECTORY, EQ_TOLERANCE from openfermion.linalg import get_sparse_operator from openfermion.ops.representations.doci_hamiltonian import ( DOCIHamiltonian, - get_tensors_from_doci, - get_projected_integrals_from_doci, get_doci_from_integrals, + get_projected_integrals_from_doci, + get_tensors_from_doci, ) -from openfermion import get_fermion_operator, InteractionOperator, normal_ordered +from openfermion.transforms import jordan_wigner numpy.set_printoptions(linewidth=2000, threshold=sys.maxsize) @@ -55,6 +55,7 @@ def test_integrals_self_inverse(self): self.assertTrue(numpy.allclose(hr1, hr1_test)) self.assertTrue(numpy.allclose(hr2, hr2_test)) + @pytest.mark.slow def test_fermionic_hamiltonian_from_integrals(self): constant = self.molecule.nuclear_repulsion doci_constant = constant diff --git a/src/openfermion/transforms/opconversions/remove_symmetry_qubits_test.py b/src/openfermion/transforms/opconversions/remove_symmetry_qubits_test.py index 95ed7b3cb..461a6fde3 100644 --- a/src/openfermion/transforms/opconversions/remove_symmetry_qubits_test.py +++ b/src/openfermion/transforms/opconversions/remove_symmetry_qubits_test.py @@ -16,16 +16,17 @@ import unittest -from openfermion.hamiltonians import fermi_hubbard +import pytest + from openfermion.chem import MolecularData -from openfermion.transforms.opconversions import get_fermion_operator +from openfermion.hamiltonians import fermi_hubbard +from openfermion.linalg import eigenspectrum from openfermion.linalg.sparse_tools import ( get_sparse_operator, jw_get_ground_state_at_particle_number, ) -from openfermion.linalg import eigenspectrum from openfermion.ops.operators import FermionOperator - +from openfermion.transforms.opconversions import get_fermion_operator from openfermion.transforms.opconversions.remove_symmetry_qubits import ( symmetry_conserving_bravyi_kitaev, ) @@ -83,6 +84,7 @@ def number_of_qubits(qubit_hamiltonian, unreduced_orbitals): class ReduceSymmetryQubitsTest(unittest.TestCase): # Check whether fermionic and reduced qubit Hamiltonians # have the same energy for LiH + @pytest.mark.slow def test_energy_reduce_symmetry_qubits(self): # Generate the fermionic Hamiltonians, # number of orbitals and number of electrons. From a91b45e66bbab2f5cacb1172931561c5928d8f80 Mon Sep 17 00:00:00 2001 From: mhucka Date: Tue, 28 Apr 2026 00:44:09 +0000 Subject: [PATCH 2/5] Undo some changes introduced by isort We don't run isort in check/format-incremental. I didn't need to run it manually in the previous commit. --- .../ops/representations/doci_hamiltonian_test.py | 9 ++++----- .../opconversions/remove_symmetry_qubits_test.py | 7 ++++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/openfermion/ops/representations/doci_hamiltonian_test.py b/src/openfermion/ops/representations/doci_hamiltonian_test.py index b80ab2d58..553764bb3 100644 --- a/src/openfermion/ops/representations/doci_hamiltonian_test.py +++ b/src/openfermion/ops/representations/doci_hamiltonian_test.py @@ -18,17 +18,16 @@ import numpy import pytest -from openfermion import InteractionOperator, get_fermion_operator, normal_ordered +from openfermion.config import EQ_TOLERANCE from openfermion.chem.molecular_data import MolecularData -from openfermion.config import DATA_DIRECTORY, EQ_TOLERANCE +from openfermion.config import DATA_DIRECTORY +from openfermion.transforms import jordan_wigner from openfermion.linalg import get_sparse_operator from openfermion.ops.representations.doci_hamiltonian import ( DOCIHamiltonian, get_doci_from_integrals, - get_projected_integrals_from_doci, - get_tensors_from_doci, ) -from openfermion.transforms import jordan_wigner +from openfermion import get_fermion_operator, InteractionOperator numpy.set_printoptions(linewidth=2000, threshold=sys.maxsize) diff --git a/src/openfermion/transforms/opconversions/remove_symmetry_qubits_test.py b/src/openfermion/transforms/opconversions/remove_symmetry_qubits_test.py index 461a6fde3..98c7bf1bd 100644 --- a/src/openfermion/transforms/opconversions/remove_symmetry_qubits_test.py +++ b/src/openfermion/transforms/opconversions/remove_symmetry_qubits_test.py @@ -18,15 +18,16 @@ import pytest -from openfermion.chem import MolecularData from openfermion.hamiltonians import fermi_hubbard -from openfermion.linalg import eigenspectrum +from openfermion.chem import MolecularData +from openfermion.transforms.opconversions import get_fermion_operator from openfermion.linalg.sparse_tools import ( get_sparse_operator, jw_get_ground_state_at_particle_number, ) +from openfermion.linalg import eigenspectrum from openfermion.ops.operators import FermionOperator -from openfermion.transforms.opconversions import get_fermion_operator + from openfermion.transforms.opconversions.remove_symmetry_qubits import ( symmetry_conserving_bravyi_kitaev, ) From 0f91507ce9f9512ab69acf2349b149bb1aa465a6 Mon Sep 17 00:00:00 2001 From: mhucka Date: Tue, 28 Apr 2026 00:45:16 +0000 Subject: [PATCH 3/5] Undo another change caused by isort --- src/openfermion/ops/representations/doci_hamiltonian_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openfermion/ops/representations/doci_hamiltonian_test.py b/src/openfermion/ops/representations/doci_hamiltonian_test.py index 553764bb3..70fa603b3 100644 --- a/src/openfermion/ops/representations/doci_hamiltonian_test.py +++ b/src/openfermion/ops/representations/doci_hamiltonian_test.py @@ -11,8 +11,8 @@ # limitations under the License. """Tests for doci_hamiltonian.py.""" -import os import sys +import os import unittest import numpy From 5708ab4330d10ccfb08321cff73af519684bb01e Mon Sep 17 00:00:00 2001 From: mhucka Date: Tue, 28 Apr 2026 00:48:52 +0000 Subject: [PATCH 4/5] Mark another slow test --- .../resource_estimates/pbc/thc/factorizations/isdf_test.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/openfermion/resource_estimates/pbc/thc/factorizations/isdf_test.py b/src/openfermion/resource_estimates/pbc/thc/factorizations/isdf_test.py index 47706baf8..ddaa3e517 100644 --- a/src/openfermion/resource_estimates/pbc/thc/factorizations/isdf_test.py +++ b/src/openfermion/resource_estimates/pbc/thc/factorizations/isdf_test.py @@ -10,6 +10,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import numpy as np import pytest @@ -252,6 +253,7 @@ def test_G_vector_mapping_single_translation(): assert np.allclose(delta_G_expected, delta_G) +@pytest.mark.slow @pytest.mark.skipif(not HAVE_DEPS_FOR_RESOURCE_ESTIMATES, reason='pyscf and/or jax not installed.') def test_kpoint_isdf_double_translation(): cell = gto.Cell() From cefb5295acc7cb72d633aa42679da5b65fa648a3 Mon Sep 17 00:00:00 2001 From: mhucka Date: Tue, 28 Apr 2026 02:27:18 +0000 Subject: [PATCH 5/5] Mark another test --- .../resource_estimates/pbc/thc/factorizations/isdf_test.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/openfermion/resource_estimates/pbc/thc/factorizations/isdf_test.py b/src/openfermion/resource_estimates/pbc/thc/factorizations/isdf_test.py index ddaa3e517..1b0e02905 100644 --- a/src/openfermion/resource_estimates/pbc/thc/factorizations/isdf_test.py +++ b/src/openfermion/resource_estimates/pbc/thc/factorizations/isdf_test.py @@ -253,8 +253,8 @@ def test_G_vector_mapping_single_translation(): assert np.allclose(delta_G_expected, delta_G) -@pytest.mark.slow @pytest.mark.skipif(not HAVE_DEPS_FOR_RESOURCE_ESTIMATES, reason='pyscf and/or jax not installed.') +@pytest.mark.slow def test_kpoint_isdf_double_translation(): cell = gto.Cell() cell.atom = """ @@ -302,6 +302,7 @@ def test_kpoint_isdf_double_translation(): @pytest.mark.skipif(not HAVE_DEPS_FOR_RESOURCE_ESTIMATES, reason='pyscf and/or jax not installed.') +@pytest.mark.slow def test_kpoint_isdf_single_translation(): cell = gto.Cell() cell.atom = """