diff --git a/recirq/qcqmc/hamiltonian_test.py b/recirq/qcqmc/hamiltonian_test.py index 128bf5a3..498e34cf 100644 --- a/recirq/qcqmc/hamiltonian_test.py +++ b/recirq/qcqmc/hamiltonian_test.py @@ -15,7 +15,6 @@ import cirq import numpy as np import pytest -import sys from openfermion import ( get_fermion_operator, get_ground_state, @@ -114,17 +113,17 @@ def test_pyscf_h4_consistent_with_file(): pyscf_hamiltonian.e_core, from_file_hamiltonian.e_core, decimal=10 ) - # The call to scf.RHF() in build_hamiltonian_from_pyscf() produces - # a different-enough numerical result in NumPy 2 on MacOS that this - # test fails. https://github.com/quantumlib/ReCirq/issues/396 - # TODO: remove this try-except wrapper once that problem is resolved. + # The call to scf.RHF() in build_hamiltonian_from_pyscf() can converge to + # either of two RHF roots for square H4 depending on platform/BLAS. + # https://github.com/quantumlib/ReCirq/issues/396 try: np.testing.assert_almost_equal( pyscf_hamiltonian.e_hf, from_file_hamiltonian.e_hf, decimal=5 ) except AssertionError: - if sys.platform != "darwin": - raise + np.testing.assert_almost_equal( + pyscf_hamiltonian.e_hf, -1.7014893632799266, decimal=5 + ) np.testing.assert_almost_equal( pyscf_hamiltonian.e_fci, from_file_hamiltonian.e_fci, decimal=10 diff --git a/recirq/random_circuit_sampling/rcs_experiment_test.py b/recirq/random_circuit_sampling/rcs_experiment_test.py index b8f926f9..1ccda806 100644 --- a/recirq/random_circuit_sampling/rcs_experiment_test.py +++ b/recirq/random_circuit_sampling/rcs_experiment_test.py @@ -30,16 +30,6 @@ def test_rcs_multi_depth_regression(): N_REPETITIONS = 10000 FIXED_SEED = 2026 - # Benchmark values from the deterministic run - expected_benchmarks = { - (0, 30): 0.9846, - (0, 50): 0.9753, - (1, 30): 0.9896, - (1, 50): 0.9967, - (2, 30): 1.0030, - (2, 50): 0.9927, - } - experiment = rcs.RCSExperiment( patches=patches, depths=DEPTHS, @@ -51,6 +41,26 @@ def test_rcs_multi_depth_regression(): simulator = cirq.Simulator(seed=FIXED_SEED) results = experiment.run(sampler=simulator, n_repetitions=N_REPETITIONS, characterize=False) + # Benchmark values from the deterministic run (Generator in Cirq >= 1.8 vs RandomState) + if isinstance(simulator._prng, np.random.Generator): + expected_benchmarks = { + (0, 30): 0.9783, + (0, 50): 0.9768, + (1, 30): 0.9781, + (1, 50): 0.9923, + (2, 30): 0.9905, + (2, 50): 1.0086, + } + else: + expected_benchmarks = { + (0, 30): 0.9846, + (0, 50): 0.9753, + (1, 30): 0.9896, + (1, 50): 0.9967, + (2, 30): 1.0030, + (2, 50): 0.9927, + } + fidelities = results.fidelities_lin() for (patch_idx, depth), expected_val in expected_benchmarks.items(): diff --git a/recirq/serialization_utils_test.py b/recirq/serialization_utils_test.py index 9679bf70..4d8df8a1 100644 --- a/recirq/serialization_utils_test.py +++ b/recirq/serialization_utils_test.py @@ -41,15 +41,15 @@ def test_bits_roundtrip(): buffer.seek(0) text = buffer.read() - assert ( - text - == """{ + assert text in ( + '{"cirq_type": "recirq.BitArray", "shape": [10], "packedbits": "5e40"}', + """{ "cirq_type": "recirq.BitArray", "shape": [ 10 ], "packedbits": "5e40" -}""" +}""", ) buffer.seek(0)