From 04cc44a15a74e3f134df6071330ae8e2c63563d9 Mon Sep 17 00:00:00 2001 From: Maarten Sebregts Date: Tue, 26 Aug 2025 15:44:28 +0200 Subject: [PATCH] Bypass __setattr__ logic when creating a deepcopy This improves deepcopy performance by ~40% for the ITER magnetics machine description. --- imas/ids_structure.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/imas/ids_structure.py b/imas/ids_structure.py index 2727003..fbc3042 100644 --- a/imas/ids_structure.py +++ b/imas/ids_structure.py @@ -1,7 +1,6 @@ # This file is part of IMAS-Python. # You should have received the IMAS-Python LICENSE file with this project. -"""A structure in an IDS -""" +"""A structure in an IDS""" import logging from copy import deepcopy @@ -151,7 +150,9 @@ def __deepcopy__(self, memo): for child in self._children: if child in self.__dict__: child_copy = deepcopy(getattr(self, child), memo) - setattr(copy, child, child_copy) + # bypass __setattr__: + copy.__dict__[child] = child_copy + child_copy._parent = copy return copy def __dir__(self) -> List[str]: