Example #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)
Example #2
0
    def test_build_run_pipeline(self):
        plx_file = PolyaxonFile(
            os.path.abspath("tests/fixtures/pipelines/build_run_pipeline.yml"))
        spec = plx_file.specification
        spec = spec.apply_context()
        assert len(spec.workflow_strategy.ops) == 2
        assert spec.workflow_strategy.ops[0].name == "build"
        assert spec.workflow_strategy.ops[1].name == "run"
        assert spec.config.workflow is not None
        assert spec.has_dag is True
        assert spec.has_pipeline is True
        assert spec.config.schedule is None
        assert len(spec.workflow_strategy.components) == 2
        assert spec.workflow_strategy.components[
            0].name == "experiment-template"
        assert spec.workflow_strategy.components[0].container.to_dict() == {
            "image": "{{ image }}",
            "command": ["python3", "main.py"],
            "args": "--lr={{ lr }}",
        }
        assert spec.workflow_strategy.components[1].name == "build-template"
        assert spec.workflow_strategy.components[1].container.to_light_dict(
        ) == {
            "image": "base"
        }
        assert spec.workflow_strategy.components[1].init.build.to_light_dict(
        ) == {
            "image": "base",
            "env": "{{ env_vars }}",
            "name": POLYAXON_DOCKERFILE_NAME,
            "workdir": POLYAXON_DOCKER_WORKDIR,
            "shell": POLYAXON_DOCKER_SHELL,
        }

        # Create a an op spec
        spec.workflow_strategy.set_op_component("run")
        assert spec.workflow_strategy.ops[1].component is not None
        job_spec = OpSpecification(spec.workflow_strategy.ops[1].to_dict())
        assert job_spec.config.params == {
            "image": "{{ ops.build.outputs.docker-image }}",
            "lr": 0.001,
        }
        op_spec = get_specification(job_spec.generate_run_data())
        assert op_spec.is_component is True
        op_spec.apply_params({"image": "foo", "lr": 0.001})
        op_spec = op_spec.apply_context()
        op_spec = op_spec.apply_container_contexts()
        assert op_spec.config.container.to_dict() == {
            "image": "foo",
            "command": ["python3", "main.py"],
            "args": "--lr=0.001",
        }
Example #3
0
    def test_op_specification_with_override_info(self):
        config_dict = {
            "version": 0.6,
            "kind": "op",
            "name": "foo",
            "description": "a description",
            "tags": ["value"],
            "component_ref": {"name": "foo"},
            "params": {"param1": "foo", "param2": "bar"},
            "trigger": "all_succeeded",
            "component": {
                "name": "build-template",
                "tags": ["kaniko"],
                "init": {"repos": [{"name": "foo", "branch": "dev"}]},
                "container": {"image": "test"},
            },
        }
        spec = OpSpecification.read(values=config_dict)
        assert spec.name == "foo"
        assert spec.description == "a description"
        assert spec.tags == ["value"]

        run_data = spec.generate_run_data()
        job_spec = get_specification(run_data)
        assert job_spec.config.name == "foo"
        assert job_spec.config.description == "a description"
        assert job_spec.tags == ["value"]
        assert job_spec.init.to_light_dict() == {
            "repos": [{"name": "foo", "branch": "dev"}]
        }
        assert job_spec.environment is None

        env = {
            "environment": {
                "resources": {
                    "requests": {"gpu": 1, "tpu": 1},
                    "limits": {"gpu": 1, "tpu": 1},
                }
            }
        }
        run_data = spec.generate_run_data(env)
        job_spec = get_specification(run_data)
        assert job_spec.environment.to_light_dict() == env["environment"]
Example #4
0
 def test_job_specification_raises_for_missing_container_section(self):
     with self.assertRaises(PolyaxonfileError):
         OpSpecification.read(
             os.path.abspath("tests/fixtures/plain/job_missing_container.yml")
         )