How to use the schematics.types function in schematics

To help you get started, we’ve selected a few schematics 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 loggi / redis-schematics / tests / test_integration.py View on Github external
def tearDown(self):
        client.delete("TestHashModel")

    @property
    def raw_value(self):
        return client.hget("TestHashModel", "TestHashModel:123")

    @property
    def stored(self):
        return json.loads(self.raw_value.decode("utf-8"))


class HashModelDynamicKeyStorageTest(BaseModelStorageTest, TestCase):
    class TestHashModel(TestModel, HashRedisMixin):
        hash_id = types.StringType(default="SubKey")

        @property
        def __set_key__(self):
            return self.__key_pattern__(self.hash_id)

    def setUp(self):
        self.TestModel = self.TestHashModel
        self.schema = self.TestModel(
            {"id": 123, "name": "Bar", "created": datetime.now(), "good_number": 42}
        )
        self.schema.set()

    def tearDown(self):
        client.delete("TestHashModel:SubKey")

    @property
github stanfordnqp / spins-b / spins / invdes / problem_graph / optplan / schema_param.py View on Github external
Attributes:
        type: Must be "parametrization.hermite_levelset".
        simulation_space: Name of simulation space to reference to generate
            the coarse grid.
        undersample: How much the coarse grid undersamples the rough grid.
        reflection_symmetry: List of booleans corresponding whether the
            structure should be symmetric about the x- and y- axes.
        init_method: Specifications on how to initialize the parametrization.
    """
    type = schema_utils.polymorphic_model_type(
        "parametrization.hermite_levelset")
    simulation_space = optplan.ReferenceType(optplan.SimulationSpaceBase)
    undersample = types.FloatType()
    init_method = optplan.ReferenceType(Initializer)
    reflection_symmetry = types.ListType(types.BooleanType())
    periods = types.ListType(types.IntType())



@optplan.register_node_type()
class DiscretePenalty(optplan.Function):
    """Defines discreteness biasing penalty function."""
    type = schema_utils.polymorphic_model_type(
        "function.discrete_penalty")


@optplan.register_node_type()
class FabricationConstraint(optplan.Function):
    """Defines fabrication constraint penalty function.

    Attributes:
github stanfordnqp / spins-b / spins / invdes / problem_graph / optplan / schema_param.py View on Github external
oversample: Oversample the fine grid by this value to evaluate the penalty.
        method:
                gap: only applies the gap constraint,
                curv: only apply the curvature constraint,
                gapAndCurve: apply the gap and curvature constraint.
        apply_weights: To meet the constraint you typically need to go for a slightly more
            stringent gap and curvature values. If true then weigth factor are applied that
            take care of this.(default: True)
    """
    type = schema_utils.polymorphic_model_type(
        "function.fabrication_constraint")
    minimum_curvature_diameter = types.FloatType()
    minimum_gap = types.FloatType()
    simulation_space = optplan.ReferenceType(optplan.SimulationSpaceBase)
    method = types.StringType(choices=("gap", "curv", "gap_and_curve"))
    apply_factors = types.BooleanType()
github stanfordnqp / spins-b / spins / invdes / problem_graph / optplan / schema_opt.py View on Github external
"""Defines an optimizer carried out by `PenaltyOptimizer`.

    Attributes:
        mu0: initial mu, i.e. the weight factor for the penalty term.
        tau: exponent by which mu is increased.
        pf: exponent over the penalty function.
        num_cycles: number of suboptimization with an increased mu.
        ftol: (As explained in the scipy minimize documentation)
        gtol: (As explained in the scipy minimize documentation)
        maxiter: maximum iteration in one suboptimization.
    """
    mu0 = types.FloatType()
    tau = types.FloatType()
    pf = types.FloatType()
    num_cycles = types.IntType()
    maxiter = types.IntType()
    ftol = types.FloatType()
    gtol = types.FloatType()


class ScipyOptimizerMonitorList(schema_utils.Model):
    """Defines an optimizer carried out by `ScipyOptimizer`.

    Attributes:
        callback_monitors: monitors evaluated every iteration
        start_monitors: monitors evaluated at the transformation start
        end_monitors: monitors evaluated at the transformation end

    """
    callback_monitors = types.ListType(optplan.ReferenceType(optplan.Monitor))
    start_monitors = types.ListType(optplan.ReferenceType(optplan.Monitor))
    end_monitors = types.ListType(optplan.ReferenceType(optplan.Monitor))
github jmcarp / betfair.py / betfair / meta / types.py View on Github external
# -*- coding: utf-8 -*-

from schematics import types
from schematics.exceptions import ConversionError
from schematics.exceptions import ValidationError


class DateTimeType(types.DateTimeType):

    DEFAULT_FORMATS = (
        '%Y-%m-%dT%H:%M:%S.%f',
        '%Y-%m-%dT%H:%M:%S.%fZ',
        '%Y-%m-%dT%H:%M:%S',
    )


class EnumType(types.BaseType):

    MESSAGES = {'choices': u'Value must belong to enum {0}.'}

    def __init__(self, enum, *args, **kwargs):
        super(EnumType, self).__init__(*args, **kwargs)
        self.enum = enum
github stanfordnqp / spins-b / spins / invdes / problem_graph / optplan / schema_opt.py View on Github external
Attributes:
        type: Must be "penalty_optimizer".
        optimizer: Name of optimizer.
        objective: Name of objective function.
        constraints_eq: List of names of equality constraint functions.
        constraints_ineq: List of names of inequality constraint functions.
        monitor_lists: List of names of monitors to trigger at certain events.
        optimization_options: Options to use for the optimization.
    """
    type = schema_utils.polymorphic_model_type("penalty_optimizer")
    optimizer = types.StringType()
    objective = optplan.ReferenceType(optplan.Function)
    constraints_eq = types.ListType(optplan.ReferenceType(optplan.Function))
    constraints_ineq = types.ListType(optplan.ReferenceType(optplan.Function))
    monitor_lists = types.ModelType(ScipyOptimizerMonitorList)
    optimization_options = types.ModelType(PenaltyOptimizerOptions)


@optplan.register_node_type(optplan.NodeMetaType.TRANSFORMATION)
class CubicParamSigmoidStrength(optplan.TransformationBase):
    """Changes the strength of the sigmoid function in `CubicParametrization`.

    `CubicParametrization` applies a sigmoid function after cubic interpolation
    to make the structure more discrete. This transformation changes the
    parameter in the sigmoid function, effectively changing how discrete the
    structure becomes. In the limit as the value tends to infinity, the sigmoid
    function becomes a step function (i.e. perfectly discrete structure).

    Attributes:
        value: Value for sigmoid function.
    """
github PermaData / rill / rill / engine / types.py View on Github external
def is_schematics_obj(obj):
        bases = (schematics.types.BaseType, schematics.models.Model)
        return (isinstance(obj, schematics.types.BaseType) or
                (inspect.isclass(obj) and issubclass(obj, bases)))
github stanfordnqp / spins-b / spins / invdes / problem_graph / optplan / schema_em.py View on Github external
"""Represents a plane wave source.

    Attributes:
        type: Must be "source.plane_wave".
    """
    type = schema_utils.polymorphic_model_type("source.plane_wave")
    center = optplan.vec3d()
    extents = optplan.vec3d()
    normal = optplan.vec3d()
    theta = types.FloatType()
    psi = types.FloatType()
    polarization_angle = types.FloatType()
    overwrite_bloch_vector = types.BooleanType()
    border = types.ListType(types.FloatType())
    power = types.FloatType()
    normalize_by_sim = types.BooleanType(default=False)


@optplan.register_node_type()
class GaussianSource(optplan.EmSource):
    """Represents a gaussian source.

    Attributes:
        type: Must be "source.gaussian_beam".
        normalize_by_sim: If `True`, normalize the power by running a
            simulation.
    """
    type = schema_utils.polymorphic_model_type("source.gaussian_beam")
    w0 = types.FloatType()
    center = optplan.vec3d()
    beam_center = optplan.vec3d()
    extents = optplan.vec3d()
github stanfordnqp / spins-b / spins / invdes / problem_graph / optplan / schema_param.py View on Github external
"""Represents a initializer."""


@optplan.register_node_type()
class UniformInitializer(Initializer):
    """Initializes parametrization uniformly at random.

    The parametrization values are initialized element-wise.

    Attributes:
        min_val: Minimum value of distribution.
        max_val: Maximum value of distribution.
    """
    type = schema_utils.polymorphic_model_type("initializer.uniform_random")
    min_val = types.FloatType()
    max_val = types.FloatType()


@optplan.register_node_type()
class NormalInitializer(Initializer):
    """Initializes parametrization using normal distribution.

    The parametrization values are initialized element-wise by a normal
    distribution.

    Attributes:
        mean: Mean value of the normal distribution.
        std: Standard deviation value of the normal distribution.
    """
    type = schema_utils.polymorphic_model_type("initializer.normal")
    mean = types.FloatType()
    std = types.FloatType()
github mattdennewitz / baseball-projection-schematics / projnorm / models.py View on Github external
from __future__ import unicode_literals

from schematics import models, types


#
# configuration layout
#

class ConfigComponentMap(models.Model):
    batting = types.compound.ListType(types.StringType())
    pitching = types.compound.ListType(types.StringType())


class ConfigSchematic(models.Model):
    "Schematic for schema generation configuration"

    components = types.compound.ModelType(ConfigComponentMap)


#
# schematic layout
#

class Component(models.Model):
    key = types.StringType()