@@ -186,7 +186,8 @@ def result(
186
186
self ,
187
187
timeout : Optional [float ] = None ,
188
188
wait : float = 5 ,
189
- partial : bool = False
189
+ partial : bool = False ,
190
+ refresh : bool = False
190
191
) -> Result :
191
192
"""Return the result of the job.
192
193
@@ -222,6 +223,8 @@ def result(
222
223
timeout: number of seconds to wait for job
223
224
wait: time between queries to IBM Q server
224
225
partial: if true attempts to return partial results for the job.
226
+ refresh: if true, query the API for the result again.
227
+ Otherwise return the cached value. Default: False.
225
228
226
229
Returns:
227
230
Result object.
@@ -243,7 +246,7 @@ def result(
243
246
raise IBMQJobFailureError ('Unable to retrieve job result. Job has failed. '
244
247
'Use job.error_message() to get more details.' )
245
248
246
- return self ._retrieve_result ()
249
+ return self ._retrieve_result (refresh = refresh )
247
250
248
251
def cancel (self ) -> bool :
249
252
"""Attempt to cancel a job.
@@ -349,7 +352,7 @@ def queue_position(self, refresh: bool = False) -> Optional[int]:
349
352
"""Return the position in the server queue.
350
353
351
354
Args:
352
- refresh (bool) : if True, query the API and return the latest value.
355
+ refresh: if True, query the API and return the latest value.
353
356
Otherwise return the cached value.
354
357
355
358
Returns:
@@ -483,9 +486,13 @@ def _wait_for_completion(
483
486
484
487
return self ._status in required_status
485
488
486
- def _retrieve_result (self ) -> Result :
489
+ def _retrieve_result (self , refresh : bool = False ) -> Result :
487
490
"""Retrieve the job result response.
488
491
492
+ Args:
493
+ refresh: if true, query the API for the result again.
494
+ Otherwise return the cached value. Default: False.
495
+
489
496
Returns:
490
497
The job result.
491
498
@@ -496,7 +503,7 @@ def _retrieve_result(self) -> Result:
496
503
"""
497
504
# pylint: disable=access-member-before-definition,attribute-defined-outside-init
498
505
result_response = None
499
- if not self ._result : # type: ignore[has-type]
506
+ if not self ._result or refresh : # type: ignore[has-type]
500
507
try :
501
508
result_response = self ._api .job_result (self .job_id (), self ._use_object_storage )
502
509
self ._result = Result .from_dict (result_response )
0 commit comments