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

Commit aa27034

Browse files
committed
Update readme and experiments parameters; minor other changes.
1 parent 4fea042 commit aa27034

File tree

8 files changed

+253
-135
lines changed

8 files changed

+253
-135
lines changed

Pipfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ click = "*"
1616
[dev-packages]
1717
twine = "*"
1818
pypandoc = "*"
19+
pytest = "*"

Pipfile.lock

Lines changed: 187 additions & 122 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,19 @@ It is based off the Google docker image `gcr.io/tensorflow/tensorflow:1.5.0-gpu`
237237
238238
A Dockerfile for building this container image is [here](https://github.com/Paperspace/tensorflow-python/).
239239
240+
241+
Create experiment
242+
=================
243+
To create new experiment use
244+
```.env
245+
paperspace-python experiments create [type] [--options]
246+
```
247+
The two available experiment types are `singlenode` and `multinode`.
248+
249+
For a full list of available options run `paperspace experiments [type] --help`.
250+
Note that some options are required to create new experiment.
251+
252+
240253
Other examples
241254
==============
242255
See the scripts in the `tests` folder for other examples.

paperspace/cli.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def convert(self, value, param, ctx):
1818
return self.type_map[value]
1919

2020

21-
EXPERIMENT_TYPES_MAP = {
21+
MULTI_NODE_EXPERIMENT_TYPES_MAP = {
2222
"GRPC": constants.EXPERIMENT_TYPE_GRPC_MULTI_NODE_ID,
2323
"MPI": constants.EXPERIMENT_TYPE_MPI_MULTI_NODE_ID,
2424
}
@@ -29,11 +29,11 @@ def json_string(val):
2929
return json.loads(val)
3030

3131

32-
def del_if_value_is_none(d):
32+
def del_if_value_is_none(dict_):
3333
"""Remove all elements with value == None"""
34-
for key, val in list(d.items()):
34+
for key, val in list(dict_.items()):
3535
if val is None:
36-
del d[key]
36+
del dict_[key]
3737

3838

3939
@click.group()
@@ -51,8 +51,22 @@ def create():
5151
pass
5252

5353

54-
def common_expepriments_create_options(f):
54+
def common_experiments_create_options(f):
5555
options = [
56+
click.option(
57+
"--projectHandle",
58+
"projectHandle",
59+
),
60+
click.option(
61+
"--projectId",
62+
"projectId",
63+
type=int,
64+
),
65+
click.option(
66+
"--triggerEventId",
67+
"triggerEventId",
68+
type=int,
69+
),
5670
click.option(
5771
"--experimentEnv",
5872
"experimentEnv",
@@ -89,11 +103,11 @@ def common_expepriments_create_options(f):
89103

90104

91105
@create.command(name="multinode")
92-
@common_expepriments_create_options
106+
@common_experiments_create_options
93107
@click.option(
94108
"--experimentTypeId",
95109
"experimentTypeId",
96-
type=ChoiceType(EXPERIMENT_TYPES_MAP, case_sensitive=False),
110+
type=ChoiceType(MULTI_NODE_EXPERIMENT_TYPES_MAP, case_sensitive=False),
97111
required=True,
98112
)
99113
@click.option(
@@ -172,7 +186,7 @@ def multi_node(**kwargs):
172186

173187

174188
@create.command(name="singlenode")
175-
@common_expepriments_create_options
189+
@common_experiments_create_options
176190
@click.option(
177191
"--container",
178192
required=True,

paperspace/commands.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
from paperspace import config, version, logger
2-
1+
from paperspace import version, logger
32
from paperspace.client import API
3+
from paperspace.config import config
44

55
default_headers = {"x-api-key": config.PAPERSPACE_API_KEY,
66
"ps_client_name": "paperspace-python",
@@ -22,5 +22,6 @@ def _log_response(response, success_msg, error_msg):
2222

2323

2424
def create_experiments(json, api=experiments_api):
25-
response = api.post("/experiments/", json=json, params={"accessToken": config.PAPERSPACE_API_KEY})
25+
response = api.post("/experiments/", json=json)
26+
logger.debug(response.content)
2627
_log_response(response, "Experiment created", "Unknown error while creating experiment")

paperspace/config.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
1+
import json
12
import os
23

3-
_DEFAULT_PAPERSPACE_API_KEY = ""
4+
5+
# TODO: this function is copy-pasted from login.py;
6+
# there is something weird going one with imports in __init__.py and I'm unable to import apikey now
7+
def apikey():
8+
paperspace_dir = os.path.expanduser('~/.paperspace')
9+
config_path = os.path.join(paperspace_dir, 'config.json')
10+
if os.path.exists(config_path):
11+
config_data = json.load(open(config_path))
12+
if config_data and 'apiKey' in config_data:
13+
return config_data['apiKey']
14+
return ''
15+
16+
17+
_DEFAULT_PAPERSPACE_API_KEY = apikey()
418
_DEFAULT_CONFIG_HOST = "https://api.paperspace.io"
519
_DEFAULT_CONFIG_LOG_HOST = "https://logs.paperspace.io"
6-
_DEFAULT_CONFIG_EXPERIMENTS_HOST = "https://" # TODO: fill this
20+
_DEFAULT_CONFIG_EXPERIMENTS_HOST = "https://services.paperspace.io/experiments/v1/" # TODO: validate this
721

822

923
class config(object):
24+
DEBUG = os.environ.get("PAPERSPACE_CLI_DEBUG") in ("true", "1")
1025
PAPERSPACE_API_KEY = os.environ.get("PAPERSPACE_API_KEY", _DEFAULT_PAPERSPACE_API_KEY)
1126
CONFIG_HOST = os.environ.get("PAPERSPACE_CONFIG_HOST", _DEFAULT_CONFIG_HOST)
1227
CONFIG_LOG_HOST = os.environ.get("PAPERSPACE_CONFIG_LOG_HOST", _DEFAULT_CONFIG_LOG_HOST)

paperspace/logger.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import click
22
from six import string_types
33

4+
from .config import config
5+
46

57
def log(*messages, **kwargs):
68
error = kwargs.get("error", False)
@@ -26,3 +28,8 @@ def log_error_response(data):
2628
for v in val:
2729
msg = "{}: {}".format(key, str(v))
2830
log(msg, error=True)
31+
32+
33+
def debug(*messages):
34+
if config.DEBUG:
35+
log(*messages)

paperspace/login.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import requests
55
from six.moves import input
66

7+
from paperspace import logger
78
from .config import *
89
from .method import requests_exception_to_error_obj, response_error_check, status_code_to_error_obj
910

@@ -52,6 +53,7 @@ def login(email=None, password=None, apiToken=None):
5253
try:
5354
r = requests.request('post', config.CONFIG_HOST + '/users/login',
5455
json=params)
56+
logger.debug(r.content)
5557
except requests.exceptions.RequestException as e:
5658
res = requests_exception_to_error_obj(e)
5759
else:

0 commit comments

Comments
 (0)