def test_apply_params_extends_connections_and_init(self): content = { "version": 1.1, "kind": "compiled_operation", "inputs": [ { "name": "docker_image", "type": types.IMAGE }, { "name": "git_repo", "type": types.GIT }, ], "run": { "kind": V1RunKind.JOB, "connections": ["{{ params.docker_image.connection }}"], "container": { "name": "polyaxon-main", "image": "{{ docker_image }}", "command": "train", }, }, } run_config = V1CompiledOperation.read(content) # no params with self.assertRaises(ValidationError): CompiledOperationSpecification.apply_operation_contexts(run_config) params = { "docker_image": { "value": "destination:tag", "connection": "docker-registry", }, "git_repo": { "value": V1GitType(revision="foo"), "connection": "repo-connection", }, } assert run_config.inputs[0].value is None assert run_config.inputs[1].value is None validated_params = run_config.validate_params(params=params) run_config.apply_params(params=params) assert params == {p.name: p.param.to_dict() for p in validated_params} assert run_config.inputs[0].connection == "docker-registry" assert run_config.inputs[1].connection == "repo-connection" run_config = CompiledOperationSpecification.apply_operation_contexts( run_config) run_config = CompiledOperationSpecification.apply_params(run_config) run_config = CompiledOperationSpecification.apply_runtime_contexts( run_config) assert run_config.run.connections == ["docker-registry"] assert run_config.run.container.image == "destination:tag"
def convert_to_git_init(x): if not isinstance(x, Mapping): x = convert_to_dict(x, key) return V1GitType.from_dict(x)
type=types.STR, value="relu", is_optional=True), V1IO(name="optimizer", type=types.STR, value="adam", is_optional=True), V1IO(name="learning_rate", type=types.FLOAT, value=0.01, is_optional=True), V1IO(name="epochs", type=types.INT), ] outputs = [ V1IO(name="loss", type=types.FLOAT), V1IO(name="accuracy", type=types.FLOAT), ] job = V1Job( init=[ V1Init(git=V1GitType( url="https://github.com/polyaxon/polyaxon-quick-start")) ], container=V1Container( image="polyaxon/polyaxon-quick-start", working_dir="{{ globals.artifacts_path }}", command=["python3", "polyaxon-quick-start/model.py"], args=[ "--conv1_size={{ conv1_size }}", "--conv2_size={{ conv2_size }}", "--dropout={{ dropout }}", "--hidden1_size={{ hidden1_size }}", "--optimizer={{ optimizer }}", "--conv_activation={{ conv_activation }}", "--dense_activation={{ dense_activation }}", "--learning_rate={{ learning_rate }}", "--epochs={{ epochs }}" ]), )
def init(project, git_connection, git_url, polyaxonfile, polyaxonignore): """Initialize a new local project and cache directory. Note: Make sure to add the local cache `.polyaxon` to your `.gitignore` and `.dockerignore` files. """ if not any( [project, git_connection, git_url, polyaxonfile, polyaxonignore]): Printer.print_warning( "`polyaxon init` did not receive any valid option.", command_help="polyaxon init", ) if project: owner, project_name = get_project_or_local(project, is_cli=True) try: polyaxon_client = ProjectClient(owner=owner, project=project_name) polyaxon_client.refresh_data() except (ApiException, HTTPError) as e: Printer.print_error( "Make sure you have a project with this name `{}`".format( project)) handle_cli_error( e, message="You can a create new project with this command: " "polyaxon project create " "--name={} [--description=...] [--tags=...]".format( project_name), ) sys.exit(1) init_project = False if ProjectConfigManager.is_initialized(): local_project = get_local_project() click.echo( "Warning! This project is already initialized with the following project:" ) with indentation.indent(4): indentation.puts("Owner: {}".format(local_project.owner)) indentation.puts("Project: {}".format(local_project.name)) if click.confirm("Would you like to override this current config?", default=False): init_project = True else: init_project = True if init_project: ProjectConfigManager.purge( visibility=ProjectConfigManager.VISIBILITY_LOCAL) config = polyaxon_client.client.sanitize_for_serialization( polyaxon_client.project_data) ProjectConfigManager.set_config( config, init=True, visibility=ProjectConfigManager.VISIBILITY_LOCAL) Printer.print_success("Project was initialized") Printer.print_header( "Make sure to add the local cache `.polyaxon` " "to your `.gitignore` and `.dockerignore` files.") else: Printer.print_header("Project config was not changed.") if git_connection or git_url: init_git = False if GitConfigManager.is_initialized(): click.echo("Warning! A {} file was found.".format( GitConfigManager.CONFIG_FILE_NAME)) if click.confirm("Would you like to override it?", default=False): init_git = True else: init_git = True if init_git: GitConfigManager.purge( visibility=GitConfigManager.VISIBILITY_LOCAL) config = GitConfigManager.CONFIG( connection=git_connection, git=V1GitType(url=git_url) if git_url else None, ) GitConfigManager.set_config(config=config, init=True) Printer.print_success("New {} file was created.".format( GitConfigManager.CONFIG_FILE_NAME)) else: Printer.print_header("{} file was not changed.".format( GitConfigManager.CONFIG_FILE_NAME)) if polyaxonfile: create_polyaxonfile() if polyaxonignore: init_ignore = False if IgnoreConfigManager.is_initialized(): click.echo("Warning! A {} file was found.".format( IgnoreConfigManager.CONFIG_FILE_NAME)) if click.confirm("Would you like to override it?", default=False): init_ignore = True else: init_ignore = True if init_ignore: IgnoreConfigManager.init_config() Printer.print_success("New {} file was created.".format( IgnoreConfigManager.CONFIG_FILE_NAME)) else: Printer.print_header("{} file was not changed.".format( IgnoreConfigManager.CONFIG_FILE_NAME))
def get_config(cls, check: bool = True): config = super(GitConfigManager, cls).get_config(check=check) if not config.git: config.git = V1GitType() return config