How to use the orion.algo.space.Space function in orion

To help you get started, we’ve selected a few orion examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Epistimio / orion / tests / unittests / core / worker / test_experiment.py View on Github external
def test_instantiation_after_init(self, exp_config):
        """Verify that algo, space and refers was instanciated properly"""
        exp = Experiment('supernaedo2-dendi')
        assert not isinstance(exp.algorithms, BaseAlgorithm)
        assert not isinstance(exp.space, Space)
        assert not isinstance(exp.refers['adapter'], BaseAdapter)
        # Deliver an external configuration to finalize init
        exp.configure(exp_config[0][0])
        assert exp._init_done is True
        assert isinstance(exp.algorithms, BaseAlgorithm)
        assert isinstance(exp.space, Space)
        assert isinstance(exp.refers['adapter'], BaseAdapter)
github Epistimio / orion / tests / unittests / algo / test_asha.py View on Github external
def space():
    """Create a Space with a real dimension and a fidelity value."""
    space = Space()
    space.register(Real('lr', 'uniform', 0, 1))
    space.register(Fidelity('epoch', 1, 9, 3))
    return space
github Epistimio / orion / tests / unittests / algo / test_space.py View on Github external
def test_bad_contain(self):
        """Checking with no iterables does no good."""
        space = Space()
        with pytest.raises(TypeError):
            5 in space
github Epistimio / orion / tests / unittests / algo / test_space.py View on Github external
def test_configuration(self):
        """Test that configuration contains all dimensions."""
        space = Space()
        space.register(Integer('yolo1', 'uniform', -3, 6, shape=(2,)))
        space.register(Integer('yolo2', 'uniform', -3, 6, shape=(2,)))
        space.register(Real('yolo3', 'norm', 0.9))
        space.register(Categorical('yolo4', ('asdfa', 2)))

        assert space.configuration == {
            'yolo1': 'uniform(-3, 3, shape=(2,), discrete=True)',
            'yolo2': 'uniform(-3, 3, shape=(2,), discrete=True)',
            'yolo3': 'norm(0.9)',
            'yolo4': 'choices([\'asdfa\', 2])'}
github Epistimio / orion / tests / unittests / algo / test_space.py View on Github external
def test_cardinality(self):
        """Check whether space capacity is correct"""
        space = Space()
        probs = (0.1, 0.2, 0.3, 0.4)
        categories = ('asdfa', 2, 3, 4)
        dim = Categorical('yolo', OrderedDict(zip(categories, probs)), shape=2)
        space.register(dim)
        dim = Integer('yolo2', 'uniform', -3, 6)
        space.register(dim)
        dim = Fidelity('epoch', 1, 9, 3)
        space.register(dim)

        assert (4 * 2) * 6 * 1 == space.cardinality

        dim = Integer('yolo3', 'uniform', -3, 2, shape=(3, 1))
        space.register(dim)
        assert (4 * 2) * 6 * 1 * (2 * 3 * 1) == space.cardinality

        dim = Real('yolo4', 'norm', 0.9)
github Epistimio / orion / tests / unittests / algo / test_space.py View on Github external
def test_order(self):
        """Test that the same space built twice will have the same ordering."""
        space1 = Space()
        space1.register(Integer('yolo1', 'uniform', -3, 6, shape=(2,)))
        space1.register(Integer('yolo2', 'uniform', -3, 6, shape=(2,)))
        space1.register(Real('yolo3', 'norm', 0.9))
        space1.register(Categorical('yolo4', ('asdfa', 2)))

        space2 = Space()
        space2.register(Integer('yolo1', 'uniform', -3, 6, shape=(2,)))
        space2.register(Real('yolo3', 'norm', 0.9))
        space2.register(Categorical('yolo4', ('asdfa', 2)))
        space2.register(Integer('yolo2', 'uniform', -3, 6, shape=(2,)))

        assert list(space1) == list(space1.keys())
        assert list(space2) == list(space2.keys())
        assert list(space1.values()) == list(space2.values())
        assert list(space1.items()) == list(space2.items())
        assert list(space1.keys()) == list(space2.keys())
github Epistimio / orion / tests / unittests / algo / test_space.py View on Github external
def test_order(self):
        """Test that the same space built twice will have the same ordering."""
        space1 = Space()
        space1.register(Integer('yolo1', 'uniform', -3, 6, shape=(2,)))
        space1.register(Integer('yolo2', 'uniform', -3, 6, shape=(2,)))
        space1.register(Real('yolo3', 'norm', 0.9))
        space1.register(Categorical('yolo4', ('asdfa', 2)))

        space2 = Space()
        space2.register(Integer('yolo1', 'uniform', -3, 6, shape=(2,)))
        space2.register(Real('yolo3', 'norm', 0.9))
        space2.register(Categorical('yolo4', ('asdfa', 2)))
        space2.register(Integer('yolo2', 'uniform', -3, 6, shape=(2,)))

        assert list(space1) == list(space1.keys())
        assert list(space2) == list(space2.keys())
        assert list(space1.values()) == list(space2.values())
        assert list(space1.items()) == list(space2.items())
        assert list(space1.keys()) == list(space2.keys())
        assert list(space1.values()) == list(space2.values())
        assert list(space1.items()) == list(space2.items())
github Epistimio / orion / tests / unittests / algo / test_tpe.py View on Github external
def test_split_trials(self, tpe):
        """Test observed trials can be split based on TPE gamma"""
        space = Space()
        dim1 = Real('yolo1', 'uniform', -3, 6)
        space.register(dim1)

        tpe.space = space

        points = numpy.linspace(-3, 3, num=10, endpoint=False)
        results = numpy.linspace(0, 1, num=10, endpoint=False)
        points_results = list(zip(points, results))
        numpy.random.shuffle(points_results)
        points, results = zip(*points_results)
        for point, result in zip(points, results):
            tpe.observe([[point]], [{'objective': result}])

        tpe.gamma = 0.25
        below_points, above_points = tpe.split_trials()
github Epistimio / orion / tests / unittests / core / test_transformer.py View on Github external
def space(dim, dim2):
    """Create an example `Space`."""
    space = Space()
    space.register(dim)
    space.register(dim2)
    return space
github Epistimio / orion / src / orion / core / io / space_builder.py View on Github external
Using information from the user's script configuration (if provided) and the
        command line arguments, will create a `Space` object defining the problem's
        search space.

        Parameters
        ----------
        configuration: OrderedDict
            An OrderedDict containing the name and the expression of the parameters.

        Returns
        -------
        `orion.algo.space.Space`
            The problem's search space definition.

        """
        self.space = Space()
        for namespace, expression in configuration.items():
            if _should_not_be_built(expression):
                continue

            expression = _remove_marker(expression)
            dimension = self.dimbuilder.build(namespace, expression)

            try:
                self.space.register(dimension)
            except ValueError as exc:
                error_msg = 'Conflict for name \'{}\' in parameters'.format(namespace)
                raise ValueError(error_msg) from exc

        return self.space