Skip to content

Commit

Permalink
Updated add_data for early initialization qiskit-community#1268
Browse files Browse the repository at this point in the history
  • Loading branch information
Musa-Sina-Ertugrul committed Oct 24, 2023
1 parent 24b210c commit cbf544a
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion qiskit_experiments/framework/experiment_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,48 @@ def add_data(
) -> None:
"""Add experiment data.
Args:
data: Experiment data to add. Several types are accepted for convenience:
* Result: Add data from this ``Result`` object.
* List[Result]: Add data from the ``Result`` objects.
* Dict: Add this data.
* List[Dict]: Add this list of data.
Raises:
TypeError: If the input data type is invalid.
"""
if any(not future.done() for future in self._analysis_futures.values()):
LOG.warning(
"Not all analysis has finished running. Adding new data may "
"create unexpected analysis results."
)
if not isinstance(data, list):
data = [data]

# Directly add non-job data
with self._result_data.lock:
for datum in data:
if isinstance(datum, dict):
if datum.get("composite_metadata"):
self._add_data(datum.child_data(),datum["composite_metadata"])
self._result_data.append(datum)
else:
datum["composite_metadata"] = [ExperimentData()]
elif isinstance(datum, Result):
if datum["metadata"]:
self._set_child_data(datum["metadata"]._metadata())
else:
self._add_result_data(datum)
else:
raise TypeError(f"Invalid data type {type(datum)}.")

def __add_data(
self,
data: Union[Result, List[Result], Dict, List[Dict]],
) -> None:
"""Add experiment data.
Args:
data: Experiment data to add. Several types are accepted for convenience:
Expand Down Expand Up @@ -835,7 +877,7 @@ def _add_data(
sub_expdata._result_data.clear()
for datum in sub_data:
self.__reacher_composite_metadata(datum)
sub_expdata.add_data(sub_data)
sub_expdata.__add_data(sub_data)

def __reacher_composite_metadata(self,data : Dict)->List:
if data.get("composite_metadata"):
Expand Down

0 comments on commit cbf544a

Please sign in to comment.