|
| 1 | +import click |
| 2 | + |
| 3 | +from paperspace import commands |
| 4 | + |
| 5 | + |
| 6 | +class OptionRequiredIfMultinode(click.Option): |
| 7 | + def full_process_value(self, ctx, value): |
| 8 | + value = super(OptionRequiredIfMultinode, self).full_process_value(ctx, value) |
| 9 | + |
| 10 | + if value is None and ctx.params["workercount"] > 1: |
| 11 | + msg = "Required if --workerCount > 1" |
| 12 | + raise click.MissingParameter(ctx=ctx, param=self, message=msg) |
| 13 | + |
| 14 | + return value |
| 15 | + |
| 16 | + |
| 17 | +def del_if_value_is_none(d): |
| 18 | + """Remove all elements with value == None""" |
| 19 | + for key, val in list(d.items()): |
| 20 | + if val is None: |
| 21 | + del d[key] |
| 22 | + |
| 23 | + |
| 24 | +@click.group() |
| 25 | +def cli(): |
| 26 | + pass |
| 27 | + |
| 28 | + |
| 29 | +@cli.group() |
| 30 | +def experiments(): |
| 31 | + pass |
| 32 | + |
| 33 | + |
| 34 | +@experiments.command() |
| 35 | +@click.option("--name", required=True) |
| 36 | +@click.option("--workerCount", "workerCount", required=True, type=int) |
| 37 | +@click.option("--workerContainer", "workerContainer", cls=OptionRequiredIfMultinode) |
| 38 | +@click.option("--workerMachineType", "workerMachineType", cls=OptionRequiredIfMultinode) |
| 39 | +@click.option("--workerCommand", "workerCommand", cls=OptionRequiredIfMultinode) |
| 40 | +@click.option("--parameterServerContainer", "parameterServerContainer", cls=OptionRequiredIfMultinode) |
| 41 | +@click.option("--parameterServerMachineType", "parameterServerMachineType", cls=OptionRequiredIfMultinode) |
| 42 | +@click.option("--parameterServerCommand", "parameterServerCommand", cls=OptionRequiredIfMultinode) |
| 43 | +@click.option("--parameterServerCount", "parameterServerCount", type=int, cls=OptionRequiredIfMultinode) |
| 44 | +@click.option("--ports", type=int) |
| 45 | +@click.option("--workspaceUrl", "workspaceUrl") |
| 46 | +@click.option("--projectHandler", "projectHandler") |
| 47 | +@click.option("--workingDirectory", "workingDirectory") |
| 48 | +@click.option("--artifactDirectory", "artifactDirectory") |
| 49 | +@click.option("--clusterId", "clusterId", type=int) |
| 50 | +# @click.option("--experimentEnv", type=dict) |
| 51 | +@click.option("--experimentTypeId", "experimentTypeId", type=int) |
| 52 | +@click.option("--workerContainerUser", "workerContainerUser") |
| 53 | +@click.option("--workerRegistryUsername", "workerRegistryUsername") |
| 54 | +@click.option("--workerRegistryPassword", "workerRegistryPassword") |
| 55 | +@click.option("--parameterServerContainerUser", "parameterServerContainerUser") |
| 56 | +@click.option("--parameterServerRegistryContainerUser", "parameterServerRegistryContainerUser") |
| 57 | +@click.option("--parameterServerRegistryPassword", "parameterServerRegistryPassword") |
| 58 | +def create(**kwargs): |
| 59 | + del_if_value_is_none(kwargs) |
| 60 | + commands.create_experiments(kwargs) |
0 commit comments