Skip to content

Commit

Permalink
supporting status attribute and status dictionary item (#528)
Browse files Browse the repository at this point in the history
* supporting status attribute and status property

* naming
  • Loading branch information
ivanbasov authored Nov 21, 2023
1 parent 9d346a6 commit 4908b19
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions azure-quantum/azure/quantum/target/microsoft/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(self, data: Union[Dict, List]):
super().__init__(data)

self._is_simple = True
if hasattr(self, 'status') and self['status'] == "success":
if self._is_succeeded():
self._repr = self._item_result_table()
self.summary = HTMLWrapper(self._item_result_summary_table())
self.diagram = EstimatorResultDiagram(self.data().copy())
Expand All @@ -63,6 +63,9 @@ def __init__(self, data: Union[Dict, List]):
# Add plot function for batching jobs
self.plot = self._plot
self.summary_data_frame = self._summary_data_frame

def _is_succeeded(self):
return 'status' in self and self['status'] == "success"

def data(self, idx: Optional[int] = None) -> Any:
"""
Expand Down Expand Up @@ -276,7 +279,7 @@ def _summary_data_frame(self, **kwargs):
labels = labels[:len(self)]

def get_row(result):
if 'status' in result and result['status'] == 'success':
if self._is_succeeded():
formatted = result["physicalCountsFormatted"]

return (
Expand Down Expand Up @@ -406,7 +409,7 @@ def _item_result_summary_table(self):
return html

def _batch_result_table(self, indices):
succeeded_item_indices = [i for i in indices if 'status' in self[i] and self[i]['status'] == 'success']
succeeded_item_indices = [i for i in indices if self[i]._is_succeeded()]
if len(succeeded_item_indices) == 0:
print("None of the jobs succeeded")
return ""
Expand Down

0 comments on commit 4908b19

Please sign in to comment.