Пример #1
0
    def test_non_yaml_spec(self):
        config = ",sdf;ldjks"
        with self.assertRaises(PolyaxonSchemaError):
            OpSpecification.read(config)

        with self.assertRaises(PolyaxonSchemaError):
            ComponentSpecification.read(config)
Пример #2
0
 def test_specification_with_quotes(self):
     plxfile = PolyaxonFile(
         os.path.abspath(
             "tests/fixtures/plain/polyaxonfile_with_quotes.yaml"))
     spec = plxfile.specification
     spec = spec.apply_context()
     assert spec.run.image == "continuumio/miniconda3"
     assert spec.run.command == ["python"]
     assert spec.run.args == ["-c \"print('Tweet tweet')\""]
     spec = ComponentSpecification(spec.data)
     spec = spec.apply_context()
     assert spec.run.image == "continuumio/miniconda3"
     assert spec.run.command == ["python"]
     assert spec.run.args == ["-c \"print('Tweet tweet')\""]
Пример #3
0
    def test_patch_experiment_without_io_and_params_raises(self):
        content = {
            "version": 0.6,
            "kind": "component",
            "container": {"image": "test/test:latest", "command": "train"},
        }
        spec = ComponentSpecification.read(content)
        spec = spec.apply_context()
        new_spec = ComponentSpecification.read(spec.data)
        spec = new_spec.apply_context()
        assert new_spec.data == content

        # Add params
        params = {"params": {"lr": 0.1}}
        with self.assertRaises(PolyaxonfileError):
            spec.patch(values=params)
Пример #4
0
    def test_apply_context_passes_with_required_inputs_and_params(self):
        content = {
            "version": 0.6,
            "kind": "component",
            "inputs": [
                {"name": "lr", "type": IOTypes.FLOAT},
                {"name": "num_steps", "type": IOTypes.INT},
            ],
            "container": {"image": "test/test:latest", "command": "train"},
        }
        spec = ComponentSpecification.read(content)
        # no params
        with self.assertRaises(PolyaxonfileError):
            spec.apply_context()

        params = {"lr": 0.1, "num_steps": 100}

        assert spec.config.inputs[0].value is None
        assert spec.config.inputs[1].value is None
        validated_params = spec.validate_params(params=params)
        spec.apply_params(params=params)
        assert params == {p.name: p.value for p in validated_params}
        assert spec.config.inputs[0].value == 0.1
        assert spec.config.inputs[1].value == 100

        new_spec = spec.apply_context()
        updated_content = {
            "version": 0.6,
            "kind": "component",
            "inputs": [
                {
                    "name": "lr",
                    "type": IOTypes.FLOAT,
                    "is_optional": True,
                    "value": 0.1,
                },
                {
                    "name": "num_steps",
                    "type": IOTypes.INT,
                    "is_optional": True,
                    "value": 100,
                },
            ],
            "container": {"image": "test/test:latest", "command": "train"},
        }
        assert new_spec.data == updated_content

        env = {
            "environment": {
                "resources": {
                    "requests": {"gpu": 1, "tpu": 1},
                    "limits": {"gpu": 1, "tpu": 1},
                }
            }
        }
        spec = spec.patch(values=env)
        assert spec.data["environment"] == env["environment"]
Пример #5
0
    def test_apply_context_raises_with_required_inputs(self):
        content = {
            "version":
            1.0,
            "kind":
            "component",
            "inputs": [
                {
                    "name": "lr",
                    "type": types.FLOAT
                },
                {
                    "name": "num_steps",
                    "type": types.INT
                },
            ],
            "run": {
                "kind": "container",
                "image": "test/test:latest",
                "command": "train",
            },
        }
        spec = ComponentSpecification.read(content)

        # Raise because required inputs are not met
        with self.assertRaises(PolyaxonfileError):
            spec.apply_context()

        # Validation for template should pass
        validated_params = spec.validate_params()
        assert {
            "lr": None,
            "num_steps": None
        } == {p.name: p.value
              for p in validated_params}
        # Validation for non template should raise
        with self.assertRaises(PolyaxonfileError):
            spec.validate_params(is_template=False)
Пример #6
0
    def test_patch_experiment_with_optional_inputs(self):
        content = {
            "version": 0.6,
            "kind": "component",
            "inputs": [
                {
                    "name": "lr",
                    "type": IOTypes.FLOAT,
                    "value": 0.6,
                    "is_optional": True,
                },
                {
                    "name": "num_steps",
                    "type": IOTypes.INT,
                    "value": 16,
                    "is_optional": True,
                },
            ],
            "container": {"image": "test/test:latest", "command": "train"},
        }
        spec = ComponentSpecification.read(content)
        assert spec.config.inputs[0].value == 0.6
        assert spec.config.inputs[1].value == 16
        spec = spec.apply_context()
        validated_params = spec.validate_params()
        assert {"lr": 0.6, "num_steps": 16} == {
            p.name: p.value for p in validated_params
        }
        assert spec.config.inputs[0].value == 0.6
        assert spec.config.inputs[1].value == 16

        new_spec = ComponentSpecification.read(spec.data)
        assert new_spec.data == content

        params = {"lr": 0.6, "num_steps": 16}
        new_spec.validate_params(params=params)
        new_spec.apply_context()
        assert spec.config.inputs[0].value == 0.6
        assert spec.config.inputs[1].value == 16

        with self.assertRaises(PolyaxonfileError):  # not valid
            params = {"params": {"lr": 0.1}}
            spec.patch(values=params)

        # Add env
        assert spec.environment is None
        env = {
            "environment": {
                "resources": {
                    "requests": {"gpu": 1, "tpu": 1},
                    "limits": {"gpu": 1, "tpu": 1},
                }
            }
        }
        spec = spec.patch(values=env)
        assert spec.environment.resources.to_dict() == {
            "requests": {"gpu": 1, "tpu": 1},
            "limits": {"gpu": 1, "tpu": 1},
        }

        # Patch with unsupported spec
        matrix = {"hptuning": {"matrix": {"lr": {"values": [0.1, 0.2]}}}}
        with self.assertRaises(PolyaxonfileError):
            spec.patch(values=matrix)

        # Patch with unsupported spec
        wrong_config = {"lr": {"values": [0.1, 0.2]}}
        with self.assertRaises(PolyaxonfileError):
            spec.patch(values=wrong_config)