playmolecule.job module#
- class playmolecule.job.Job(session, appid, execid=None, job_json=None, strict=True)#
Bases:
ProtocolInterface
Create a Job object given the user session and an app id.
- Parameters
session (Session) – The user session
appid (str) – The app ID
execid (str) – The ID of the job if it has already been submited
job_json (dict) – A dictionary from which to instantiate the job. Useful when creating a job from data from the API
strict (bool) – If strict is True, Job creation will fail if not able to load correctly existing app configuration into the Job.
- cancel(_logger=True)#
Cancel the job
Cancels the job. This will set the status to ERROR and stop any running execution (children as well)
- describe(_logger=True)#
Describes the input parameters of an application
- get_children(status=None, return_dict=False, _logger=True)#
Returns the children of the job.
- Parameters
- Returns
children – The children of the job
- Return type
- get_error_info(_logger=True)#
Get information related to an errored job
- get_progress(_logger=True)#
Prints the job progress.
- Parameters
_logger (bool) – Set as True for printing the info and errors in sys.stdout. If False, it returns the same information as an object (default=True).
- Returns
info (str) – The information on the current progress
completion (str) – The completion percentage
- get_status(_logger=True)#
Prints or returns the job status
- read_arguments(filename, ftype='yaml')#
Reads argument values of the job from a json or yaml file
- retrieve(path=None, force=False, skip=False, on_status=(<JobStatus.RUNNING: 3>, <JobStatus.COMPLETED: 4>, <JobStatus.ERROR: 5>, <JobStatus.SLEEPING: 7>), attempts=5, execid_subdir=True, tmpdir=None, _logger=True)#
Retrieve the results of a job execution.
The output will be retrieved in the working directory if the argument path is not passed, inside a folder with the id job as a name. If this folder already exists, another one with a timestamp will be created. If the job has not completed, the function will try to download intermediate results.
- Parameters
path (str) – Destination folder
force (bool) – If the destination folder exists and force == True, the destination folder will be removed.
skip (bool) – If the destination folder exists and skip == True, nothing will be performed.
on_status (list or JobStatus) – Restrict at which job status the results will be retrieved
attempts (int) – How many times to attempt downloading the data from minio
execid_subdir (bool) – If True it will create a subdirectory inside path with the execution ID as name and retrieve the results there
tmpdir (str) – Set a different directory for storing temporary files. If set to None it defaults to /tmp/
_logger (bool) – Set as True for printing the info and errors in sys.stdout. If False, it returns the same information as an object (default=True).
- Returns
path – The destination path of the retrieved data
- Return type
Examples
>>> job.retrieve("./results/", on_status=(JobStatus.COMPLETED, JobStatus.ERROR))
- submit(child_of=None, queue_config=None, _logger=True)#
Submits the job to the PlayMolecule backend server.
- Parameters
child_of (str) – The id of another job. If provided, the new job will be submited as a child of that job.
queue_config (dict) – A dictionary containing key-value pairs for defailed configuration for this job on the queueing system. You can specify “cpus”, “memory” and “priority” for the job.
_logger (bool) – Set to False to reduce verbosity
Examples
>>> job = sess.start_app("proteinprepare") >>> job.pdbid = "3ptb" >>> job.submit(queue_config={"ncpu": 2, "memory": 4000, "priority": 500})
- wait(on_status=(<JobStatus.COMPLETED: 4>, <JobStatus.ERROR: 5>), seconds=10, _logger=True, _return_dataset=True)#
Blocks execution until the job has reached the specific status or any of a list of statuses.
- wait_children(on_status=(<JobStatus.COMPLETED: 4>, <JobStatus.ERROR: 5>), seconds=10, _logger=True)#
Blocks execution until all the children of the job have reached the given status
- write_arguments(filename, ftype='yaml')#
Writes the current argument values of the job to a json or yaml file
- class playmolecule.job.JobStatus(value)#
Bases:
IntEnum
Job status codes describing the current status of a job
WAITING_DATA : Waiting for communication fromm the job. Job has not reached the queue yet for computation. VALIDATING : Job is pending validation by admins WAITING_APPROVAL : Job is pending approval by admins RUNNING : Job is currently running COMPLETED : Job has successfully completed ERROR : Job has exited with an error QUEUED : Job is queued for execution SLEEPING : Job is sleeping and will be respawned soon. Used by periodically executing apps.
- COMPLETED = 4#
- ERROR = 5#
- QUEUED = 6#
- RUNNING = 3#
- SLEEPING = 7#
- VALIDATING = 1#
- WAITING_APPROVAL = 2#
- WAITING_DATA = 0#
- describe()#
- playmolecule.job.short_execid(execid)#
Returns the short execution ID of a job from the full execution ID