示例#1
0
    def dill_calls(self):
        logger.debug("Dumping calls to andes.pkl with dill")
        import dill
        dill.settings['recurse'] = True

        pkl_path = get_pkl_path()
        with open(pkl_path, 'wb') as f:
            dill.dump(self.calls, f)
示例#2
0
    def dill(self):
        """
        Serialize generated functions in ``System.calls`` with dill.

        The serialized file will be stored to ``~/calls.pkl``.
        """
        logger.debug("Dumping calls to calls.pkl with dill")
        import dill
        dill.settings['recurse'] = True

        pkl_path = get_pkl_path()
        with open(pkl_path, 'wb') as f:
            dill.dump(self.calls, f)
示例#3
0
    def undill_calls(self):
        import dill
        dill.settings['recurse'] = True

        pkl_path = get_pkl_path()

        if not os.path.isfile(pkl_path):
            self.prepare()

        with open(pkl_path, 'rb') as f:
            self.calls = dill.load(f)
        logger.debug(f'System undill: loaded <{pkl_path}> file.')
        for name, model_call in self.calls.items():
            self.__dict__[name].calls = model_call
示例#4
0
文件: system.py 项目: songcn206/andes
    def _load_pkl():
        import dill
        dill.settings['recurse'] = True
        pkl_path = get_pkl_path()

        if os.path.isfile(pkl_path):
            with open(pkl_path, 'rb') as f:

                try:
                    loaded_calls = dill.load(f)
                    return loaded_calls
                except IOError:
                    pass
                except AttributeError:
                    pass

        return None
示例#5
0
文件: system.py 项目: songcn206/andes
    def dill(self):
        """
        Serialize generated numerical functions in `System.calls` with package `dill`.

        The serialized file will be stored to ``~/andes/calls.pkl``, where `~` is the home directory path.

        Notes
        -----
        This function sets `dill.settings['recurse'] = True` to serialize the function calls recursively.

        """
        logger.debug("Dumping calls to calls.pkl with dill")
        import dill
        dill.settings['recurse'] = True

        pkl_path = get_pkl_path()
        with open(pkl_path, 'wb') as f:
            dill.dump(self.calls, f)
示例#6
0
    def undill(self):
        """
        Deserialize the function calls from `calls.pkl` with dill.
        """
        import dill
        dill.settings['recurse'] = True

        pkl_path = get_pkl_path()
        if not os.path.isfile(pkl_path):
            self.prepare()

        with open(pkl_path, 'rb') as f:
            self.calls = dill.load(f)
        logger.debug(f'Undill loaded "{pkl_path}" file.')

        for name, model_call in self.calls.items():
            if name in self.__dict__:
                self.__dict__[name].calls = model_call