コード例 #1
0
    def __init__(self, name, minimum, maximum):
        """
        Constructor.

        :param name: The name of the column in the data
            view to which this constraint should be applied
        :type name: str
        :param minimum: The minimum allowed value
        :type minimum: float
        :param maximum: The maximum allowed value
        :type maximum: float
        """

        try:
            minimum_f = float(minimum)
            maximum_f = float(maximum)
        except TypeError:
            raise CitrinationClientError("RealRangeConstraint requires that minimum and maximum must be able to be cast to float")

        if minimum_f > maximum_f:
            raise CitrinationClientError("RealRangeConstraint requires that minimum be less than maximum")

        self._min = minimum_f
        self._max = maximum_f
        self._type = "real"
        self._name = name
コード例 #2
0
    def validate(self):
        categories = self.options['descriptor_values']
        if type(categories) is not list:
            raise CitrinationClientError(
                "CategoricalColumn requires that the categories value is a list of strings"
            )

        if not all(isinstance(item, string_types) for item in categories):
            raise CitrinationClientError(
                "CategoricalColumn requires that the categories value is a list of strings"
            )
コード例 #3
0
 def length(self, value):
     try:
         self._length = int(value)
     except ValueError:
         raise CitrinationClientError(
             "When constructing a VectorColumn, parameter length must be castable as an int"
         )
コード例 #4
0
 def _cast_and_validate_float(self, value, attr_name):
     try:
         return float(value)
     except ValueError:
         raise CitrinationClientError(
             "For a RealColumn, {} must be castable as a float".format(
                 attr_name))
コード例 #5
0
    def _validate_search_query(self, returning_query):
        """
        Checks to see that the query will not exceed the max query depth

        :param returning_query: The PIF system or Dataset query to execute.
        :type returning_query: :class:`PifSystemReturningQuery` or :class: `DatasetReturningQuery`
        """

        start_index = returning_query.from_index or 0
        size = returning_query.size or 0

        if start_index < 0:
            raise CitrinationClientError(
                "start_index cannot be negative. Please enter a value greater than or equal to zero")
        if size < 0:
            raise CitrinationClientError("Size cannot be negative. Please enter a value greater than or equal to zero")
        if start_index + size > MAX_QUERY_DEPTH:
            raise CitrinationClientError(
                "Citrination does not support pagination past the {0}th result. Please reduce either the from_index and/or size such that their sum is below {0}".format(
                    MAX_QUERY_DEPTH))
コード例 #6
0
    def __init__(self, name, elements, minimum, maximum):
        """
        Constructor.

        :param name: The name of the column in the data
            view to which this constraint should be applied
        :type name: str
        :param elements: An array of element abbreviations as
            strings, e.g. ["Mg", "C"]
        :type elements: list of str
        :param minimum: The minimum value (<= 100) as a percentage
            at which the specified elements should appear in
            candidate compositions
        :type minimum: float
        :param maximum: The maximum value (<= 100) as a percentage
            at which the specified elements should appear in
            candidate compositions
        :type maximum: float
        """
        if not 0 <= minimum <= 100:
            raise CitrinationClientError(
                "ElementalCompositionConstraint requires that minimum be between 0 and 100"
            )

        if not 0 <= maximum <= 100:
            raise CitrinationClientError(
                "ElementalCompositionConstraint requires that maximum be between 0 and 100"
            )

        if not maximum >= minimum:
            raise CitrinationClientError(
                "ElementalCompositionConstraint requires that maximum be greater than minimum"
            )

        self._type = "elementalCompositionConstraint"
        self._elements = elements
        self._name = name
        self._min = minimum
        self._max = maximum
コード例 #7
0
    def submit_design_run(self,
                          data_view_id,
                          num_candidates,
                          effort,
                          target=None,
                          constraints=[],
                          sampler="Default"):
        """
        Submits a new experimental design run

        :param data_view_id: The ID number of the data view to which the
            run belongs, as a string
        :type data_view_id: str
        :param num_candidates: The number of candidates to return
        :type num_candidates: int
        :param target: An :class:``Target`` instance representing
            the design run optimization target
        :type target: :class:``Target``
        :param constraints: An array of design constraints (instances of
            objects which extend :class:``BaseConstraint``)
        :type constraints: list of :class:``BaseConstraint``
        :param sampler: The name of the sampler to use during the design run:
            either "Default" or "This view"
        :type sampler: str
        :return: A :class:`DesignRun` instance containing the UID of the
            new run
        """

        if effort > 30:
            raise CitrinationClientError(
                "Parameter effort must be less than 30 to trigger a design run"
            )

        if target is not None:
            target = target.to_dict()

        constraint_dicts = [c.to_dict() for c in constraints]

        body = {
            "num_candidates": num_candidates,
            "target": target,
            "effort": effort,
            "constraints": constraint_dicts,
            "sampler": sampler
        }

        url = routes.submit_data_view_design(data_view_id)

        response = self._post_json(url, body).json()

        return DesignRun(response["data"]["design_run"]["uid"])
コード例 #8
0
    def _validate_role(self, role):
        """
        Validates that the role parameter has a valid value.

        :param role: Name of the column's role
        :type role: str
        """
        valid_roles = [
            "Input", "Output", "Latent Variable", "Ignore", "input", "output",
            "latentVariable", "ignore"
        ]
        if role not in valid_roles:
            raise CitrinationClientError(
                "Column role must be one of: {}".format(valid_roles))
コード例 #9
0
    def __init__(self, name, objective):
        """
        Constructor.

        :param name: The name of the target output column
        :type name: str
        :param objective: The optimization objective; either "Min"
            or "Max"
        :type objective: str
        """
        if objective not in ["Max", "Min"]:
            raise CitrinationClientError(
                "Target objective must either be \"Min\" or \"Max\"")

        self._name = name
        self._objective = objective
コード例 #10
0
    def __init__(self, name, objective):
        """
        Constructor.

        :param name: The name of the target output column
        :type name: str
        :param objective: The optimization objective; "Min", "Max", or a scalar value (such as "5.0")
        :type objective: str
        """

        try:
            self._objective = float(objective)
        except ValueError:
            if objective.lower() not in ["max", "min"]:
                raise CitrinationClientError(
                    "Target objective must either be \"min\" or \"max\"")
            self._objective = objective

        self._name = name
コード例 #11
0
    def __init__(self, name, elements, logic):
        """
        Constructor.

        :param name: The name of the column in the data
            view to which this constraint should be applied
        :type name: str
        :param elements: An array of element abbreviations as
            strings, e.g. ["Mg", "C"]
        :type elements: list of str
        :param logic: The logic to apply to the constraint; either
            "must", "should", or "exclude"
        :type logic: str
        """
        bad_logic_msg = "ElementalInclusionConstraint must be initialized with the logic parameter equal to \"must\", \"should\", or \"exclude\""

        if logic not in ["must", "should", "exclude"]:
            raise CitrinationClientError(bad_logic_msg)

        self._name = name
        self._type = "elementalInclusionConstraint"
        self._elements = elements
        self._logic = logic
コード例 #12
0
 def _cast_and_validate_int(self, value, attr_name):
     try:
         return int(value)
     except ValueError:
         raise CitrinationClientError("For a IntColumn, {} must be castable as an integer".format(attr_name))
コード例 #13
0
 def _validate_bounds(self):
     if self._both_bounds_present() and self._lower_bound > self._upper_bound:
         raise CitrinationClientError("When constructing a IntColumn, lower_bound must be less than upper_bound")