def apply_content(self): try: self.compiled_operation = CompiledOperationSpecification.apply_context( self.compiled_operation) except Exception as e: raise PolyaxonCompilerError( "Could not apply run context, error: {}".format(repr(e)))
def test_create_run_with_job_spec(self): config_dict = get_fxt_job() spec = OperationSpecification.read(values=config_dict) run = compile_operation_run(project_id=self.project.id, user_id=self.user.id, op_spec=spec) assert run.kind == V1RunKind.JOB assert run.name == "foo" assert run.description == "a description" assert set(run.tags) == {"tag1", "tag2"} # Check compiled operation passes compiled_operation = CompiledOperationSpecification.read(run.content) compiled_operation = CompiledOperationSpecification.apply_params( compiled_operation) CompiledOperationSpecification.apply_run_contexts(compiled_operation, ) # Check job job_spec = CompiledOperationSpecification.read(run.content) assert job_spec.run.container.image == "test" job_spec = CompiledOperationSpecification.apply_context(job_spec) assert job_spec.run.container.image == "test"
def _run(ctx, name, owner, project_name, description, tags, specification, log): docker = DockerOperator() if not docker.check(): raise PolyaxonException("Docker is required to run this command.") # Create Build project = "{}.{}".format(owner, project_name) build_job = Run(project=project) specification = CompiledOperationSpecification.apply_context(specification) content = specification.to_dict(dump=True) build_job.create(name=name, description=description, tags=tags, content=content) image = _create_docker_build(build_job, specification, project) experiment = Run(project=project) experiment.create(name=name, tags=tags, description=description, content=content) cmd_args = ["run", "--rm"] data_paths, bind_mounts = _get_data_bind_mounts(specification.data_refs) for key, value in _get_env_vars( project=project, experiment_id=experiment.experiment_id, params=specification.params, data_paths=data_paths, ): cmd_args += ["-e", "{key}={value}".format(key=key, value=value)] cmd_args += _get_config_volume() cmd_args += _get_data_volumes(bind_mounts) cmd_args += [image] # Add cmd.run _, args = specification.container.get_container_command_args() for arg in args: cmd_args += arg try: print(cmd_args) docker.execute(cmd_args, stream=True) except Exception as e: handle_cli_error(e, message="Could start local run.") sys.exit(1)
def test_create_run_with_templated_job_spec(self): config_dict = get_fxt_job_with_inputs() spec = OperationSpecification.read(values=config_dict) run = compile_operation_run(project_id=self.project.id, user_id=self.user.id, op_spec=spec) assert run.kind == V1RunKind.JOB assert run.name == "foo" assert run.description == "a description" assert set(run.tags) == {"tag1", "tag2"} # From template compiled_operation = CompiledOperationSpecification.read(run.content) compiled_operation = CompiledOperationSpecification.apply_params( compiled_operation, params=spec.params) compiled_operation = CompiledOperationSpecification.apply_context( compiled_operation) CompiledOperationSpecification.apply_run_contexts(compiled_operation, ) run.content = compiled_operation.to_dict(dump=True) run.save(update_fields=["content"]) job_spec = CompiledOperationSpecification.read(run.content) assert job_spec.run.container.image == "{{ image }}" job_spec = CompiledOperationSpecification.apply_run_contexts(job_spec) assert job_spec.run.container.image == "foo/bar"
def run( ctx, project, polyaxonfile, python_module, url, hub, name, tags, description, upload, log, watch, local, conda_env, params, profile, queue, nocache, ): """Run polyaxonfile specification. Examples: \b $ polyaxon run -f file -f file_override ... Upload before running \b $ polyaxon run -f file -u Run and set description and tags for this run \b $ polyaxon run -f file -u --description="Description of the current run" --tags="foo, bar, moo" Run and set a unique name for this run \b polyaxon run --name=foo Run for a specific project \b $ polyaxon run -p project1 -f file.yaml Run with updated params \b $ polyaxon run -p project1 -f file.yaml -P param1=234.2 -P param2=relu If a python file contains a component main, you can run that component \b polyaxon run -pm path/to/my-component.py If a python file contains more than one component, you can specify the component to run \b polyaxon run -pm path/to/my-component.py:componentA """ op_spec = check_polyaxonfile( polyaxonfile=polyaxonfile, python_module=python_module, url=url, hub=hub, params=params, profile=profile, queue=queue, nocache=nocache, log=False, ) owner, project_name = get_project_or_local(project, is_cli=True) tags = validate_tags(tags) if local: try: compiled_operation = OperationSpecification.compile_operation(op_spec) compiled_operation = CompiledOperationSpecification.apply_context( compiled_operation ) except (PolyaxonSchemaError, ValidationError): Printer.print_error( "Could not run this polyaxonfile locally, " "a context is required to resolve it dependencies." ) sys.exit(1) docker_run( ctx=ctx, name=name, owner=owner, project_name=project_name, description=description, tags=tags, compiled_operation=compiled_operation, log=log, ) elif settings.CLIENT_CONFIG.no_api: k8s_run( ctx=ctx, name=name, owner=owner, project_name=project_name, description=description, tags=tags, op_spec=op_spec, upload=upload, log=log, can_upload=all([upload, project]), ) else: platform_run( ctx=ctx, name=name, owner=owner, project_name=project_name, description=description, tags=tags, op_spec=op_spec, upload=upload, log=log, watch=watch, can_upload=all([upload, project]), )