From 12a2f7e9b48010a8d7b02c7bc9795d79e4e65856 Mon Sep 17 00:00:00 2001 From: mounika-2604 Date: Mon, 5 Oct 2026 00:57:13 +0530 Subject: [PATCH 1/2] Add option to disable saving in run_pyscf --- openfermionpyscf/_run_pyscf.py | 8 ++++++-- openfermionpyscf/tests/_run_pyscf_test.py | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/openfermionpyscf/_run_pyscf.py b/openfermionpyscf/_run_pyscf.py index b374b2c..4d65f8e 100644 --- a/openfermionpyscf/_run_pyscf.py +++ b/openfermionpyscf/_run_pyscf.py @@ -103,7 +103,9 @@ def run_pyscf(molecule, run_cisd=False, run_ccsd=False, run_fci=False, - verbose=False): + verbose=False, + save=True): + """ This function runs a pyscf calculation. @@ -115,6 +117,7 @@ def run_pyscf(molecule, run_ccsd: Optional boolean to run CCSD calculation. run_fci: Optional boolean to FCI calculation. verbose: Boolean whether to print calculation results to screen. + save: Boolean whether to save the calculated molecular data to disk. Returns: molecule: The updated PyscfMolecularData object. Note the attributes @@ -202,7 +205,8 @@ def run_pyscf(molecule, # Return updated molecule instance. pyscf_molecular_data = PyscfMolecularData.__new__(PyscfMolecularData) pyscf_molecular_data.__dict__.update(molecule.__dict__) - pyscf_molecular_data.save() + if save: + pyscf_molecular_data.save() return pyscf_molecular_data diff --git a/openfermionpyscf/tests/_run_pyscf_test.py b/openfermionpyscf/tests/_run_pyscf_test.py index 3481d23..43e966f 100644 --- a/openfermionpyscf/tests/_run_pyscf_test.py +++ b/openfermionpyscf/tests/_run_pyscf_test.py @@ -37,3 +37,18 @@ def test_run_pyscf(): run_fci=True, verbose=1) assert isinstance(new_mole, PyscfMolecularData) + +def test_run_pyscf_without_save(monkeypatch): + save_called = [] + + def mock_save(self): + save_called.append(True) + + monkeypatch.setattr(PyscfMolecularData, 'save', mock_save) + + new_mole = run_pyscf(molecule, + run_scf=True, + save=False) + + assert isinstance(new_mole, PyscfMolecularData) + assert not save_called \ No newline at end of file From 3c5a579f23aee138e8e33340dd355e0e25df97b5 Mon Sep 17 00:00:00 2001 From: mounika-2604 Date: Fri, 9 Oct 2026 12:19:01 +0530 Subject: [PATCH 2/2] Fix issue 56: resolve PySCF calculation issue --- openfermionpyscf/_run_pyscf.py | 4 +--- openfermionpyscf/tests/_run_pyscf_test.py | 24 ++++++++++++++--------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/openfermionpyscf/_run_pyscf.py b/openfermionpyscf/_run_pyscf.py index 4d65f8e..997e545 100644 --- a/openfermionpyscf/_run_pyscf.py +++ b/openfermionpyscf/_run_pyscf.py @@ -105,9 +105,7 @@ def run_pyscf(molecule, run_fci=False, verbose=False, save=True): - - """ - This function runs a pyscf calculation. + """This function runs a pyscf calculation. Args: molecule: An instance of the MolecularData or PyscfMolecularData class. diff --git a/openfermionpyscf/tests/_run_pyscf_test.py b/openfermionpyscf/tests/_run_pyscf_test.py index 43e966f..a7083a7 100644 --- a/openfermionpyscf/tests/_run_pyscf_test.py +++ b/openfermionpyscf/tests/_run_pyscf_test.py @@ -13,6 +13,8 @@ """Tests many modules to call pyscf functions.""" from __future__ import absolute_import +import os + from openfermion.chem import MolecularData from openfermionpyscf import run_pyscf from openfermionpyscf import PyscfMolecularData @@ -38,17 +40,21 @@ def test_run_pyscf(): verbose=1) assert isinstance(new_mole, PyscfMolecularData) -def test_run_pyscf_without_save(monkeypatch): - save_called = [] - - def mock_save(self): - save_called.append(True) - monkeypatch.setattr(PyscfMolecularData, 'save', mock_save) +def test_run_pyscf_without_save(tmp_path): + test_molecule = MolecularData(geometry, + basis, + multiplicity, + charge, + data_directory=str(tmp_path)) - new_mole = run_pyscf(molecule, + new_mole = run_pyscf(test_molecule, run_scf=True, save=False) - assert isinstance(new_mole, PyscfMolecularData) - assert not save_called \ No newline at end of file + assert not os.path.exists(f'{new_mole.filename}.hdf5') + + new_mole_saved = run_pyscf(test_molecule, + run_scf=True) + assert isinstance(new_mole_saved, PyscfMolecularData) + assert os.path.exists(f'{new_mole_saved.filename}.hdf5')