def __init__(self, name: str, *, bounds: BaseBounds, uids: Optional[Dict[str, str]] = None, description: Optional[str] = None, tags: Optional[List[str]] = None): if uids is None: uids = dict() DataConcepts.__init__(self, GEMDConditionTemplate.typ) GEMDConditionTemplate.__init__(self, name=name, bounds=bounds, tags=tags, uids=uids, description=description)
def test_passthrough_bounds(): """Test that unspecified Bounds are accepted and set to None.""" template = ProcessTemplate('foo', conditions=[ (LinkByUID('1', '2'), None), [LinkByUID('3', '4'), None], LinkByUID('5', '6'), ConditionTemplate('foo', bounds=IntegerBounds( 0, 10)), ]) assert len(template.conditions) == 4 for _, bounds in template.conditions: assert bounds is None copied = loads(dumps(template)) assert len(copied.conditions) == 4 for _, bounds in copied.conditions: assert bounds is None from_dict = ProcessTemplate.build({ 'type': 'process_template', 'name': 'foo', 'conditions': [[ { 'scope': 'foo', 'id': 'bar', 'type': 'link_by_uid', }, None, ]], }) assert len(from_dict.conditions) == 1
def test_dependencies(): """Test that dependency lists make sense.""" attribute_bounds = RealBounds(0, 100, '') cond_template = ConditionTemplate("a condition", bounds=attribute_bounds) proc_template = ProcessTemplate("a process template", conditions=[cond_template]) assert cond_template in proc_template.all_dependencies()
def test_bounds_mismatch(): """Test that a mismatch between the attribute and given bounds throws a ValueError.""" attribute_bounds = RealBounds(0, 100, '') object_bounds = RealBounds(200, 300, '') cond_template = ConditionTemplate("a condition", bounds=attribute_bounds) with pytest.raises(ValueError): ProcessTemplate("a process template", conditions=[[cond_template, object_bounds]])
def test_dependencies(): """Test that dependency lists make sense.""" targets = [ PropertyTemplate(name="name", bounds=RealBounds(0, 1, '')), ConditionTemplate(name="name", bounds=RealBounds(0, 1, '')), ParameterTemplate(name="name", bounds=RealBounds(0, 1, '')), ] for target in targets: assert len(target.all_dependencies()) == 0, f"{type(target)} had dependencies"
def test_flatten_bounds(): """Test that flatten works when the objects contain other objects.""" bounds = CategoricalBounds(categories=["foo", "bar"]) template = ProcessTemplate( "spam", conditions=[(ConditionTemplate(name="eggs", bounds=bounds), bounds)] ) spec = ProcessSpec(name="spec", template=template) flat = flatten(spec, 'test-scope') assert len(flat) == 2, "Expected 2 flattened objects"
def test_repeated_objects(): """Test that objects aren't double counted.""" ct = ConditionTemplate(name="color", bounds=CategoricalBounds(categories=["black", "white"])) pt = ProcessTemplate(name="painting", conditions=[ct]) ps = ProcessSpec(name='painting', template=pt, conditions=Condition(name='Paint color', value=NominalCategorical("black"), template=ct ) ) assert len(recursive_flatmap(ps, lambda x: [x])) == 3
def test_fields_from_property(): """Test that several fields of the attribute are derived from the property.""" prop_template = PropertyTemplate(name="cookie eating template", bounds=IntegerBounds(0, 1000)) cond_template = ConditionTemplate(name="Hunger template", bounds=CategoricalBounds(["hungry", "full", "peckish"])) prop = Property(name="number of cookies eaten", template=prop_template, origin='measured', value=NominalInteger(27)) cond = Condition(name="hunger level", template=cond_template, origin='specified', value=NominalCategorical("hungry")) prop_and_conds = PropertyAndConditions(property=prop, conditions=[cond]) assert prop_and_conds.name == prop.name assert prop_and_conds.template == prop.template assert prop_and_conds.origin == prop.origin assert prop_and_conds.value == prop.value
from gemd.entity.template.measurement_template import MeasurementTemplate from gemd.entity.template.process_template import ProcessTemplate from gemd.entity.template.property_template import PropertyTemplate from gemd.entity.value.discrete_categorical import DiscreteCategorical from gemd.entity.value.nominal_composition import NominalComposition from gemd.entity.value.nominal_real import NominalReal from gemd.entity.value.normal_real import NormalReal from gemd.entity.value.uniform_real import UniformReal density_template = PropertyTemplate(name="Density", bounds=RealBounds(lower_bound=0, upper_bound=1.0e9, default_units='')) firing_temperature_template = ConditionTemplate(name="Firing Temperature", bounds=RealBounds( lower_bound=0, upper_bound=1.0e9, default_units='degC')) measurement_template = MeasurementTemplate("Density Measurement", properties=density_template) firing_template = ProcessTemplate(name="Firing in a kiln", conditions=(firing_temperature_template, RealBounds( lower_bound=500, upper_bound=1000, default_units='degC'))) material_template = MaterialTemplate(name="Some ceramic thing", properties=density_template)
from gemd.entity.value.normal_real import NormalReal known_properties = { "density": PropertyTemplate( name="density", bounds=RealBounds(lower_bound=0.0, upper_bound=1000.0, default_units='g / cm^3') ), "kinematic viscosity": PropertyTemplate( name="kinematic viscosity", bounds=RealBounds(lower_bound=0.0, upper_bound=10.0**40, default_units="m^2 / s") ) } known_conditions = { "temperature": ConditionTemplate( name="temperature", bounds=RealBounds(lower_bound=0.0, upper_bound=1000.0, default_units='K') ) } known_parameters = { "knob_2_setting": ParameterTemplate( name="knob_2_setting", bounds=CategoricalBounds(categories={"low", "medium", "high"}) ) } def _parse_value(val): """Example field-parsing logic.""" # If the string is complicated, split it up and try to get uncertainty and/or units if isinstance(val, str) and len(val.split()) > 1: