예제 #1
0
    def test_incomplete_params(self):
        config_dict = {
            'params': {
                'param1': 1,
            },
            'inputs': [
                {'name': 'param1', 'type': IOTypes.INT},
                {'name': 'param2', 'type': IOTypes.INT},
            ]
        }
        config = BaseOpConfig.from_dict(config_dict)
        with self.assertRaises(ValidationError):
            ops_params.validate_params(params=config.params,
                                       inputs=config.inputs,
                                       outputs=config.outputs,
                                       is_template=False,
                                       is_run=True)

        config_dict = {
            'params': {
                'param1': 1,
            },
            'outputs': [
                {'name': 'param1', 'type': IOTypes.INT, 'default': 12, 'is_optional': True},
                {'name': 'param2', 'type': IOTypes.INT},
            ]
        }
        config = BaseOpConfig.from_dict(config_dict)
        ops_params.validate_params(params=config.params,
                                   inputs=config.inputs,
                                   outputs=config.outputs,
                                   is_template=False,
                                   is_run=True)
예제 #2
0
    def process_templates(self):
        if not self.templates:
            raise PolyaxonSchemaError(
                'Pipeline is not valid, '
                'it has no templates to validate operations.')

        if not self.ops:
            raise PolyaxonSchemaError('Pipeline is not valid, '
                                      'it has no ops to validate operations.')

        for template in self.templates:
            template_name = template.name
            if template_name in self._template_by_names:
                raise PolyaxonSchemaError(
                    'Pipeline has multiple templates with the same name `{}`'.
                    format(template_name))
            self._template_by_names[template_name] = template

        for op in self.ops:
            op_name = op.name
            template_name = op.template.name
            if op_name in self._op_template_mapping:
                raise PolyaxonSchemaError(
                    'Pipeline has multiple ops with the same name `{}`'.format(
                        op_name))

            if template_name not in self._template_by_names:
                raise PolyaxonSchemaError(
                    'Pipeline op with name `{}` requires a template with name `{}`, '
                    'which is not defined on this pipeline.'.format(
                        op_name, template_name))

            self._op_template_mapping[op_name] = template_name
            outputs = self._template_by_names[template_name].outputs
            if not outputs:
                continue
            for output in outputs:
                self._context['ops.{}.outputs.{}'.format(op_name,
                                                         output.name)] = output

        for op in self.ops:
            template = self._template_by_names[self._op_template_mapping[
                op.name]]
            ops_params.validate_params(params=op.params,
                                       inputs=template.inputs,
                                       outputs=template.outputs,
                                       context=self._context,
                                       is_template=False,
                                       is_run=False)
예제 #3
0
 def __init__(self,
              version=None,
              kind=None,
              logging=None,
              name=None,
              description=None,
              tags=None,
              environment=None,
              params=None,
              declarations=None,
              inputs=None,
              outputs=None):
     self.version = version
     self.kind = kind
     self.logging = logging
     self.name = name
     self.description = description
     self.tags = tags
     self.environment = environment
     validate_declarations({'params': params, 'declarations': declarations})
     self.params = params or declarations
     self._validated_params = ops_params.validate_params(params=self.params,
                                                         inputs=inputs,
                                                         outputs=outputs,
                                                         is_template=True,
                                                         is_run=True)
     self.inputs = inputs
     self.outputs = outputs
예제 #4
0
    def test_required_input_no_param_only_validated_on_run(self):
        # Inputs
        config_dict = {
            'params': {
                'param1': 'text',
            },
            'inputs': [
                {'name': 'param1', 'type': IOTypes.STR},
                {'name': 'param10', 'type': IOTypes.PATH},
            ]
        }
        config = BaseOpConfig.from_dict(config_dict)
        with self.assertRaises(ValidationError):
            ops_params.validate_params(params=config.params,
                                       inputs=config.inputs,
                                       outputs=config.outputs,
                                       is_template=False,
                                       is_run=True)

        # Outputs
        config_dict = {
            'params': {
                'param1': 'text',
            },
            'outputs': [
                {'name': 'param1', 'type': IOTypes.STR},
                {'name': 'param10', 'type': IOTypes.PATH},
            ]
        }
        config = BaseOpConfig.from_dict(config_dict)

        ops_params.validate_params(params=config.params,
                                   inputs=config.inputs,
                                   outputs=config.outputs,
                                   is_template=False,
                                   is_run=True)

        # IO
        config_dict = {
            'params': {
                'param1': 'text',
            },
            'inputs': [
                {'name': 'param1', 'type': IOTypes.STR},
            ],
            'outputs': [
                {'name': 'param10', 'type': IOTypes.PATH},
            ]
        }
        config = BaseOpConfig.from_dict(config_dict)
        ops_params.validate_params(params=config.params,
                                   inputs=config.inputs,
                                   outputs=config.outputs,
                                   is_template=False,
                                   is_run=True)
예제 #5
0
 def validate_params(self, values):
     ops_params.validate_params(params=values.get('params'),
                                inputs=values.get('inputs'),
                                outputs=values.get('outputs'),
                                is_template=True,
                                is_run=True)