Skip to content

Add option to disable saving in run_pyscf - #73

Open
Mounika-2604 wants to merge 2 commits into
quantumlib:mainfrom
Mounika-2604:fix-issue-56
Open

Mounika-2604 wants to merge 2 commits into
quantumlib:mainfrom
Mounika-2604:fix-issue-56

Conversation

@Mounika-2604

Copy link
Copy Markdown

Summary

Fixes #56.

This PR adds a save option to run_pyscf() to allow callers to disable
saving the calculated molecular data to disk.

Changes

  • Added save=True parameter to run_pyscf().
  • Updated the docstring to document the new parameter.
  • Saving is performed only when save=True.
  • Added a regression test verifying that saving can be disabled.

Testing

  • pytest openfermionpyscf/tests/_run_pyscf_test.py -v
  • Result: 2 passed, 1 warning

@Mounika-2604

Copy link
Copy Markdown
Author

Hi @mhucka , I’ve implemented the requested save option for run_pyscf(), keeping the default behavior unchanged. I also added a regression test for save=False, and all tests pass (2 passed, 1 warning). The changes are pushed to my fix-issue-56 branch.

@mhucka mhucka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this contribution. Some change requests follow.

Comment thread openfermionpyscf/_run_pyscf.py Outdated
verbose=False):
verbose=False,
save=True):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please delete the extra blank line.

Suggested change

Comment thread openfermionpyscf/_run_pyscf.py Outdated
Comment on lines 109 to 110
"""
This function runs a pyscf calculation.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first line of a docstring should start right after the triple quotes.

Suggested change
"""
This function runs a pyscf calculation.
"""This function runs a pyscf calculation.

save=False)

assert isinstance(new_mole, PyscfMolecularData)
assert not save_called No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure the file ends with a newline.

run_fci=True,
verbose=1)
assert isinstance(new_mole, PyscfMolecularData)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two blank lines between functions at the top level of a file.

Suggested change

Comment on lines +41 to +52
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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code looks like it was generated by an LLM. They are fond of using mocks and monkey patching, but it's usually unnecessary. In this particular case, MolecularData accepts a data_directory (or filename) in its constructor and saves to f"{self.filename}.hdf5". Using pytest's built-in tmp_path fixture (or tempfile.TemporaryDirectory), the test can be rewritten to check whether the .hdf5 file is actually created on disk rather than monkey-patching PyscfMolecularData.save.

@Mounika-2604

Copy link
Copy Markdown
Author

Thanks for the thorough review and helpful suggestions, @mhucka!

I have updated the PR to address all the feedback:

  • Removed the extra blank line and formatted the docstring so it starts immediately after the triple quotes.
  • Formatted the test file with PEP 8 spacing (two blank lines between top-level functions) and ensured it ends with a newline.
  • Rewrote test_run_pyscf_without_save using pytest's built-in tmp_path fixture instead of monkeypatching, explicitly asserting that the .hdf5 file is not created on disk when save=False (and is created when save=True).

Please let me know if any further adjustments are needed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optional disable file saving when run_pyscf

2 participants