Пример #1
0
class CheckpointsConfig(BaseConfig):
    validation_steps: Union[confloat(gt=0.0, le=1.0), PositiveInt] = 1.0
    """How often within one training epoch to check the validation set.
    If float, % of training epoch. If int, check every n batches."""

    save_top_k: int = 1
    """Save and keep only ``k`` best models according to main metric;
    -1 will keep all; 0 will never save a model."""

    early_stop_patience: conint(ge=0) = 0
    """Stop training if evaluation metrics do not improve after X validations;
Пример #2
0
    class Config(BaseModel):

        buffer_size: int = None
        """Number of consecutive instances to be temporarily stored in
        the buffer, which will be used later for batching/bucketing."""

        train: Optional[TrainingConfig] = None
        valid: Optional[TrainingConfig] = None
        test: Optional[TestConfig] = None

        split: Optional[confloat(gt=0.0, lt=1.0)] = None
        """Split train dataset in case that no validation set is given."""
        @validator('split', pre=True, always=True)
        def ensure_there_is_validation_data(cls, v, values):
            if v is None and values.get('valid') is None:
                raise ValueError(
                    'In data configuration: must specify a `split` value in (0.0, 1.0) '
                    'or pass options for validation data using `valid.*`.')
            return v
Пример #3
0
    base_schema = {
        'title': 'Model',
        'type': 'object',
        'properties': {'a': {'title': 'A', 'type': 'integer'}},
        'required': ['a'],
    }
    base_schema['properties']['a'].update(expected_schema)

    assert Model.schema() == base_schema


@pytest.mark.parametrize(
    'field_type,expected_schema',
    [
        (ConstrainedFloat, {}),
        (confloat(gt=5, lt=10), {'exclusiveMinimum': 5, 'exclusiveMaximum': 10}),
        (confloat(ge=5, le=10), {'minimum': 5, 'maximum': 10}),
        (confloat(multiple_of=5), {'multipleOf': 5}),
        (PositiveFloat, {'exclusiveMinimum': 0}),
        (NegativeFloat, {'exclusiveMaximum': 0}),
        (ConstrainedDecimal, {}),
        (condecimal(gt=5, lt=10), {'exclusiveMinimum': 5, 'exclusiveMaximum': 10}),
        (condecimal(ge=5, le=10), {'minimum': 5, 'maximum': 10}),
        (condecimal(multiple_of=5), {'multipleOf': 5}),
    ],
)
def test_special_float_types(field_type, expected_schema):
    class Model(BaseModel):
        a: field_type

    base_schema = {
Пример #4
0
                'title': 'A',
                'type': 'integer'
            }
        },
        'required': ['a'],
    }
    base_schema['properties']['a'].update(expected_schema)

    assert Model.schema() == base_schema


@pytest.mark.parametrize(
    'field_type,expected_schema',
    [
        (ConstrainedFloat, {}),
        (confloat(gt=5, lt=10), {
            'exclusiveMinimum': 5,
            'exclusiveMaximum': 10
        }),
        (confloat(ge=5, le=10), {
            'minimum': 5,
            'maximum': 10
        }),
        (PositiveFloat, {
            'exclusiveMinimum': 0
        }),
        (NegativeFloat, {
            'exclusiveMaximum': 0
        }),
        (ConstrainedDecimal, {}),
        (condecimal(gt=5, lt=10), {
Пример #5
0
                'title': 'A',
                'type': 'integer'
            }
        },
        'required': ['a'],
    }
    base_schema['properties']['a'].update(expected_schema)

    assert Model.schema() == base_schema


@pytest.mark.parametrize(
    'field_type,expected_schema',
    [
        (ConstrainedFloat, {}),
        (confloat(gt=5, lt=10), {
            'exclusiveMinimum': 5,
            'exclusiveMaximum': 10
        }),
        (confloat(ge=5, le=10), {
            'minimum': 5,
            'maximum': 10
        }),
        (confloat(multiple_of=5), {
            'multipleOf': 5
        }),
        (PositiveFloat, {
            'exclusiveMinimum': 0
        }),
        (NegativeFloat, {
            'exclusiveMaximum': 0
Пример #6
0
class LegendConfig(BaseModel):
    """Config for the legend to be created from a dataset."""
    class Config:
        validate_all = True
        validate_assignment = True

    color_set: ColorSets = Field(
        ColorSets.ecotect,
        description=
        'Color set to be used on data and legend. Currently, this field'
        ' only uses Ladybug color sets. Defaults to using ecotect colorset.')

    min: Union[Autocalculate, float] = Field(
        Autocalculate(),
        description=
        'Minimum value for the legend. Also known as the lower end of the'
        ' legend. If min and max values are not specified, autocalculated min and max'
        ' values will be used from data.')

    max: Union[Autocalculate, float] = Field(
        Autocalculate(),
        description=
        'Maximum value for the legend. Also known as the higher end of the'
        ' legend. If min and max values are not specified, autocalculated min and max'
        ' values will be used from data.')

    hide_legend: bool = Field(
        False,
        description=
        'A bool value to indicate whether to show legend in the exported'
        ' images or not.')

    orientation: Orientation = Field(
        Orientation.vertical,
        description=
        'Choose between horizontal and vertical orientation of legend.')

    width: confloat(ge=0.05, le=0.95) = Field(
        0.05,
        description=
        ' A decimal number representing the fraction of viewport width'
        ' that will be used to define the width of the legend.')

    height: confloat(ge=0.05, le=0.95) = Field(
        0.45,
        description=
        'A decimal number representing the fraction of viewport height'
        'that will be used to define the height of the legend.')

    position: conlist(confloat(
        ge=0.05, le=0.95), min_items=2, max_items=2) = Field(
            [0.9, 0.5],
            description=
            'A tuple of two decimal values. The values represent the fraction'
            ' of viewport width and the fraction of viewport height.')

    color_count: Union[Autocalculate, int] = Field(
        Autocalculate(),
        description=
        'An integer representing the number of colors in a legend. If not'
        ' specified, it defaults to the number of colors in a Ladybug color set.'
    )

    label_count: Union[Autocalculate, int] = Field(
        Autocalculate(),
        description=
        'An integer representing the number of text labels on a legend.'
        ' Label count will have to be less than or equal to color count. It defaults'
        ' to vtk scalarbar default setting.')

    decimal_count: DecimalCount = Field(
        DecimalCount.default,
        description=
        'Controlling the number of decimals on each label of the legend.'
        'Accepted values are "default", "integer", "decimal_two", and "decimal_three".'
        'Defaults to VTKs default settings.')

    preceding_labels: bool = Field(
        False,
        description='Boolean value to decide whether the legend title and the'
        ' legend labels will precede the legend or not.')

    label_parameters: TextConfig = Field(
        TextConfig(),
        description='Text parameters for the labels on the legend.')

    title_parameters: TextConfig = Field(
        TextConfig(bold=True),
        description='Text parameters for the title of the legend.')
Пример #7
0
def unitfloat(unit: str, **kwargs) -> Type[float]:
    namespace = dict(unit=unit)
    confloat_t = confloat(**kwargs)
    return type("UnitFloat", (confloat_t, ), namespace)