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

Commit 2feb268

Browse files
committed
Add experiment createAndStart command
1 parent aa27034 commit 2feb268

File tree

3 files changed

+171
-125
lines changed

3 files changed

+171
-125
lines changed

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,15 +238,20 @@ It is based off the Google docker image `gcr.io/tensorflow/tensorflow:1.5.0-gpu`
238238
A Dockerfile for building this container image is [here](https://github.com/Paperspace/tensorflow-python/).
239239
240240
241-
Create experiment
241+
Create/create and start experiment
242242
=================
243-
To create new experiment use
243+
To create new experiment use:
244244
```.env
245245
paperspace-python experiments create [type] [--options]
246246
```
247247
The two available experiment types are `singlenode` and `multinode`.
248248

249-
For a full list of available options run `paperspace experiments [type] --help`.
249+
To create and immediately start new experiment use:
250+
```.env
251+
paperspace-python experiments createAndStart [type] [--options]
252+
```
253+
254+
For a full list of available commands run `paperspace experiments --help`.
250255
Note that some options are required to create new experiment.
251256

252257

paperspace/cli.py

Lines changed: 157 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,36 @@ def create():
5151
pass
5252

5353

54+
@experiments.group(name="createAndStart")
55+
def create_and_start():
56+
pass
57+
58+
5459
def common_experiments_create_options(f):
5560
options = [
5661
click.option(
57-
"--projectHandle",
58-
"projectHandle",
62+
"--name",
63+
required=True,
5964
),
6065
click.option(
61-
"--projectId",
62-
"projectId",
66+
"--ports",
6367
type=int,
6468
),
6569
click.option(
66-
"--triggerEventId",
67-
"triggerEventId",
70+
"--workspaceUrl",
71+
"workspaceUrl",
72+
),
73+
click.option(
74+
"--workingDirectory",
75+
"workingDirectory",
76+
),
77+
click.option(
78+
"--artifactDirectory",
79+
"artifactDirectory",
80+
),
81+
click.option(
82+
"--clusterId",
83+
"clusterId",
6884
type=int,
6985
),
7086
click.option(
@@ -73,149 +89,168 @@ def common_experiments_create_options(f):
7389
type=json_string,
7490
),
7591
click.option(
76-
"--clusterId",
77-
"clusterId",
92+
"--triggerEventId",
93+
"triggerEventId",
7894
type=int,
7995
),
8096
click.option(
81-
"--artifactDirectory",
82-
"artifactDirectory",
97+
"--projectId",
98+
"projectId",
99+
type=int,
83100
),
84101
click.option(
85-
"--workingDirectory",
86-
"workingDirectory",
102+
"--projectHandle",
103+
"projectHandle",
87104
),
105+
]
106+
return functools.reduce(lambda x, opt: opt(x), reversed(options), f)
107+
108+
109+
def common_experiment_create_multi_node_options(f):
110+
options = [
88111
click.option(
89-
"--workspaceUrl",
90-
"workspaceUrl",
112+
"--experimentTypeId",
113+
"experimentTypeId",
114+
type=ChoiceType(MULTI_NODE_EXPERIMENT_TYPES_MAP, case_sensitive=False),
115+
required=True,
91116
),
92117
click.option(
93-
"--ports",
118+
"--workerContainer",
119+
"workerContainer",
120+
required=True,
121+
),
122+
click.option(
123+
"--workerMachineType",
124+
"workerMachineType",
125+
required=True,
126+
),
127+
click.option(
128+
"--workerCommand",
129+
"workerCommand",
130+
required=True,
131+
),
132+
click.option(
133+
"--workerCount",
134+
"workerCount",
94135
type=int,
136+
required=True,
95137
),
96138
click.option(
97-
"--name",
139+
"--parameterServerContainer",
140+
"parameterServerContainer",
98141
required=True,
99142
),
143+
click.option(
144+
"--parameterServerMachineType",
145+
"parameterServerMachineType",
146+
required=True,
147+
),
148+
click.option(
149+
"--parameterServerCommand",
150+
"parameterServerCommand",
151+
required=True,
152+
),
153+
click.option(
154+
"--parameterServerCount",
155+
"parameterServerCount",
156+
type=int,
157+
required=True,
158+
),
159+
click.option(
160+
"--projectHandler",
161+
"projectHandler",
162+
),
163+
click.option(
164+
"--workerContainerUser",
165+
"workerContainerUser",
166+
),
167+
click.option(
168+
"--workerRegistryUsername",
169+
"workerRegistryUsername",
170+
),
171+
click.option(
172+
"--workerRegistryPassword",
173+
"workerRegistryPassword",
174+
),
175+
click.option(
176+
"--parameterServerContainerUser",
177+
"parameterServerContainerUser",
178+
),
179+
click.option(
180+
"--parameterServerRegistryContainerUser",
181+
"parameterServerRegistryContainerUser",
182+
),
183+
click.option(
184+
"--parameterServerRegistryPassword",
185+
"parameterServerRegistryPassword",
186+
),
187+
]
188+
return functools.reduce(lambda x, opt: opt(x), reversed(options), f)
189+
100190

191+
def common_experiments_create_single_node_options(f):
192+
options = [
193+
click.option(
194+
"--container",
195+
required=True,
196+
),
197+
click.option(
198+
"--machineType",
199+
"machineType",
200+
required=True,
201+
),
202+
click.option(
203+
"--command",
204+
required=True,
205+
),
206+
click.option(
207+
"--count",
208+
type=int,
209+
),
210+
click.option(
211+
"--containerUser",
212+
"containerUser",
213+
),
214+
click.option(
215+
"--registryUsername",
216+
"registryUsername",
217+
),
218+
click.option(
219+
"--registryPassword",
220+
"registryPassword",
221+
),
101222
]
102-
return functools.reduce(lambda x, opt: opt(x), options, f)
223+
return functools.reduce(lambda x, opt: opt(x), reversed(options), f)
103224

104225

105226
@create.command(name="multinode")
106227
@common_experiments_create_options
107-
@click.option(
108-
"--experimentTypeId",
109-
"experimentTypeId",
110-
type=ChoiceType(MULTI_NODE_EXPERIMENT_TYPES_MAP, case_sensitive=False),
111-
required=True,
112-
)
113-
@click.option(
114-
"--workerContainer",
115-
"workerContainer",
116-
required=True,
117-
)
118-
@click.option(
119-
"--workerMachineType",
120-
"workerMachineType",
121-
required=True,
122-
)
123-
@click.option(
124-
"--workerCommand",
125-
"workerCommand",
126-
required=True,
127-
)
128-
@click.option(
129-
"--workerCount",
130-
"workerCount",
131-
type=int,
132-
required=True,
133-
)
134-
@click.option(
135-
"--parameterServerContainer",
136-
"parameterServerContainer",
137-
required=True,
138-
)
139-
@click.option(
140-
"--parameterServerMachineType",
141-
"parameterServerMachineType",
142-
required=True,
143-
)
144-
@click.option(
145-
"--parameterServerCommand",
146-
"parameterServerCommand",
147-
required=True,
148-
)
149-
@click.option(
150-
"--parameterServerCount",
151-
"parameterServerCount",
152-
type=int,
153-
required=True,
154-
)
155-
@click.option(
156-
"--projectHandler",
157-
"projectHandler",
158-
)
159-
@click.option(
160-
"--workerContainerUser",
161-
"workerContainerUser",
162-
)
163-
@click.option(
164-
"--workerRegistryUsername",
165-
"workerRegistryUsername",
166-
)
167-
@click.option(
168-
"--workerRegistryPassword",
169-
"workerRegistryPassword",
170-
)
171-
@click.option(
172-
"--parameterServerContainerUser",
173-
"parameterServerContainerUser",
174-
)
175-
@click.option(
176-
"--parameterServerRegistryContainerUser",
177-
"parameterServerRegistryContainerUser",
178-
)
179-
@click.option(
180-
"--parameterServerRegistryPassword",
181-
"parameterServerRegistryPassword",
182-
)
228+
@common_experiment_create_multi_node_options
183229
def multi_node(**kwargs):
184230
del_if_value_is_none(kwargs)
185231
commands.create_experiments(kwargs)
186232

187233

188234
@create.command(name="singlenode")
189235
@common_experiments_create_options
190-
@click.option(
191-
"--container",
192-
required=True,
193-
)
194-
@click.option(
195-
"--machineType",
196-
"machineType",
197-
required=True,
198-
)
199-
@click.option(
200-
"--command",
201-
required=True,
202-
)
203-
@click.option(
204-
"--count",
205-
type=int,
206-
)
207-
@click.option(
208-
"--containerUser",
209-
"containerUser",
210-
)
211-
@click.option(
212-
"--registryUsername",
213-
"registryUsername",
214-
)
215-
@click.option(
216-
"--registryPassword",
217-
"registryPassword",
218-
)
236+
@common_experiments_create_single_node_options
237+
def single_node(**kwargs):
238+
kwargs["experimentTypeId"] = constants.EXPERIMENT_TYPE_SINGLE_NODE_ID
239+
del_if_value_is_none(kwargs)
240+
commands.create_experiments(kwargs)
241+
242+
243+
@create_and_start.command(name="multinode")
244+
@common_experiments_create_options
245+
@common_experiment_create_multi_node_options
246+
def multi_node(**kwargs):
247+
del_if_value_is_none(kwargs)
248+
commands.create_experiments(kwargs)
249+
250+
251+
@create_and_start.command(name="singlenode")
252+
@common_experiments_create_options
253+
@common_experiments_create_single_node_options
219254
def single_node(**kwargs):
220255
kwargs["experimentTypeId"] = constants.EXPERIMENT_TYPE_SINGLE_NODE_ID
221256
del_if_value_is_none(kwargs)

paperspace/commands.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,9 @@ def create_experiments(json, api=experiments_api):
2525
response = api.post("/experiments/", json=json)
2626
logger.debug(response.content)
2727
_log_response(response, "Experiment created", "Unknown error while creating experiment")
28+
29+
30+
def create_and_start_experiments(json, api=experiments_api):
31+
response = api.post("/experiments/create_and_start/", json=json)
32+
logger.debug(response.content)
33+
_log_response(response, "Experiment created", "Unknown error while creating experiment")

0 commit comments

Comments
 (0)