def _maybe_set_up_user_private_modules()

in flsim/utils/fl/personalized_model.py [0:0]


    def _maybe_set_up_user_private_modules(self, forced: bool = False):
        """
        Set an instance's private modules to class attributes to share among
        all users. This function runs only when all user-private attributes
        have been set.
        """
        if not forced:
            for module_name in self._get_user_private_module_names():
                # The user-private modules may not be set during component creation.
                if not hasattr(self, module_name) or getattr(self, module_name) is None:
                    return

        # Initialize the class attributes if not exist.
        for module_name in self._get_user_private_module_names():
            if module_name not in self.user_private_module_dict:
                self.user_private_module_dict[module_name] = getattr(self, module_name)

            # Replace instance-based private attributes with the class attributes.
            # for module_name in self._get_user_private_module_names():
            # Remove instance version if not removed.
            if hasattr(self, module_name):
                delattr(self, module_name)

            setattr(
                self,
                self._get_user_private_module_attr_name(module_name),
                self.user_private_module_dict[module_name],
            )