Exemplo n.º 1
0
"""Tests for citrine.informatics.processors serialization."""
import pytest

from citrine.informatics.processors import Processor, GridProcessor, EnumeratedProcessor, \
    MonteCarloProcessor


@pytest.fixture(params=[
    MonteCarloProcessor("test", "mc optimizer test"),
    EnumeratedProcessor("test", "test_enumeration", max_size=64),
    GridProcessor("test", "test_grid", grid_sizes={
        "foo": 2,
        "bar": 5
    })
])
def processor(request):
    return request.param


def test_deser_from_parent(processor):
    # Serialize and deserialize the processor, making sure they are round-trip serializable
    data = processor.dump()
    data.update({"status": "READY"})
    deserialized = Processor.build(data)
    assert processor == deserialized
    "{} passed!".format(processor)  # check str method


def test_invalid_eq(processor):
    other = None
    assert not processor == other
Exemplo n.º 2
0
from citrine.informatics.design_spaces import ProductDesignSpace, EnumeratedDesignSpace
from citrine.informatics.objectives import ScalarMaxObjective, ScalarMinObjective
from citrine.informatics.processors import GridProcessor, EnumeratedProcessor
from citrine.informatics.scores import LIScore, EIScore
from citrine.informatics.reports import ModelSummary, FeatureImportanceReport

informatics_string_data = [
    (ScalarRangeConstraint('z'), "<ScalarRangeConstraint 'z'>"),
    (CategoricalConstraint('x', []), "<CategoricalConstraint 'x'>"),
    (ProductDesignSpace('my design space', 'does some things',
                        []), "<ProductDesignSpace 'my design space'>"),
    (EnumeratedDesignSpace('enumerated', 'desc', [],
                           []), "<EnumeratedDesignSpace 'enumerated'>"),
    (ScalarMaxObjective('z', 1.0, 10.0), "<ScalarMaxObjective 'z'>"),
    (ScalarMinObjective('z', 1.0, 10.0), "<ScalarMinObjective 'z'>"),
    (GridProcessor('my thing', 'does a thing',
                   dict(x=1)), "<GridProcessor 'my thing'>"),
    (EnumeratedProcessor('my enumerated thing', 'enumerates',
                         10), "<EnumeratedProcessor 'my enumerated thing'>"),
    (LIScore("LI(z)", "score for z", [], []), "<LIScore 'LI(z)'>"),
    (EIScore("EI(x)", "score for x", [], [], []), "<EIScore 'EI(x)'>"),
    (FeatureImportanceReport("reflectivity",
                             {}), "<FeatureImportanceReport 'reflectivity'>"),
    (ModelSummary("my model", "ML Model", [], [], {}, [],
                  "predictor name"), "<ModelSummary 'my model'>"),
]


@pytest.mark.parametrize('obj,repr', informatics_string_data)
def test_str_representation(obj, repr):
    assert str(obj) == repr
Exemplo n.º 3
0
def test_grid_serialization(valid_grid_data):
    """Ensure a serialized GridProcessor looks sane."""
    processor: GridProcessor = GridProcessor.build(valid_grid_data)
    serialized = processor.dump()
    serialized['id'] = valid_grid_data['id']
    assert serialized == valid_serialization_output(valid_grid_data)
def grid_processor() -> GridProcessor:
    """Build a GridProcessor for testing."""
    return GridProcessor('my thing', 'does a thing', dict(x=1))
Exemplo n.º 5
0
def test_simple_grid_deserialization(valid_grid_data):
    """Ensure a deserialized GridProcessor looks sane."""
    processor: GridProcessor = GridProcessor.build(valid_grid_data)
    assert processor.name == 'my processor'
    assert processor.description == 'does some things'
    assert processor.grid_sizes == dict(x=5, y=10)