Skip to content

Instantly share code, notes, and snippets.

@Autoplectic
Created April 23, 2015 06:36
Show Gist options
  • Save Autoplectic/2b154ccc8883cdd919f9 to your computer and use it in GitHub Desktop.
Save Autoplectic/2b154ccc8883cdd919f9 to your computer and use it in GitHub Desktop.
"""
This is an example script for use with dispatcher.py. It is manditory to define three things:
- NAME: the base name to give all jobs.
- params: a function that transforms global parameters to a set of local parameters.
- compute: a function that takes in local parameters and performs the desired computation.
"""
from logbook import Logger
# dispatcher.py has a logbook handler all set up, so we just need a logger.
# Using a log is completely optional.
LOG = Logger('script')
# The first of three things that need to be defined.
NAME = 'test_run'
# The second of three things that need to be defined.
def params(n):
"""
This function takes in global parameters (min and max temperature, number of iterations, etc)
and returns local parameters -- the ones that will be passed to each compute node. In this
trivial example we pass in the maximum value to go up to, and yield each integer up to that
value.
"""
for i in xrange(n):
yield i
# The third of three things that need to be defined.
def compute(i):
"""
Here we do nothing fancy -- just send to the log the square of the parameter.
"""
LOG.info("{}**2 is {}".format(i, i**2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment