Skip to content

Commit

Permalink
Sperated init children data, create children qiskit-community#1268
Browse files Browse the repository at this point in the history
  • Loading branch information
Musa-Sina-Ertugrul committed Apr 15, 2024
1 parent b33387b commit 8edaa7b
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions qiskit_experiments/framework/experiment_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8edaa7b

Please sign in to comment.