Getting started

Hello world

OAR job that prints “Hello world” to the standard output.

Minimal

[1]:
from oarpy import oarjob

jobdef = oarjob.JobFactory(command='echo "Hello word"')
job = jobdef.submit()
print(job)
job.wait()

if job.exit_code:
    print('Failed:\n{}'.format(job.stderr))
elif job.exit_code is None:
    print('Interrupted:\n{}'.format(job.stdout))
else:
    print('Succes:\n{}'.format(job.stdout))
job.remove_logs()
Job(1130826)
 name = OAR
 project = default
 state = Waiting
 owner = denolf
 runtime = 0:00:00
........
Succes:
Hello word

With resources and postponed execution

[2]:
from oarpy import oarjob
from oarpy.oarresource import Resource

resource = Resource(core=1, walltime={'hours':1,'minutes':30}, gpu=False)
jobdef = oarjob.JobFactory(name='helloworld', project='oarpy',
                           command='echo "Hello word"', resource=resource)

job = jobdef.submit(hold=True)
print(job)
job.wait(states='Hold')
# job is waiting for you to resume it
job.resume()
job.wait()

if job.exit_code:
    print('Failed:\n{}'.format(job.stderr))
elif job.exit_code is None:
    print('Interrupted:\n{}'.format(job.stdout))
else:
    print('Succes:\n{}'.format(job.stdout))
job.remove_logs()
Job(1130827)
 name = helloworld
 project = oarpy
 state = Hold
 owner = denolf
 runtime = 0:00:00
...............
Succes:
Hello word

Job management

Find all jobs started in the last 5 minutes:

[3]:
from oarpy import oarjob
from oarpy import timeutils

start = timeutils.add(timeutils.now(), minutes=-1)
jobs = oarjob.search(start=start)
print(sorted(jobs))
print(set([(job['owner'], job.status) for job in jobs]))
[Job(1130826), Job(1130827), Job(976220)]
set([(u'ljacques', u'Error'), (u'denolf', u'Terminated')])

Retrieve job definition (can be used to resubmit a job):

[4]:
from oarpy import oarjob

job = oarjob.Job(1103714)
if job.exists:
    jobdef = job.definition
    stats = job.stats
    print('Initial request:\n {}\n'.format(stats['initial_request']))
    print('Wanted resources:\n {}\n'.format(stats['wanted_resources']))
    print('Properties:\n {}\n'.format(stats['properties']))
    print('Job resource:\n {}\n'.format(jobdef.resource))
    print('Job definition:\n {}\n'.format(jobdef))
Initial request:


Wanted resources:
 -l "{type = 'default'}/host=1/core=16,walltime=16:0:0"

Properties:
 (((((gpu='YES') AND desktop_computing = 'NO') AND cluster = 'NICE') AND opsys = 'debian8') AND interactive = 'MIXED') AND drain='NO'

Job resource:
 -l nodes=1/core=16,walltime=16:00:00 -p "gpu='YES' and drain='NO'"

Job definition:
 -n Gecko_2_0p7um_2474_3031__001_.par --project default -d /mntdirect/_data_visitor/md1189/id17/GeckosHR/Gecko_2/Gecko_2_0p7um_2474_3031__001_/Slices -O OAR.Gecko_2_0p7um_2474_3031__001_.par.%jobid%.stdout -E OAR.Gecko_2_0p7um_2474_3031__001_.par.%jobid%.stderr -l nodes=1/core=16,walltime=16:00:00 -p "gpu='YES' and drain='NO'" /mntdirect/_data_visitor/md1189/id17/GeckosHR/Gecko_2/Gecko_2_0p7um_2474_3031__001_/Slices//./tmpmd1189.sh

Remove the log files of all succesfully finished jobs of a particular user and project:

[5]:
from oarpy import oarjob
jobs = oarjob.search(owner='testuser', project='oarpy', state='Terminated')
for job in jobs:
    job.remove_logs()