Skip to content

Commit 145beff

Browse files
Add unit test for QSimSimulator.get_seed (#1027)
Added a new test case `test_get_seed` to `qsimcirq_tests/qsimcirq_test.py` to verify: - The returned seed is within the expected [0, 2^31 - 1) range. - The simulator is deterministic when initialized with a fixed seed. - Subsequent calls to `get_seed` return different values. --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent fd73593 commit 145beff

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

qsimcirq_tests/qsimcirq_test.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2196,3 +2196,21 @@ def test_1d_representation():
21962196
want = np.array([0.0 - 0.5j, 0.0 + 0.5j, 0.0 - 0.5j, 0.0 + 0.5j])
21972197
_, res, _ = qsim_sim.simulate_into_1d_array(c)
21982198
np.testing.assert_allclose(res, np.array(want, dtype=np.complex64))
2199+
2200+
2201+
def test_get_seed():
2202+
# Test range.
2203+
qsim_sim = qsimcirq.QSimSimulator(seed=42)
2204+
for _ in range(100):
2205+
seed = qsim_sim.get_seed()
2206+
assert 0 <= seed < 2**31 - 1
2207+
2208+
# Test determinism.
2209+
sim1 = qsimcirq.QSimSimulator(seed=42)
2210+
sim2 = qsimcirq.QSimSimulator(seed=42)
2211+
assert sim1.get_seed() == sim2.get_seed()
2212+
2213+
# Test subsequent calls.
2214+
sim = qsimcirq.QSimSimulator(seed=42)
2215+
seeds = {sim.get_seed() for _ in range(10)}
2216+
assert len(seeds) > 1

0 commit comments

Comments
 (0)