Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added assertions for preciseness of results #1

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)