From f34cd3a8f7d1c04e126da1b985befde546ac45bd Mon Sep 17 00:00:00 2001 From: merav-aharoni Date: Thu, 23 Nov 2023 11:53:48 +0000 Subject: [PATCH] Added assertness for preciseness of results --- test/integration/test_qctrl.py | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/test/integration/test_qctrl.py b/test/integration/test_qctrl.py index a5979acb2..908715155 100644 --- a/test/integration/test_qctrl.py +++ b/test/integration/test_qctrl.py @@ -26,6 +26,9 @@ from ..decorators import run_integration_test, cloud_only from ..utils import cancel_job_safe +FIDELITY_THRESHOLD = 0.9 +DIFFERENCE_THRESHOLD = 0.1 + class TestQCTRL(IBMIntegrationJobTestCase): """Integration tests for QCTRL integration.""" @@ -86,7 +89,8 @@ def test_sampler_qctrl_bell(self, service): # Execute circuit in a session with sampler with Session(service, backend=self.backend): - sampler = Sampler() + options = Options(resilience_level=1) + sampler = Sampler(options=options) result = sampler.run(bell_circuit_sampler, shots=shots).result() results_dict = { @@ -100,6 +104,7 @@ def test_sampler_qctrl_bell(self, service): fidelity = hellinger_fidelity(results_dict, ideal_result) print("fidelity with ideal results: ", fidelity) + self.assertGreater(fidelity, FIDELITY_THRESHOLD) @run_integration_test @cloud_only @@ -119,7 +124,8 @@ def test_sampler_qctrl_ghz(self, service): # Execute circuit in a session with sampler with Session(service, backend=self.backend): - sampler = Sampler() + options = Options(resilience_level=1) + sampler = Sampler(options=options) result = sampler.run(ghz_circuit_sampler, shots=shots).result() results_dict = { @@ -131,8 +137,7 @@ def test_sampler_qctrl_ghz(self, service): key: val / shots for key, val in Statevector(ghz_circuit).probabilities_dict().items() } fidelity = hellinger_fidelity(results_dict, ideal_result) - - print("fidelity with ideal results: ", fidelity) + self.assertGreater(fidelity, FIDELITY_THRESHOLD) @run_integration_test @cloud_only @@ -150,7 +155,8 @@ def test_sampler_qctrl_superposition(self, service): # Execute circuit in a session with sampler with Session(service, backend=self.backend): - sampler = Sampler() + options = Options(resilience_level=1) + sampler = Sampler(options=options) result = sampler.run(superposition_circuit_sampler, shots=shots).result() results_dict = { @@ -163,8 +169,7 @@ def test_sampler_qctrl_superposition(self, service): for key, val in Statevector(superposition_circuit).probabilities_dict().items() } fidelity = hellinger_fidelity(results_dict, ideal_result) - - print("fidelity with ideal results: ", fidelity) + self.assertGreater(fidelity, FIDELITY_THRESHOLD) @run_integration_test @cloud_only @@ -192,7 +197,8 @@ def test_sampler_qctrl_conditional_states(self, service): # Execute circuit in a session with sampler with Session(service, backend=self.backend): - sampler = Sampler() + options = Options(resilience_level=1) + sampler = Sampler(options=options) result = sampler.run(computational_states_sampler_circuits, shots=shots).result() results_dict_list = [ @@ -210,6 +216,8 @@ def test_sampler_qctrl_conditional_states(self, service): ] print("fidelity with ideal results: ", fidelities) + for fidelity in fidelities: + self.assertGreater(fidelity, FIDELITY_THRESHOLD) @run_integration_test @cloud_only @@ -249,6 +257,8 @@ def test_estimator_qctrl_bell(self, service): "absolute difference between theory and experiment expectation values: ", absolute_difference_dict, ) + for diff in absolute_difference: + self.assertLess(diff, DIFFERENCE_THRESHOLD) @run_integration_test @cloud_only @@ -291,6 +301,8 @@ def test_estimator_qctrl_ghz(self, service): "absolute difference between theory and experiment expectation values: ", absolute_difference_dict, ) + for diff in absolute_difference: + self.assertLess(diff, DIFFERENCE_THRESHOLD) @run_integration_test @cloud_only @@ -331,6 +343,8 @@ def test_estimator_qctrl_superposition(self, service): "absolute difference between theory and experiment expectation values: ", absolute_difference_dict, ) + for diff in absolute_difference: + self.assertLess(diff, DIFFERENCE_THRESHOLD) @run_integration_test @cloud_only @@ -392,3 +406,5 @@ def test_estimator_qctrl_conditional(self, service): absolute_difference[idx * len(observables) : (idx + 1) * len(observables)], ) } + for diff in absolute_difference: + self.assertLess(diff, DIFFERENCE_THRESHOLD)