Skip to content

Conversation

mhucka
Copy link
Contributor

@mhucka mhucka commented Aug 25, 2025

The nightly test runs would often fail at least one test that fetched data from a Pubchem network service. The failures happened because sometimes the remote server would respond with an error (probably because it's getting hit with too many requests). The problem was reported years ago in issue #481.

This PR should address this problem. I added a simple retry mechanism to the function geometry_from_pubchem() in the file src/openfermion/chem/pubchem.py. It now catches exceptions and retries the network call up to three times with a delay between each attempt. I also updated the corresponding tests in src/openfermion/chem/pubchem_test.py to mock the network calls and verify the new retry logic.

I added a retry mechanism to the function `geometry_from_pubchem()` in
the file `src/openfermion/chem/pubchem.py`. It now catches exceptions
and reries network call up to three times with a five-second delay
between each attempt. I also updated the corresponding tests in
`src/openfermion/chem/pubchem_test.py` to mock the network calls and
verify the new retry logic.
@mhucka mhucka added announcement An important announcement area/health Involves code and/or project health and removed announcement An important announcement labels Aug 25, 2025
mhucka added 4 commits August 25, 2025 11:56
When adding a new term to a `SymbolicOperator` with a sympy coefficient,
the coefficient was being cast to a float. This was because the default
value for a new term was `0.0`, which is a float. This commit changes
the default value to `0`, which is an integer. This ensures that the
type of the coefficient is preserved when adding new terms.
This should address the code coverage failure in the CI checks.
@mhucka mhucka marked this pull request as ready for review August 28, 2025 04:01
Copy link
Contributor

@pavoljuhas pavoljuhas left a comment

Choose a reason for hiding this comment

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

Please do not add hard-coded retries to geometry_from_pubchem.
We cannot presume users would always want to retry the pubchempy.get_compounds call.
They may want it to fail quickly and handle the failure in their own way. As it is, they'd be getting an extra 10 second delay before the function finally throws.

If the goal here is to avoid server related flakes in pubchem_test, a better option is to define a mock pubchempy.get_compounds function, which returns hard-coded results for the molecules used in the test. The tests can then run with mocked get_compounds.

If you'd like to also have a test with an actual pubchempy.get_compounds call, the place to add retries is in that test rather than in geometry_from_pubchem.

@mhucka mhucka force-pushed the master branch 2 times, most recently from 68c920e to 5fcc1d8 Compare September 1, 2025 02:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/health Involves code and/or project health
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants