Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions recirq/qcqmc/hamiltonian_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import cirq
import numpy as np
import pytest
import sys
from openfermion import (
get_fermion_operator,
get_ground_state,
Expand Down Expand Up @@ -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
Expand Down
30 changes: 20 additions & 10 deletions recirq/random_circuit_sampling/rcs_experiment_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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():
Expand Down
8 changes: 4 additions & 4 deletions recirq/serialization_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading