Skip to content

Save diatomic example data to working directory - #75

Open
mhucka wants to merge 1 commit into
mainfrom
mh-fix-issue-64
Open

mhucka wants to merge 1 commit into
mainfrom
mh-fix-issue-64

Conversation

@mhucka

@mhucka mhucka commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #64.

When running examples/generate_diatomic.py, MolecularData instances were created without specifying data_directory. Consequently, MolecularData defaulted to openfermion.config.DATA_DIRECTORY (which points to testing/data inside the installed openfermion package). In read-only or system environments (e.g. /usr/local/lib/python3.X/site-packages), run_pyscf and molecule.save() raised PermissionError: [Errno 13] Permission denied.

Changes

  • In examples/generate_diatomic.py:
    • Set data_directory = os.getcwd() and pass it to both MolecularData(...) calls so output is written to the local working directory.
    • Remove redundant explicit molecule.save() calls since run_pyscf() already saves by default.
  • In openfermionpyscf/tests/_run_pyscf_test.py:
    • Add test_generate_diatomic() regression test to verify that examples/generate_diatomic.py executes and writes 32 .hdf5 files to the working directory even when DATA_DIRECTORY is unwritable (0o555).

Testing

  • Full test suite verified locally via pytest:
    pytest -v (6 passed in 19.91s).
  • Verified test failure with reproduction before fix:
    Temporarily omitting data_directory from generate_diatomic.py caused test_generate_diatomic to fail with PermissionError: [Errno 13] Permission denied.

Fixes #64.

In examples/generate_diatomic.py, MolecularData instances were created
without specifying data_directory, causing them to default to
openfermion.config.DATA_DIRECTORY (located within the installed
openfermion package). In read-only or system installations, running the
example raised PermissionError when run_pyscf and molecule.save()
attempted to write HDF5 data into the package directory.

This change:
- Sets data_directory = os.getcwd() in examples/generate_diatomic.py and
  passes it to MolecularData calls so output is written to the working
  directory.
- Removes redundant explicit molecule.save() calls since run_pyscf saves
  by default.
- Adds an integration test in openfermionpyscf/tests/_run_pyscf_test.py
  verifying generate_diatomic.py runs and saves files to the working
  directory even when DATA_DIRECTORY is read-only.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant