Beispiel #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)
Beispiel #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)
Beispiel #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
Beispiel #4
0
    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
Beispiel #5
0
    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)
Beispiel #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