Beispiel #1
0
    def test_dimension_deletion_forward_not_existing(self, trials):
        """Test :meth:`orion.core.evc.adapters.DimensionDeletion.forward`
        with valid param and invalid trials because param does not exist
        """
        new_param = Trial.Param(name="second_normal_prior",
                                type="integer",
                                value=1)
        dimension_deletion_adapter = DimensionDeletion(new_param)

        with pytest.raises(RuntimeError) as exc_info:
            dimension_deletion_adapter.forward(trials)
        assert "Provided trial does not have a compatible configuration" in str(
            exc_info.value)
Beispiel #2
0
    def test_dimension_deletion_forward(self, trials):
        """Test :meth:`orion.core.evc.adapters.DimensionDeletion.forward`
        with valid param and valid trials
        """
        new_param = Trial.Param(name="second_normal_prior",
                                type="integer",
                                value=1)
        dimension_deletion_adapter = DimensionDeletion(new_param)

        sampler = DimensionBuilder().build("random",
                                           "uniform(10, 100, discrete=True)")
        for trial in trials:
            random_param = new_param.to_dict()
            random_param["value"] = sampler.sample()
            trial._params.append(Trial.Param(**random_param))

        adapted_trials = dimension_deletion_adapter.forward(trials)
        assert len(adapted_trials) == 0

        trials[0]._params[-1].value = 1
        assert trials[0]._params[-1] == new_param

        adapted_trials = dimension_deletion_adapter.forward(trials)
        assert len(adapted_trials) == 1

        trials[4]._params[-1].value = 1
        assert trials[4]._params[-1] == new_param

        adapted_trials = dimension_deletion_adapter.forward(trials)
        assert len(adapted_trials) == 2

        trials[-1]._params[-1].value = 1
        assert trials[-1]._params[-1] == new_param

        adapted_trials = dimension_deletion_adapter.forward(trials)
        assert len(adapted_trials) == 3

        assert new_param not in (adapted_trials[0]._params)
        assert new_param not in (adapted_trials[1]._params)
        assert new_param not in (adapted_trials[2]._params)