Skip to content

Commit

Permalink
Merge pull request #1 from merav-aharoni/qctrl_assertions
Browse files Browse the repository at this point in the history
Added assertions for preciseness of results
  • Loading branch information
kt474 authored Nov 28, 2023
2 parents 79c1ff1 + f34cd3a commit 2a20d47
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions test/integration/test_qctrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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 = {
Expand All @@ -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
Expand All @@ -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 = {
Expand All @@ -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
Expand All @@ -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 = {
Expand All @@ -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
Expand Down Expand Up @@ -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 = [
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

0 comments on commit 2a20d47

Please sign in to comment.