Skip to content
This repository was archived by the owner on Aug 11, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 13 additions & 18 deletions paperspace/cli/experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,9 @@ def common_experiments_create_options(f):
),
click.option(
"--projectId",
"projectId",
help="Project ID",
),
click.option(
"--projectHandle",
"projectHandle",
required=True,
help="Project handle",
help="Project ID",
),
click.option(
"--modelType",
Expand Down Expand Up @@ -278,33 +273,33 @@ def create_and_start_single_node(api_key, **kwargs):


@experiments.command("start", help="Start experiment")
@click.argument("experiment-handle")
@click.argument("experiment-id")
@api_key_option
def start_experiment(experiment_handle, api_key):
def start_experiment(experiment_id, api_key):
experiments_api = client.API(config.CONFIG_EXPERIMENTS_HOST, api_key=api_key)
experiments_commands.start_experiment(experiment_handle, api=experiments_api)
experiments_commands.start_experiment(experiment_id, api=experiments_api)


@experiments.command("stop", help="Stop experiment")
@click.argument("experiment-handle")
@click.argument("experiment-id")
@api_key_option
def stop_experiment(experiment_handle, api_key):
def stop_experiment(experiment_id, api_key):
experiments_api = client.API(config.CONFIG_EXPERIMENTS_HOST, api_key=api_key)
experiments_commands.stop_experiment(experiment_handle, api=experiments_api)
experiments_commands.stop_experiment(experiment_id, api=experiments_api)


@experiments.command("list", help="List experiments")
@click.option("--projectHandle", "-p", "project_handles", multiple=True)
@click.option("--projectId", "-p", "project_ids", multiple=True)
@api_key_option
def list_experiments(project_handles, api_key):
def list_experiments(project_ids, api_key):
experiments_api = client.API(config.CONFIG_EXPERIMENTS_HOST, api_key=api_key)
command = experiments_commands.ListExperimentsCommand(api=experiments_api)
command.execute(project_handles)
command.execute(project_ids)


@experiments.command("details", help="Show detail of an experiment")
@click.argument("experiment-handle")
@click.argument("experiment-id")
@api_key_option
def get_experiment_details(experiment_handle, api_key):
def get_experiment_details(experiment_id, api_key):
experiments_api = client.API(config.CONFIG_EXPERIMENTS_HOST, api_key=api_key)
experiments_commands.get_experiment_details(experiment_handle, api=experiments_api)
experiments_commands.get_experiment_details(experiment_id, api=experiments_api)
2 changes: 1 addition & 1 deletion paperspace/cli/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def list_jobs(api_key, **filters):
@click.option("--useDockerfile", "useDockerfile", help="Flag: using Dockerfile")
@click.option("--isPreemptible", "isPreemptible", help="Flag: isPreemptible")
@click.option("--project", "project", help="Project name")
@click.option("--projectHandle", "--projectId", "projectHandle", help="Project handle", required=True)
@click.option("--projectId", "projectHandle", help="Project ID", required=True)
@click.option("--startedByUserId", "startedByUserId", help="User ID")
@click.option("--relDockerfilePath", "relDockerfilePath", help="Relative path to Dockerfile")
@click.option("--registryUsername", "registryUsername", help="Docker registry username")
Expand Down
46 changes: 23 additions & 23 deletions paperspace/commands/experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def __init__(self, workspace_handler=None, **kwargs):
def _log_create_experiment(self, response, success_msg_template, error_msg):
if response.ok:
j = response.json()
handle = j["handle"]
msg = success_msg_template.format(handle)
id_ = j["handle"]
msg = success_msg_template.format(id_)
self.logger.log(msg)
else:
try:
Expand All @@ -40,7 +40,7 @@ def execute(self, json_):
response = self.api.post("/experiments/", json=json_)

self._log_create_experiment(response,
"New experiment created with handle: {}",
"New experiment created with ID: {}",
"Unknown error while creating the experiment")


Expand All @@ -52,18 +52,18 @@ def execute(self, json_):

response = self.api.post("/experiments/create_and_start/", json=json_)
self._log_create_experiment(response,
"New experiment created and started with handle: {}",
"New experiment created and started with ID: {}",
"Unknown error while creating/starting the experiment")


def start_experiment(experiment_handle, api=experiments_api):
url = "/experiments/{}/start/".format(experiment_handle)
def start_experiment(experiment_id, api=experiments_api):
url = "/experiments/{}/start/".format(experiment_id)
response = api.put(url)
log_response(response, "Experiment started", "Unknown error while starting the experiment")


def stop_experiment(experiment_handle, api=experiments_api):
url = "/experiments/{}/stop/".format(experiment_handle)
def stop_experiment(experiment_id, api=experiments_api):
url = "/experiments/{}/stop/".format(experiment_id)
response = api.put(url)
log_response(response, "Experiment stopped", "Unknown error while stopping the experiment")

Expand All @@ -73,9 +73,9 @@ def __init__(self, api=experiments_api, logger_=logger):
self.api = api
self.logger = logger_

def execute(self, project_handles=None):
project_handles = project_handles or []
params = self._get_query_params(project_handles)
def execute(self, project_ids=None):
project_ids = project_ids or []
params = self._get_query_params(project_ids)
response = self.api.get("/experiments/", params=params)

try:
Expand All @@ -84,24 +84,24 @@ def execute(self, project_handles=None):
self.logger.log_error_response(data)
return

experiments = self._get_experiments_list(data, bool(project_handles))
experiments = self._get_experiments_list(data, bool(project_ids))
except (ValueError, KeyError) as e:
self.logger.error("Error while parsing response data: {}".format(e))
else:
self._log_experiments_list(experiments)

@staticmethod
def _get_query_params(project_handles):
def _get_query_params(project_ids):
params = {"limit": -1} # so the API sends back full list without pagination
for i, handle in enumerate(project_handles):
for i, experiment_id in enumerate(project_ids):
key = "projectHandle[{}]".format(i)
params[key] = handle
params[key] = experiment_id

return params

@staticmethod
def _make_experiments_list_table(experiments):
data = [("Name", "Handle", "Status")]
data = [("Name", "ID", "Status")]
for experiment in experiments:
name = experiment["templateHistory"]["params"].get("name")
handle = experiment["handle"]
Expand All @@ -114,7 +114,7 @@ def _make_experiments_list_table(experiments):

@staticmethod
def _get_experiments_list(data, filtered=False):
if not filtered: # If filtering by projectHandle response data has different format...
if not filtered: # If filtering by project ID response data has different format...
return data["data"]

experiments = []
Expand All @@ -138,10 +138,10 @@ def _make_details_table(experiment):
if experiment["experimentTypeId"] == constants.ExperimentType.SINGLE_NODE:
data = (
("Name", experiment["templateHistory"]["params"].get("name")),
("Handle", experiment.get("handle")),
("ID", experiment.get("handle")),
("State", constants.ExperimentState.get_state_str(experiment.get("state"))),
("Ports", experiment["templateHistory"]["params"].get("ports")),
("Project Handle", experiment["templateHistory"]["params"].get("project_handle")),
("Project ID", experiment["templateHistory"]["params"].get("project_handle")),
("Worker Command", experiment["templateHistory"]["params"].get("worker_command")),
("Worker Container", experiment["templateHistory"]["params"].get("worker_container")),
("Worker Machine Type", experiment["templateHistory"]["params"].get("worker_machine_type")),
Expand All @@ -154,7 +154,7 @@ def _make_details_table(experiment):
constants.ExperimentType.MPI_MULTI_NODE):
data = (
("Name", experiment["templateHistory"]["params"].get("name")),
("Handle", experiment.get("handle")),
("ID", experiment.get("handle")),
("State", constants.ExperimentState.get_state_str(experiment.get("state"))),
("Artifact directory", experiment["templateHistory"]["params"].get("artifactDirectory")),
("Cluster ID", experiment["templateHistory"]["params"].get("clusterId")),
Expand All @@ -169,7 +169,7 @@ def _make_details_table(experiment):
("Parameter Server Machine Type",
experiment["templateHistory"]["params"].get("parameter_server_machine_type")),
("Ports", experiment["templateHistory"]["params"].get("ports")),
("Project Handle", experiment["templateHistory"]["params"].get("project_handle")),
("Project ID", experiment["templateHistory"]["params"].get("project_handle")),
("Worker Command", experiment["templateHistory"]["params"].get("worker_command")),
("Worker Container", experiment["templateHistory"]["params"].get("worker_container")),
("Worker Count", experiment["templateHistory"]["params"].get("worker_count")),
Expand All @@ -185,8 +185,8 @@ def _make_details_table(experiment):
return table_string


def get_experiment_details(experiment_handle, api=experiments_api):
url = "/experiments/{}/".format(experiment_handle)
def get_experiment_details(experiment_id, api=experiments_api):
url = "/experiments/{}/".format(experiment_id)
response = api.get(url)
details = response.content
if response.ok:
Expand Down
2 changes: 1 addition & 1 deletion tests/example_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@
}

LIST_OF_EXPERIMENTS_FILTERED_WITH_TWO_PROJECTS_STDOUT = """+--------+----------------+---------+
| Name | Handle | Status |
| Name | ID | Status |
+--------+----------------+---------+
| dsfads | esj8mcpaayh5kx | failed |
| dsfads | estun7jhqta8sm | failed |
Expand Down
Loading