Example #1
0
    def update_trials(self, experiment=None, uid=None, where=None, **kwargs):
        """See :func:`orion.storage.base.BaseStorageProtocol.update_trials`"""
        uid = get_uid(experiment, uid)
        if where is None:
            where = dict()

        where["experiment"] = uid
        return self._db.write("trials", data=kwargs, query=where)
Example #2
0
    def update_experiment(self, experiment=None, uid=None, where=None, **kwargs):
        """See :meth:`orion.storage.base.BaseStorageProtocol.update_experiment`"""
        uid = get_uid(experiment, uid)

        self.group = self.backend.fetch_and_update_group(
            {"_uid": uid}, "set_group_metadata", **kwargs
        )

        return self.group
Example #3
0
    def delete_trials(self, experiment=None, uid=None, where=None):
        """See :func:`orion.storage.base.BaseStorageProtocol.delete_trials`"""
        uid = get_uid(experiment, uid)

        if where is None:
            where = dict()

        if uid is not None:
            where["experiment"] = uid
        return self._db.remove("trials", query=where)
Example #4
0
    def fetch_trials(self, experiment=None, uid=None, where=None):
        """See :func:`orion.storage.base.BaseStorageProtocol.fetch_trials`"""
        uid = get_uid(experiment, uid)

        if where is None:
            where = dict()

        where["experiment"] = uid

        return self._fetch_trials(where)
Example #5
0
    def update_trials(self, experiment=None, uid=None, where=None, **kwargs):
        """See :meth:`orion.storage.base.BaseStorageProtocol.update_trials`"""
        uid = get_uid(experiment, uid)

        if where is None:
            where = dict()

        where["group_id"] = uid

        count = 0
        for trial in self._fetch_trials(where):
            count += self.update_trial(trial, **kwargs)

        return count
Example #6
0
    def get_algorithm_lock_info(self, experiment=None, uid=None):
        """See :func:`orion.storage.base.BaseStorageProtocol.get_algorithm_lock_info`"""
        uid = get_uid(experiment, uid)
        locks = self._db.read("algo", {"experiment": uid})

        if not locks:
            return None

        algo_state_lock = locks[0]
        return LockedAlgorithmState(
            state=pickle.loads(algo_state_lock["state"])
            if algo_state_lock["state"] is not None else None,
            configuration=algo_state_lock["configuration"],
            locked=algo_state_lock["locked"],
        )
Example #7
0
    def release_algorithm_lock(self,
                               experiment=None,
                               uid=None,
                               new_state=None):
        """See :func:`orion.storage.base.BaseStorageProtocol.release_algorithm_lock`"""
        uid = get_uid(experiment, uid)

        new_data = dict(
            experiment=uid,
            locked=0,
            heartbeat=datetime.datetime.utcnow(),
        )
        if new_state is not None:
            new_data["state"] = pickle.dumps(new_state)

        self._db.read_and_write(
            "algo",
            query=dict(experiment=uid, locked=1),
            data=new_data,
        )
Example #8
0
    def get_trial(self, trial=None, uid=None):
        """See :meth:`orion.storage.base.BaseStorageProtocol.get_trial`"""
        uid = get_uid(trial, uid)

        _hash, _rev = 0, 0
        data = uid.split("_", maxsplit=1)

        if len(data) == 1:
            _hash = data[0]

        elif len(data) == 2:
            _hash, _rev = data

        trials = self.backend.get_trial(TrackTrial(_hash=_hash, revision=_rev))

        if trials is None:
            return None

        assert len(trials) == 1
        return TrialAdapter(trials[0], objective=self.objective)
Example #9
0
    def acquire_algorithm_lock(self,
                               experiment=None,
                               uid=None,
                               timeout=60,
                               retry_interval=1):
        """See :func:`orion.storage.base.BaseStorageProtocol.acquire_algorithm_lock`"""
        uid = get_uid(experiment, uid)

        algo_state_lock = None
        start = time.perf_counter()
        while algo_state_lock is None and time.perf_counter() - start < timeout:
            algo_state_lock = self._db.read_and_write(
                "algo",
                query=dict(experiment=uid, locked=0),
                data=dict(
                    locked=1,
                    heartbeat=datetime.datetime.utcnow(),
                ),
            )
            if algo_state_lock is None:
                time.sleep(retry_interval)

        if algo_state_lock is None:
            raise LockAcquisitionTimeout

        locked_algo_state = LockedAlgorithmState(
            state=pickle.loads(algo_state_lock["state"])
            if algo_state_lock["state"] is not None else None,
            configuration=algo_state_lock["configuration"],
            locked=True,
        )

        try:
            yield locked_algo_state
        except Exception:
            # Reset algo to state fetched lock time
            locked_algo_state.reset()
            raise
        finally:
            self.release_algorithm_lock(uid=uid,
                                        new_state=locked_algo_state.state)
Example #10
0
    def fetch_trials(self, experiment=None, uid=None):
        """See :func:`orion.storage.base.BaseStorageProtocol.fetch_trials`"""
        uid = get_uid(experiment, uid)

        return self._fetch_trials(dict(experiment=uid))
Example #11
0
 def delete_experiment(self, experiment=None, uid=None):
     """See :func:`orion.storage.base.BaseStorageProtocol.delete_experiment`"""
     uid = get_uid(experiment, uid)
     return self._db.remove("experiments", query={"_id": uid})
Example #12
0
 def delete_algorithm_lock(self, experiment=None, uid=None):
     """See :func:`orion.storage.base.BaseStorageProtocol.delete_algorithm_lock`"""
     uid = get_uid(experiment, uid)
     return self._db.remove("algo", query={"experiment": uid})