def put_trajectory(self, trajectory, raw=False): try: trajectory_ = utils.structed2dict_trajectory(trajectory) trajectory_ = utils.pack(trajectory_) collection = self._raw_trajectory_collection if raw \ else self._trajectory_collection collection.insert_one( { "trajectory": trajectory_, "date": datetime.datetime.utcnow(), "epoch": self._epoch } ) except pymongo.errors.AutoReconnect: time.sleep(self._reconnect_timeout) return self.put_trajectory(trajectory, raw)
def put_checkpoint(self, checkpoint, epoch): try: self._epoch = epoch checkpoint_ = utils.pack(checkpoint) if self._checkpoint_collection.exists({"filename": "checkpoint"}): self.del_checkpoint() self._checkpoint_collection.put( checkpoint_, encoding="ascii", filename="checkpoint", epoch=self._epoch ) except pymongo.errors.AutoReconnect: time.sleep(self._reconnect_timeout) return self.put_checkpoint(checkpoint, epoch)
def save_checkpoint(self, checkpoint, epoch): self._epoch = epoch checkpoint = {"checkpoint": checkpoint, "epoch": self._epoch} checkpoint = utils.pack(checkpoint) self._server.set(f"{self._prefix}_checkpoint", checkpoint)
def push_trajectory(self, trajectory, raw=False): trajectory = utils.structed2dict_trajectory(trajectory) trajectory = {"trajectory": trajectory, "epoch": self._epoch} trajectory = utils.pack(trajectory) name = "raw_trajectories" if raw else "trajectories" self._server.rpush(name, trajectory)
def dump_weights(self, weights, prefix, epoch): self._epoch = epoch weights = {"weights": weights, "epoch": self._epoch} weights = utils.pack(weights) self._server.set(f"{self._prefix}_{prefix}_weights", weights)
def push_trajectory(self, trajectory): trajectory = utils.structed2dict_trajectory(trajectory) trajectory = {"trajectory": trajectory, "epoch": self._epoch} trajectory = utils.pack(trajectory) self._server.rpush("trajectories", trajectory)