Exemple #1
0
    def test_acquire_algorithm_lock_successful(self, new_config, algorithm):
        with OrionState(experiments=[new_config]) as cfg:
            exp = Experiment("supernaekei", mode="x")
            exp._id = 0
            exp.algorithms = algorithm

            state_dict = algorithm.state_dict
            # No state_dict in DB
            with exp.acquire_algorithm_lock(
                    timeout=0.2, retry_interval=0.1) as locked_algorithm:
                assert locked_algorithm is algorithm

                assert algorithm.state_dict == state_dict
                algorithm.suggest(1)
                assert algorithm.state_dict != state_dict
                new_state_dict = algorithm.state_dict

            algorithm.set_state(state_dict)
            assert algorithm.configuration != new_state_dict

            # State_dict in DB used to set algorithm state.
            with exp.acquire_algorithm_lock(timeout=0.2, retry_interval=0.1):
                assert algorithm.state_dict == new_state_dict
Exemple #2
0
    def test_acquire_algorithm_lock_timeout(self, new_config, algorithm, mocker):
        with OrionState(experiments=[new_config]) as cfg:
            exp = Experiment("supernaekei", mode="x")
            exp._id = 0
            exp.algorithms = algorithm

            storage_acquisition_mock = mocker.spy(
                cfg.storage(), "acquire_algorithm_lock"
            )

            with exp.acquire_algorithm_lock(timeout=0.2, retry_interval=0.1):
                pass

            storage_acquisition_mock.assert_called_with(
                experiment=exp, timeout=0.2, retry_interval=0.1
            )
Exemple #3
0
    def test_acquire_algorithm_lock_with_different_config(self, new_config, algorithm):
        with OrionState(experiments=[new_config]) as cfg:
            exp = Experiment("supernaekei", mode="x")
            exp._id = 0
            algorithm_original_config = algorithm.configuration
            exp.algorithms = algorithm
            # Setting attribute to algorithm inside the wrapper
            algorithm.algorithm.seed = 10

            assert algorithm.configuration != algorithm_original_config

            with pytest.raises(
                RuntimeError, match="Algorithm configuration changed since"
            ):
                with exp.acquire_algorithm_lock(timeout=0.2, retry_interval=0.1):
                    pass