From 08835ece4fbc08b0c3d30a664ea0d99c49f95c68 Mon Sep 17 00:00:00 2001 From: Michael Hucka Date: Mon, 2 Jun 2025 14:17:53 -0700 Subject: [PATCH 1/2] Set a fixed random seed during testing Some of the tests became more flaky with the move to NumPy 2. In all cases, random numbers were involved at some point. Setting a fixed random seed made the tests reproducible and (so far) seems to have stopped the flakiness. --- src/openfermion/conftest.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/openfermion/conftest.py b/src/openfermion/conftest.py index 0a91e8ed3..4ad82d5d9 100644 --- a/src/openfermion/conftest.py +++ b/src/openfermion/conftest.py @@ -9,9 +9,20 @@ # 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 os +import pytest +import numpy as np +import random def pytest_configure(config): # fail tests when using deprecated cirq functionality os.environ['CIRQ_TESTING'] = "true" + + +@pytest.fixture(autouse=True) +def set_random_seed(): + """Set a fixed random seed when testing.""" + random.seed(0) + np.random.seed(0) From 8bae13f2f560c96e3bff978606843c228f460b96 Mon Sep 17 00:00:00 2001 From: Michael Hucka Date: Mon, 2 Jun 2025 14:52:52 -0700 Subject: [PATCH 2/2] Fix pylint warning about order of imports --- src/openfermion/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openfermion/conftest.py b/src/openfermion/conftest.py index 4ad82d5d9..ac3ed7d30 100644 --- a/src/openfermion/conftest.py +++ b/src/openfermion/conftest.py @@ -11,9 +11,9 @@ # limitations under the License. import os +import random import pytest import numpy as np -import random def pytest_configure(config):