Skip to content

Commit 6e6472c

Browse files
authored
Merge branch 'master' into add_projector_lgpu
2 parents 6b1e629 + a36fe22 commit 6e6472c

File tree

1 file changed

+14
-23
lines changed

1 file changed

+14
-23
lines changed

tests/lightning_qubit/test_measurements_class.py

+14-23
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,8 @@ def calculate_reference(tape, lightning_sv):
408408
m = LightningMeasurements(statevector)
409409
return m.measure_final_state(tape)
410410

411-
@flaky(max_runs=15)
412-
@pytest.mark.parametrize("shots", [None, 200_000, [190_000, 190_000]])
411+
@flaky(max_runs=5)
412+
@pytest.mark.parametrize("shots", [None, 500_000, [500_000, 500_000]])
413413
@pytest.mark.parametrize("measurement", [qml.expval, qml.probs, qml.var])
414414
@pytest.mark.parametrize(
415415
"observable",
@@ -449,16 +449,12 @@ def test_single_return_value(self, shots, measurement, observable, lightning_sv,
449449
pytest.skip(
450450
f"Measurement of type {type(measurement).__name__} does not have a keyword argument 'wires'."
451451
)
452-
rtol = 1.0e-2 # 1% of expected value as tolerance
453452
if shots != None and measurement is qml.expval:
454453
# Increase the number of shots
455454
if isinstance(shots, int):
456-
shots *= 10
455+
shots = 1_000_000
457456
else:
458-
shots = [i * 10 for i in shots]
459-
460-
# Extra tolerance
461-
rtol = 5.0e-2 # 5% of expected value as tolerance
457+
shots = [1_000_000, 1_000_000]
462458

463459
n_qubits = 4
464460
n_layers = 1
@@ -499,14 +495,13 @@ def test_single_return_value(self, shots, measurement, observable, lightning_sv,
499495
if shots is None:
500496
assert np.allclose(result, expected, max(tol, 1.0e-4))
501497
else:
502-
atol = max(tol, 1.0e-2) if statevector.dtype == np.complex64 else max(tol, 1.0e-3)
503-
rtol = max(tol, rtol) # % of expected value as tolerance
504-
498+
# TODO Set better atol and rtol
499+
dtol = max(tol, 1.0e-2)
505500
# allclose -> absolute(a - b) <= (atol + rtol * absolute(b))
506-
assert np.allclose(result, expected, rtol=rtol, atol=atol)
501+
assert np.allclose(result, expected, rtol=dtol, atol=dtol)
507502

508-
@flaky(max_runs=10)
509-
@pytest.mark.parametrize("shots", [None, 100_000, (90_000, 90_000)])
503+
@flaky(max_runs=5)
504+
@pytest.mark.parametrize("shots", [None, 400_000, (400_000, 400_000)])
510505
@pytest.mark.parametrize("measurement", [qml.expval, qml.probs, qml.var])
511506
@pytest.mark.parametrize(
512507
"obs0_",
@@ -557,16 +552,12 @@ def test_double_return_value(self, shots, measurement, obs0_, obs1_, lightning_s
557552
f"Observable of type {type(obs0_).__name__} is not supported for rotating probabilities."
558553
)
559554

560-
rtol = 1.0e-2 # 1% of expected value as tolerance
561555
if shots != None and measurement is qml.expval:
562556
# Increase the number of shots
563557
if isinstance(shots, int):
564-
shots *= 10
558+
shots = 1_000_000
565559
else:
566-
shots = [i * 10 for i in shots]
567-
568-
# Extra tolerance
569-
rtol = 5.0e-2 # 5% of expected value as tolerance
560+
shots = [1_000_000, 1_000_000]
570561

571562
n_qubits = 4
572563
n_layers = 1
@@ -610,14 +601,14 @@ def test_double_return_value(self, shots, measurement, obs0_, obs1_, lightning_s
610601
assert isinstance(result, Sequence)
611602
assert len(result) == len(expected)
612603
# a few tests may fail in single precision, and hence we increase the tolerance
613-
atol = tol if shots is None else max(tol, 1.0e-2)
614-
rtol = max(tol, rtol) # % of expected value as tolerance
604+
dtol = tol if shots is None else max(tol, 1.0e-2)
605+
# TODO Set better atol and rtol
615606
for r, e in zip(result, expected):
616607
if isinstance(shots, tuple) and isinstance(r[0], np.ndarray):
617608
r = np.concatenate(r)
618609
e = np.concatenate(e)
619610
# allclose -> absolute(r - e) <= (atol + rtol * absolute(e))
620-
assert np.allclose(r, e, atol=atol, rtol=rtol)
611+
assert np.allclose(r, e, atol=dtol, rtol=dtol)
621612

622613
@pytest.mark.parametrize(
623614
"cases",

0 commit comments

Comments
 (0)