Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Serialize jobenv to envVars PS-15020 #325

Merged
merged 9 commits into from
Sep 25, 2020
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions gradient/api_sdk/clients/job_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def create(
working_directory=None,
experiment_id=None,
job_env=None,
env_vars=None,
use_dockerfile=None,
is_preemptible=None,
project=None,
Expand Down Expand Up @@ -75,7 +76,7 @@ def create(
name='Example job',
command='pip install -r requirements.txt && python mnist.py',
ports='5000:5000',
job_env={
env_vars={
'CUSTOM_ENV'='Some value that will be set as system environment',
paperspace-philip marked this conversation as resolved.
Show resolved Hide resolved
}
)
Expand Down Expand Up @@ -113,7 +114,8 @@ def create(
:param str working_directory: location of code to run. By default ``/paperspace``
:param str experiment_id: Id of experiment to which job should be connected. If not provided there will be
created new experiment for this job.
:param dict job_env: key value collection of envs that are used in code
:param dict job_env: key value collection of envs that are used in code (deprecated)
paperspace-philip marked this conversation as resolved.
Show resolved Hide resolved
:param dict env_vars: key value collection of envs that are used in code
:param bool use_dockerfile: determines whether to build from Dockerfile (default false).
Do not include a --container argument when using this flag.
:param bool is_preemptible: flag if we you want to use spot instance. By default False
Expand Down Expand Up @@ -152,6 +154,7 @@ def create(
working_directory=working_directory,
experiment_id=experiment_id,
job_env=job_env,
env_vars=env_vars,
use_dockerfile=use_dockerfile,
is_preemptible=is_preemptible,
project=project,
Expand Down
1 change: 1 addition & 0 deletions gradient/api_sdk/models/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class Job(object):
tpu_model_dir = attr.ib(type=str, default=None)
target_node_attrs = attr.ib(type=dict, default=None)
job_env = attr.ib(type=dict, default=None)
env_vars = attr.ib(type=dict, default=None)
shared_mem_mbytes = attr.ib(type=int, default=None)
shutdown_timeout = attr.ib(type=int, default=None)
is_preemptible = attr.ib(type=bool, default=None)
Expand Down
17 changes: 17 additions & 0 deletions gradient/api_sdk/serializers/job.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
import json

import marshmallow

from .base import BaseSchema
from .. import models


class JSONField(marshmallow.fields.Field):
"""Field that serializes to json
"""

def _serialize(self, value, attr, obj, **kwargs):
if value is None:
return None

return json.dumps(value)

def _deserialize(self, value, attr, data, **kwargs):
return value


class JobSchema(BaseSchema):
MODEL = models.Job

Expand Down Expand Up @@ -71,6 +87,7 @@ class JobSchema(BaseSchema):
tpu_model_dir = marshmallow.fields.Str(dump_to="tpuModelDir", load_from="tpuModelDir")
target_node_attrs = marshmallow.fields.Dict(dump_to="targetNodeAttrs", load_from="targetNodeAttrs")
job_env = marshmallow.fields.Dict(dump_to="jobEnv", load_from="jobEnv")
env_vars = JSONField(dump_to="envVars", load_from="envVars")
shared_mem_mbytes = marshmallow.fields.Int(dump_to="sharedMemMBytes", load_from="sharedMemMBytes")
shutdown_timeout = marshmallow.fields.Int(dump_to="shutdownTimeout", load_from="shutdownTimeout")
is_preemptible = marshmallow.fields.Bool(dump_to="isPreemptible", load_from="isPreemptible")
Expand Down
9 changes: 8 additions & 1 deletion gradient/cli/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,14 @@ def common_jobs_create_options(f):
"--jobEnv",
"job_env",
type=json_string,
help="Environmental variables ",
help="Environmental variables (deprecated)",
cls=common.GradientOption,
),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I'd probably just remove this. If you want to support the old flag you can just add it to the --envVars option.

click.option(
"--envVars",
"env_vars",
type=json_string,
help="Environmental variables",
cls=common.GradientOption,
),
click.option(
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ class TestJobsCreate(object):
"registryTarget": "some_registry_target",
"isPublic": True,
"workspaceFileName": "s3://some-path",
"jobEnv": {"key": "val"},
"envVars": '{"key": "val"}',
"useDockerfile": True,
"name": "some_name",
"relDockerfilePath": "some dockerfile path",
Expand Down