Skip to content
This repository was archived by the owner on Aug 11, 2020. It is now read-only.

Commit e6207e4

Browse files
committed
Merge branch 'master' of github.com:Paperspace/paperspace-python into v0.2.0a2
2 parents 8bb6a52 + 765ebe5 commit e6207e4

15 files changed

+1463
-41
lines changed

paperspace/cli/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import paperspace.cli.auth
66
import paperspace.cli.deployments
77
import paperspace.cli.experiments
8+
import paperspace.cli.hyperparameters
89
import paperspace.cli.jobs
910
import paperspace.cli.machines
1011
import paperspace.cli.models

paperspace/cli/deployments.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def create_deployment(api_key=None, **kwargs):
100100
@click.option(
101101
"--modelId",
102102
"modelId",
103-
help="Use to filter by project ID",
103+
help="Use to filter by model ID",
104104
)
105105
@api_key_option
106106
def get_deployments_list(api_key=None, **filters):

paperspace/cli/experiments.py

+5
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ def common_experiments_create_options(f):
5858
"workspaceUrl",
5959
help="Project git repository url",
6060
),
61+
click.option(
62+
"--ignoreFiles",
63+
"ignore_files",
64+
help="Ignore certain files from uploading"
65+
),
6166
click.option(
6267
"--workingDirectory",
6368
"workingDirectory",

paperspace/cli/hyperparameters.py

+136
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
import functools
2+
3+
import click
4+
5+
from paperspace import client, config
6+
from paperspace.cli import common
7+
from paperspace.cli.cli import cli
8+
from paperspace.cli.common import ClickGroup
9+
from paperspace.commands import hyperparameters as hyperparameters_commands
10+
11+
12+
@cli.group("hyperparameters", help="Manage hyperparameters", cls=ClickGroup)
13+
def hyperparameters_group():
14+
pass
15+
16+
17+
def common_hyperparameter_create_options(f):
18+
options = [
19+
click.option(
20+
"--name",
21+
"name",
22+
required=True,
23+
),
24+
click.option(
25+
"--projectId",
26+
"projectHandle",
27+
required=True,
28+
),
29+
click.option(
30+
"--tuningCommand",
31+
"tuningCommand",
32+
required=True,
33+
),
34+
click.option(
35+
"--workerContainer",
36+
"workerContainer",
37+
required=True,
38+
),
39+
click.option(
40+
"--workerMachineType",
41+
"workerMachineType",
42+
required=True,
43+
),
44+
click.option(
45+
"--workerCommand",
46+
"workerCommand",
47+
required=True,
48+
),
49+
click.option(
50+
"--workerCount",
51+
"workerCount",
52+
required=True,
53+
type=int,
54+
),
55+
click.option(
56+
"--serverRegistryUsername",
57+
"hyperparameterServerRegistryUsername",
58+
),
59+
click.option(
60+
"--serverRegistryPassword",
61+
"hyperparameterServerRegistryPassword",
62+
),
63+
click.option(
64+
"--serverContainerUser",
65+
"hyperparameterServerContainerUser",
66+
),
67+
]
68+
return functools.reduce(lambda x, opt: opt(x), reversed(options), f)
69+
70+
71+
@hyperparameters_group.command("create", help="Create hyperparameter")
72+
@common_hyperparameter_create_options
73+
@common.api_key_option
74+
def create_hyperparameter(api_key, **hyperparameter):
75+
common.del_if_value_is_none(hyperparameter)
76+
hyperparameters_api = client.API(config.CONFIG_EXPERIMENTS_HOST, api_key=api_key)
77+
command = hyperparameters_commands.CreateHyperparameterCommand(api=hyperparameters_api)
78+
command.execute(hyperparameter)
79+
80+
81+
@hyperparameters_group.command("createAndStart", help="Create hyperparameter")
82+
@common_hyperparameter_create_options
83+
@common.api_key_option
84+
def create_and_start_hyperparameter(api_key, **hyperparameter):
85+
common.del_if_value_is_none(hyperparameter)
86+
hyperparameters_api = client.API(config.CONFIG_EXPERIMENTS_HOST, api_key=api_key)
87+
command = hyperparameters_commands.CreateAndStartHyperparameterCommand(api=hyperparameters_api)
88+
command.execute(hyperparameter)
89+
90+
91+
@hyperparameters_group.command("list", help="List hyperparameters")
92+
@common.api_key_option
93+
def list_hyperparameters(api_key):
94+
hyperparameters_api = client.API(config.CONFIG_EXPERIMENTS_HOST, api_key=api_key)
95+
command = hyperparameters_commands.ListHyperparametersCommand(api=hyperparameters_api)
96+
command.execute()
97+
98+
99+
# TODO: 'unhidden' command and test it when api is updated to support deleting hyperparameters
100+
@hyperparameters_group.command("delete", help="Delete hyperparameter", hidden=True)
101+
@click.option(
102+
"--id",
103+
"id_",
104+
required=True,
105+
)
106+
@common.api_key_option
107+
def delete_hyperparameter(api_key, id_):
108+
hyperparameters_api = client.API(config.CONFIG_EXPERIMENTS_HOST, api_key=api_key)
109+
command = hyperparameters_commands.DeleteHyperparameterCommand(api=hyperparameters_api)
110+
command.execute(id_)
111+
112+
113+
@hyperparameters_group.command("details", help="Show details of hyperparameter")
114+
@click.option(
115+
"--id",
116+
"id_",
117+
required=True,
118+
)
119+
@common.api_key_option
120+
def get_hyperparameter_details(api_key, id_):
121+
hyperparameters_api = client.API(config.CONFIG_EXPERIMENTS_HOST, api_key=api_key)
122+
command = hyperparameters_commands.HyperparameterDetailsCommand(api=hyperparameters_api)
123+
command.execute(id_)
124+
125+
126+
@hyperparameters_group.command("start", help="Start hyperparameter tuning")
127+
@click.option(
128+
"--id",
129+
"id_",
130+
required=True,
131+
)
132+
@common.api_key_option
133+
def start_hyperparameter_tuning(api_key, id_):
134+
hyperparameters_api = client.API(config.CONFIG_EXPERIMENTS_HOST, api_key=api_key)
135+
command = hyperparameters_commands.HyperparameterStartCommand(api=hyperparameters_api)
136+
command.execute(id_)

paperspace/cli/jobs.py

+46-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import click
22

33
from paperspace import client, config
4-
from paperspace.cli import common
5-
from paperspace.cli.cli_types import json_string
6-
from paperspace.cli.common import del_if_value_is_none, ClickGroup
74
from paperspace.cli.cli import cli
5+
from paperspace.cli.cli_types import json_string
6+
from paperspace.cli.common import api_key_option, del_if_value_is_none, ClickGroup
87
from paperspace.commands import jobs as jobs_commands
98

109

@@ -20,7 +19,7 @@ def jobs_group():
2019
required=True,
2120
help="Delete job with given ID",
2221
)
23-
@common.api_key_option
22+
@api_key_option
2423
def delete_job(job_id, api_key=None):
2524
jobs_api = client.API(config.CONFIG_HOST, api_key=api_key)
2625
command = jobs_commands.DeleteJobCommand(api=jobs_api)
@@ -34,7 +33,7 @@ def delete_job(job_id, api_key=None):
3433
required=True,
3534
help="Stop job with given ID",
3635
)
37-
@common.api_key_option
36+
@api_key_option
3837
def stop_job(job_id, api_key=None):
3938
jobs_api = client.API(config.CONFIG_HOST, api_key=api_key)
4039
command = jobs_commands.StopJobCommand(api=jobs_api)
@@ -57,9 +56,9 @@ def stop_job(job_id, api_key=None):
5756
"experimentId",
5857
help="Use to filter jobs by experiment ID",
5958
)
60-
@common.api_key_option
59+
@api_key_option
6160
def list_jobs(api_key, **filters):
62-
common.del_if_value_is_none(filters)
61+
del_if_value_is_none(filters)
6362
jobs_api = client.API(config.CONFIG_HOST, api_key=api_key)
6463
command = jobs_commands.ListJobsCommand(api=jobs_api)
6564
command.execute(filters=filters)
@@ -75,7 +74,8 @@ def list_jobs(api_key, **filters):
7574
@click.option("--workspace", "workspace", required=False, help="Path to workspace directory")
7675
@click.option("--workspaceArchive", "workspaceArchive", required=False, help="Path to workspace archive")
7776
@click.option("--workspaceUrl", "workspaceUrl", required=False, help="Project git repository url")
78-
@click.option("--workingDirectory", "workingDirectory", help="Working directory for the experiment", )
77+
@click.option("--workingDirectory", "workingDirectory", help="Working directory for the experiment")
78+
@click.option("--ignoreFiles", "ignore_files", help="Ignore certain files from uploading")
7979
@click.option("--experimentId", "experimentId", help="Experiment Id")
8080
@click.option("--jobEnv", "envVars", type=json_string, help="Environmental variables ")
8181
@click.option("--useDockerfile", "useDockerfile", help="Flag: using Dockerfile")
@@ -86,7 +86,7 @@ def list_jobs(api_key, **filters):
8686
@click.option("--relDockerfilePath", "relDockerfilePath", help="Relative path to Dockerfile")
8787
@click.option("--registryUsername", "registryUsername", help="Docker registry username")
8888
@click.option("--registryPassword", "registryPassword", help="Docker registry password")
89-
@common.api_key_option
89+
@api_key_option
9090
def create_job(api_key, **kwargs):
9191
del_if_value_is_none(kwargs)
9292
jobs_api = client.API(config.CONFIG_HOST, api_key=api_key)
@@ -100,8 +100,44 @@ def create_job(api_key, **kwargs):
100100
"job_id",
101101
required=True
102102
)
103-
@common.api_key_option
103+
@api_key_option
104104
def list_logs(job_id, api_key=None):
105105
logs_api = client.API(config.CONFIG_LOG_HOST, api_key=api_key)
106106
command = jobs_commands.JobLogsCommand(api=logs_api)
107107
command.execute(job_id)
108+
109+
110+
@jobs_group.group("artifacts", help="Manage jobs' artifacts", cls=ClickGroup)
111+
def artifacts():
112+
pass
113+
114+
115+
@artifacts.command("destroy", help="Destroy job's artifacts")
116+
@click.argument("job_id")
117+
@click.option("--files", "files")
118+
@api_key_option
119+
def destroy_artifacts(job_id, api_key=None, files=None):
120+
jobs_api = client.API(config.CONFIG_HOST, api_key=api_key)
121+
command = jobs_commands.ArtifactsDestroyCommand(api=jobs_api)
122+
command.execute(job_id, files=files)
123+
124+
125+
@artifacts.command("get", help="Get job's artifacts")
126+
@click.argument("job_id")
127+
@api_key_option
128+
def get_artifacts(job_id, api_key=None):
129+
jobs_api = client.API(config.CONFIG_HOST, api_key=api_key)
130+
command = jobs_commands.ArtifactsGetCommand(api=jobs_api)
131+
command.execute(job_id)
132+
133+
134+
@artifacts.command("list", help="List job's artifacts")
135+
@click.argument("job_id")
136+
@click.option("--size", "-s", "size", help="Show file size", is_flag=True)
137+
@click.option("--links", "-l", "links", help="Show file URL", is_flag=True)
138+
@click.option("--files", "files", help="Get only given file (use at the end * as a wildcard)")
139+
@api_key_option
140+
def list_artifacts(job_id, size, links, files, api_key=None):
141+
jobs_api = client.API(config.CONFIG_HOST, api_key=api_key)
142+
command = jobs_commands.ArtifactsListCommand(api=jobs_api)
143+
command.execute(job_id=job_id, size=size, links=links, files=files)

paperspace/client.py

+14-5
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,35 @@ def get_path(self, url):
3030

3131
def post(self, url, json=None, params=None, files=None):
3232
path = self.get_path(url)
33-
response = requests.post(path, json=json, params=params, headers=self.headers, files=files)
3433
logger.debug("POST request sent to: {} \n\theaders: {}\n\tjson: {}\n\tparams: {}"
35-
.format(response.url, self.headers, json, params))
34+
.format(path, self.headers, json, params))
35+
response = requests.post(path, json=json, params=params, headers=self.headers, files=files)
3636
logger.debug("Response status code: {}".format(response.status_code))
3737
logger.debug("Response content: {}".format(response.content))
3838
return response
3939

4040
def put(self, url, json=None, params=None):
4141
path = self.get_path(url)
42-
response = requests.put(path, json=json, params=params, headers=self.headers)
4342
logger.debug("PUT request sent to: {} \n\theaders: {}\n\tjson: {}\n\tparams: {}"
44-
.format(response.url, self.headers, json, params))
43+
.format(path, self.headers, json, params))
44+
response = requests.put(path, json=json, params=params, headers=self.headers)
4545
logger.debug("Response status code: {}".format(response.status_code))
4646
logger.debug("Response content: {}".format(response.content))
4747
return response
4848

4949
def get(self, url, json=None, params=None):
5050
path = self.get_path(url)
51-
response = requests.get(path, params=params, headers=self.headers, json=json)
5251
logger.debug("GET request sent to: {} \n\theaders: {}\n\tjson: {}\n\tparams: {}"
52+
.format(path, self.headers, json, params))
53+
response = requests.get(path, params=params, headers=self.headers, json=json)
54+
logger.debug("Response status code: {}".format(response.status_code))
55+
logger.debug("Response content: {}".format(response.content))
56+
return response
57+
58+
def delete(self, url, json=None, params=None):
59+
path = self.get_path(url)
60+
response = requests.delete(path, params=params, headers=self.headers, json=json)
61+
logger.debug("DELETE request sent to: {} \n\theaders: {}\n\tjson: {}\n\tparams: {}"
5362
.format(response.url, self.headers, json, params))
5463
logger.debug("Response status code: {}".format(response.status_code))
5564
logger.debug("Response content: {}".format(response.content))

paperspace/commands/__init__.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from collections import OrderedDict
2+
3+
from paperspace import logger
4+
5+
6+
class CommandBase(object):
7+
def __init__(self, api=None, logger_=logger):
8+
self.api = api
9+
self.logger = logger_
10+
11+
def _print_dict_recursive(self, input_dict, indent=0, tabulator=" "):
12+
for key, val in input_dict.items():
13+
self.logger.log("%s%s:" % (tabulator * indent, key))
14+
if type(val) is dict:
15+
self._print_dict_recursive(OrderedDict(val), indent + 1)
16+
else:
17+
self.logger.log("%s%s" % (tabulator * (indent + 1), val))

0 commit comments

Comments
 (0)