Jobs

Job class

class schedy.Job(job_id, experiment, hyperparameters, status='QUEUED', results={}, etag=None)[source]

Represents a job instance belonging to an experiment. You should not need to create it by hand. Use schedy.Experiment.add_job(), schedy.Experiment.get_job(), schedy.Experiment.all_jobs() or schedy.Experiment.next_job() instead.

Jobs object are context managers, that it to say they can be used with a with statement. They will be put in the RUNNING state at the start of the with statement, and in the DONE or CRASHED state at the end (depending on whether an uncaught exception is raised within the with block). See schedy.Job.__enter__() for an example of how to use this feature.

Parameters:
  • job_id (str) – Unique id of the job.
  • experiment (schedy.Experiment) – Experiment containing this job.
  • hyperparameters (dict) – A dictionnary of hyperparameters values.
  • status (str) – Job status. See Job status.
  • results (dict) – A dictionnary of results values.
  • etag (str) – Value of the entity tag sent by the backend.
PRUNED = 'PRUNED'

Status of a job that was abandonned because it was not worth working on.

put(safe=True)[source]

Puts a job in the database, either by creating it or by updating it.

This function is always called at the end of a with block.

Parameters:safe (bool) – If true, this operation will make sure not to erase any content that would have been put by another Schedy call in the meantime. For example, this ensures that no two workers overwrite each other’s work on this job because they are working in parallel.
try_run()[source]

Try to set the status of the job as RUNNING, or raise an exception if another worker tried to do so before this one.

delete(ensure=True)[source]

Deletes this job from the Schedy service.

Parameters:ensure (bool) – If true, an exception will be raised if the job was deleted before this call.
__enter__()[source]

Context manager __enter__ method. Will try to set the job as CRASHED if the job has not been modified by another worker concurrently.

Example:

>>> db = schedy.SchedyDB()
>>> exp = db.get_experiment('Test')
>>> with exp.next_job() as job:
>>>     my_train_function(job)

If my_train_function raises an exception, the job will be marked as CRASHED. Otherwise it will be marked as DONE. (See py:meth:Job.__exit__.)

Note that since schedy.Experiment.next_job() will always return a RUNNING job, this method will never raise schedy.errors.UnsafeUpdateError in this case.

__exit__(exc_type, exc_value, traceback)[source]

Context manager __exit__ method. Will try to set the job status as CRASHED if an exception was raised in the with block. Otherwise, it will try to set the job status as DONE. It will also push all the updates that were made locally to the Schedy service (by calling Job.put() for you).

Job status

Job.QUEUED = 'QUEUED'

Status of a queued job. Queued jobs are returned when calling schedy.Experiment.next_job().

Job.RUNNING = 'RUNNING'

Status of a job that is currently running on a worker.

Job.CRASHED = 'CRASHED'

Status of job that was being processed by a worker, but the worker crashed before completing the job.

Job.DONE = 'DONE'

Status of a completed job.