Skip to content

Commit

Permalink
Add in_cluster notebook detection
Browse files Browse the repository at this point in the history
  • Loading branch information
mmourafiq committed Feb 18, 2019
1 parent dc239a4 commit 861f62e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
29 changes: 29 additions & 0 deletions polyaxon_client/tracking/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
from __future__ import absolute_import, division, print_function

import atexit
import json
import os
import sys
import time

from polystores.stores.manager import StoreManager

from polyaxon_client import PolyaxonClient, settings
from polyaxon_client.exceptions import PolyaxonClientException
from polyaxon_client.tracking.in_cluster import ensure_in_custer
from polyaxon_client.tracking.paths import get_outputs_path
from polyaxon_client.tracking.utils.project import get_project_info

Expand All @@ -28,6 +31,9 @@ def __init__(self,

if not settings.IN_CLUSTER and project is None:
raise PolyaxonClientException('Please provide a valid project.')
elif self.is_notebook_job:
job_info = self.get_notebook_job_info()
project = job_info['project_name']

self.last_status = None
self.client = client or PolyaxonClient()
Expand All @@ -52,6 +58,29 @@ def __init__(self,
if outputs_store is None and settings.IN_CLUSTER and self.REQUIRES_OUTPUTS:
self.set_outputs_store(outputs_path=get_outputs_path(), set_env_vars=True)

def get_notebook_job_info(self):
if settings.NO_OP:
return None

ensure_in_custer()

info = os.getenv('POLYAXON_NOTEBOOK_INFO', None)
try:
return json.loads(info) if info else None
except (ValueError, TypeError):
print('Could get experiment info, '
'please make sure this is running inside a polyaxon job.')
return None

@property
def is_notebook_job(self):
if settings.NO_OP:
return None

ensure_in_custer()

return 'POLYAXON_NOTEBOOK_INFO' in os.environ

def get_data(self):
raise NotImplementedError

Expand Down
4 changes: 2 additions & 2 deletions polyaxon_client/tracking/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(self,
if settings.NO_OP:
return

if project is None and settings.IN_CLUSTER:
if project is None and settings.IN_CLUSTER and not self.is_notebook_job:
experiment_info = self.get_experiment_info()
project = experiment_info['project_name']
experiment_id = experiment_info['experiment_name'].split('.')[-1]
Expand Down Expand Up @@ -67,7 +67,7 @@ def __init__(self,
self._set_health_url()

# Track run env
if settings.IN_CLUSTER and self.track_env:
if settings.IN_CLUSTER and self.track_env and not self.is_notebook_job:
self.log_run_env()

def get_data(self):
Expand Down
2 changes: 1 addition & 1 deletion polyaxon_client/tracking/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(self,
if settings.NO_OP:
return

if project is None and settings.IN_CLUSTER:
if project is None and settings.IN_CLUSTER and not self.is_notebook_job:
job_info = self.get_job_info()
project = job_info['project_name']
job_id = job_info['job_name'].split('.')[-1]
Expand Down

0 comments on commit 861f62e

Please sign in to comment.