diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index 8618b334d..1509f65b3 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -26,6 +26,9 @@ ### Improvements +* Reduce flaky test and increase test shots count. + [(#1015)](https://github.com/PennyLaneAI/pennylane-lightning/pull/1015) + * Update the logic for enabling `grad_on_execution` during device execution. [(#1016)](https://github.com/PennyLaneAI/pennylane-lightning/pull/1016) diff --git a/pennylane_lightning/core/_version.py b/pennylane_lightning/core/_version.py index 3ecb65af2..f748fa2b7 100644 --- a/pennylane_lightning/core/_version.py +++ b/pennylane_lightning/core/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.40.0-dev28" +__version__ = "0.40.0-dev29" diff --git a/tests/lightning_qubit/test_measurements_class.py b/tests/lightning_qubit/test_measurements_class.py index b2d073601..8e73a5b13 100644 --- a/tests/lightning_qubit/test_measurements_class.py +++ b/tests/lightning_qubit/test_measurements_class.py @@ -707,7 +707,6 @@ def calculate_reference(tape): results = dev.execute(tapes) return transf_fn(results) - @flaky(max_runs=5) @pytest.mark.parametrize( "operation", [ @@ -819,7 +818,6 @@ def test_controlled_qubit_unitary_from_op(self, tol, lightning_sv): assert np.allclose(result, expected, tol) - @flaky(max_runs=5) @pytest.mark.parametrize("control_wires", range(4)) @pytest.mark.parametrize("target_wires", range(4)) def test_cnot_controlled_qubit_unitary(self, control_wires, target_wires, tol, lightning_sv): @@ -831,6 +829,7 @@ def test_cnot_controlled_qubit_unitary(self, control_wires, target_wires, tol, l target_wires = [target_wires] wires = control_wires + target_wires U = qml.matrix(qml.PauliX(target_wires)) + np.random.seed(0) init_state = np.random.rand(2**n_qubits) + 1.0j * np.random.rand(2**n_qubits) init_state /= np.linalg.norm(init_state) diff --git a/tests/test_measurements.py b/tests/test_measurements.py index 12707b6f4..e20d8ad65 100644 --- a/tests/test_measurements.py +++ b/tests/test_measurements.py @@ -660,7 +660,7 @@ def test_sample_values(self, qubit_device, tol): @pytest.mark.parametrize("nwires", range(1, 11)) def test_sample_variations(self, qubit_device, nwires, seed): """Tests if `sample(wires)` returns correct statistics.""" - shots = 20000 + shots = 200000 n_qubits = max(5, nwires + 1) np.random.seed(seed) wires = qml.wires.Wires(np.random.permutation(nwires)) @@ -669,6 +669,7 @@ def test_sample_variations(self, qubit_device, nwires, seed): state /= np.linalg.norm(state) ops = [qml.StatePrep(state, wires=range(n_qubits))] tape = qml.tape.QuantumScript(ops, [qml.sample(wires=wires)], shots=shots) + tape_exact = qml.tape.QuantumScript(ops, [qml.probs(wires=wires)]) def reshape_samples(samples): return np.atleast_3d(samples) if len(wires) == 1 else np.atleast_2d(samples) @@ -679,13 +680,10 @@ def reshape_samples(samples): reshape_samples(samples), wire_order=wires ) - dev = qml.device("default.qubit", wires=n_qubits, shots=shots) - samples = dev.execute(tape) - ref = qml.measurements.ProbabilityMP(wires=wires).process_samples( - reshape_samples(samples), wire_order=wires - ) + dev_ref = qml.device("default.qubit", wires=n_qubits) + probs_ref = dev_ref.execute(tape_exact) - assert np.allclose(probs, ref, atol=2.0e-2, rtol=1.0e-4) + assert np.allclose(probs, probs_ref, atol=2.0e-2, rtol=1.0e-4) class TestWiresInVar: @@ -734,8 +732,7 @@ def circuit2(): assert np.allclose(circuit1(), circuit2(), atol=tol) -@flaky(max_runs=5) -@pytest.mark.parametrize("shots", [None, 10000, [10000, 11111]]) +@pytest.mark.parametrize("shots", [None, 100000, [100000, 111111]]) @pytest.mark.parametrize("measure_f", [qml.counts, qml.expval, qml.probs, qml.sample, qml.var]) @pytest.mark.parametrize( "obs",