Example #1
0
 def load_weights(self, prefix):
     weights = self._server.get(f"{self._prefix}_{prefix}_weights")
     if weights is None:
         return None
     weights = utils.unpack(weights)
     self._epoch = weights.get("epoch")
     return weights["weights"]
Example #2
0
 def load_checkpoint(self):
     checkpoint = self._server.get(f"{self._prefix}_checkpoint")
     if checkpoint is None:
         return None
     checkpoint = utils.unpack(checkpoint)
     self._epoch = checkpoint.get("epoch")
     return checkpoint["checkpoint"]
Example #3
0
    def get_trajectory(self, index=None):
        assert index is None

        try:
            trajectory_obj = self._trajectory_collection.find_one(
                {"date": {
                    "$gt": self._last_datetime
                }})
        except pymongo.errors.AutoReconnect:
            time.sleep(self._reconnect_timeout)
            return self.get_trajectory(index)

        if trajectory_obj is not None:
            self._last_datetime = trajectory_obj["date"]

            trajectory, trajectory_epoch = \
                utils.unpack(trajectory_obj["trajectory"]), \
                trajectory_obj["epoch"]
            if self._sync_epoch and self._epoch != trajectory_epoch:
                trajectory = None
            else:
                trajectory = utils.dict2structed_trajectory(trajectory)
        else:
            trajectory = None

        return trajectory
Example #4
0
 def load_weights(self, prefix):
     weights_obj = self._weights_collection.find_one({"prefix": prefix})
     weights = weights_obj.get("weights")
     if weights is None:
         return None
     self._epoch = weights_obj["epoch"]
     weights = utils.unpack(weights)
     return weights
Example #5
0
 def load_checkpoint(self):
     checkpoint_obj = self._checkpoints_collection.find_one(
         {"prefix": "checkpoint"})
     checkpoint = checkpoint_obj.get("checkpoint")
     if checkpoint is None:
         return None
     self._epoch = checkpoint_obj["epoch"]
     checkpoint = utils.unpack(checkpoint)
     return checkpoint
Example #6
0
    def get_trajectory(self, index=None):
        index = index if index is not None else self._index
        trajectory = self._server.lindex("trajectories", index)
        if trajectory is not None:
            self._index = index + 1

            trajectory = utils.unpack(trajectory)
            trajectory, trajectory_epoch = \
                trajectory["trajectory"], trajectory["epoch"]
            if self._sync_epoch and self._epoch != trajectory_epoch:
                trajectory = None
            else:
                trajectory = utils.dict2structed_trajectory(trajectory)

        return trajectory
Example #7
0
    def get_checkpoint(self):
        try:
            checkpoint_obj = self._checkpoint_collection.find_one(
                {"filename": "checkpoint"})
        except pymongo.errors.AutoReconnect:
            time.sleep(self._reconnect_timeout)
            return self.get_checkpoint()

        if checkpoint_obj is not None:
            checkpoint = checkpoint_obj.read().decode("ascii")
            self._epoch = checkpoint_obj.epoch
            checkpoint = utils.unpack(checkpoint)
        else:
            checkpoint = None
        return checkpoint
Example #8
0
    def get_checkpoint(self):
        try:
            checkpoint_obj = self._checkpoints_collection.find_one(
                {"prefix": "checkpoint"})
        except pymongo.errors.AutoReconnect:
            time.sleep(self._reconnect_timeout)
            return self.get_checkpoint()

        if checkpoint_obj is not None:
            checkpoint = checkpoint_obj.get("checkpoint")
            self._epoch = checkpoint_obj["epoch"]
            checkpoint = utils.unpack(checkpoint)
        else:
            checkpoint = None
        return checkpoint
Example #9
0
    def get_trajectory(self, index=None):
        assert index is None

        trajectory_obj = self._trajectory_collection.find_one(
            {"date": {
                "$gt": self._last_datetime
            }})
        if trajectory_obj is not None:
            self._last_datetime = trajectory_obj["date"]

            trajectory, trajectory_epoch = \
                utils.unpack(
                    trajectory_obj["trajectory"]), trajectory_obj["epoch"]
            if self._sync_epoch and self._epoch != trajectory_epoch:
                trajectory = None
            else:
                trajectory = utils.dict2structed_trajectory(trajectory)
        else:
            trajectory = None

        return trajectory