MikeDacre / fyrd

Submit functions and shell scripts to torque and slurm clusters or local machines using python.
https://fyrd.science
MIT License
22 stars 8 forks source link

Add decorator definitions #30

Closed MikeDacre closed 7 years ago

MikeDacre commented 8 years ago

I want folks to be able to add a simple decorator to a function to make it submit to the cluster when called.

MikeDacre commented 7 years ago

This can be done with a three layer decorator:

>>> class Job:
... 
...     def __init__(self, command, args, kwds, profile):
...         self.command = command
...         self.args = args
...         self.kwds = kwds
...         self.profile = profile
... 
...     def submit(self):
...         self.command(*self.args, **self.kwds)
... 
...     def __repr__(self):
...         return "Im a Job, and my name is {0}".format(self.profile)
... 
>>> def make_job(profile=None):
...     def deco(func):
...         def wrapper(*args, **kwds):
...             job = Job(func, args, kwds, profile)
...             return job
...         return wrapper
...     return deco
... 
>>> @make_job(profile='bob')
... def hi(instr):
...     print('Hi {0}!'.format(instr))
... 
>>> j = hi('vincent')
>>> j
Im a Job, and my name is bob
>>> j.submit()
Hi vincent!

This will allow people to make any random function a job.

MikeDacre commented 7 years ago

Now implemented and functional in 0.6.2

MikeDacre commented 7 years ago

Closing as done in 0.6.2