Skip to content

Commit

Permalink
Slight improvements to Qiskit Runtime retry loop (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
garrison authored Nov 4, 2022
1 parent 2f0eefa commit 94551e0
Showing 1 changed file with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
from .entanglement_forging_ansatz import Bitstring, EntanglementForgingAnsatz
from .entanglement_forging_operator import EntanglementForgingOperator

logger = logging.getLogger(__name__)


class EntanglementForgingKnitter:
"""Container for Knitter class functions and attributes.
Expand Down Expand Up @@ -711,17 +713,15 @@ def _estimate_expvals(
# job results to be returned as None. These results often seem to be retrievable at a later time,
# so we have hacked together this loop to try and prevent a crash of the program.
for i in range(20):
if job.result() is None:
if i == 19:
raise RuntimeError(
"A None result was returned from Qiskit Runtime."
)
logging.warning(
"A None result was returned from Qiskit Runtime. Waiting 3 seconds and querying again..."
)
time.sleep(3)
else:
if job.result() is not None:
break
logger.warning(
f"A None result was returned from Qiskit Runtime (job id: {job.job_id}). "
"Waiting 3 seconds and querying again..."
)
time.sleep(3)
else:
raise RuntimeError("A None result was returned from Qiskit Runtime.")

results = job.result().values

Expand Down

0 comments on commit 94551e0

Please sign in to comment.