From 8edaa7b30936ce8fb41ad2f18329715ba11962f1 Mon Sep 17 00:00:00 2001 From: Musa-Sina-Ertugrul Date: Mon, 15 Apr 2024 19:55:02 +0300 Subject: [PATCH] Sperated init children data, create children #1268 --- .../framework/experiment_data.py | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/qiskit_experiments/framework/experiment_data.py b/qiskit_experiments/framework/experiment_data.py index 0819952d80..cd26a28089 100644 --- a/qiskit_experiments/framework/experiment_data.py +++ b/qiskit_experiments/framework/experiment_data.py @@ -738,6 +738,7 @@ def add_data( else: raise TypeError(f"Invalid data type {type(datum)}.") self.create_child_data() + self.init_children_data() @property def __retrive_self_attrs_as_dict(self) -> dict: @@ -787,13 +788,21 @@ def create_child_data(self): # pylint: disable=inconsistent-return-statements except (KeyError, IndexError): pass self.add_child_data(child_data) + + return self + + def init_children_data(self): + + if (component_metadata := self.metadata.get("component_metadata", None)) is None: + return - for data in self._result_data: - for idx, sub_data in self._decompose_component_data(data): - # NOTE : These lines for preventing multiple data addition, - # it occurs and I dont know why - if sub_data not in self.child_data(idx).data(): - self.child_data(idx).add_data(sub_data) + with self._result_data.lock: + for data in self._result_data: + for idx, sub_data in self._decompose_component_data(data): + # NOTE : These lines for preventing multiple data addition, + # it occurs and I dont know why + if sub_data not in self.child_data(idx).data(): + self.child_data(idx).add_data(sub_data) return self