Posts for the month of April 2010

Mole example using a model in a plugin

In this example we want to distribute replications of a genetic algorithm for solving the TSP problem. The sources of this library are available here for browsing and here for checkout. The way to turn a maven project into an OSGi bundle and by consequence an OpenMOLE plugin is described here.

First import needed packages and load the platform plugins.

plugin.loadDir('openmole-plugins')
import org.openmole.core.workflow.implementation.data.*
import org.openmole.core.workflow.implementation.transition.*
import org.openmole.core.workflow.implementation.mole.Mole
import org.openmole.core.workflow.implementation.task.*
import org.openmole.core.workflow.implementation.capsule.*
import org.openmole.core.workflow.implementation.plan.*
import org.openmole.core.workflow.implementation.domain.*
import org.openmole.core.workflow.implementation.resource.*
import org.openmole.core.workflow.implementation.mole.execution.*
import org.openmole.plugin.plan.completeplan.*
import org.openmole.plugin.task.groovytask.*
import org.openmole.plugin.domain.interval.*
import org.openmole.plugin.environmentprovider.glite.*
import org.openmole.plugin.task.storeintocsvtask.*

Then define paths for future use.

tspPlugin = '/iscpif/users/reuillon/NetBeansProjects/tsp/target/tsp-1.0-SNAPSHOT.jar'
tspDir = "/iscpif/users/reuillon/work/TSP"
tspFilePath = new File(tspDir, "att48.tsp")

Load the user-crafted plugin containing the classes for solving the TSP.

plugin.load(tspPlugin)
import org.openmole.tools.distrng.prng.*
import org.openmole.tools.distrng.prng.parallelization.*

Configure a grid environment.

baseCheckoutDir = '/iscpif/users/reuillon/tmp/openmole/'
runtime = baseCheckoutDir + "runtime/org.openmole.runtime/target/org.openmole.runtime-0.3.tar.bz2"
desc = new GliteEnvironmentDescription("vo.iscpif.fr", "voms://grid12.lal.in2p3.fr:20013/O=GRID-FR/C=FR/O=CNRS/OU=LAL/CN=grid12.lal.in2p3.fr", "ldap://topbdii.grif.fr:2170")
env = desc.getMatching()
env.setRuntime(runtime)

Declare 3 variables. TspFile contains a description of the TSP problem to solve. The distance is a double containing the length of the best solution found by the algorithm. Rng contains a pseudo-random number generator (PRNG).

tspFile = new Prototype("tspFile", File)
distance = new Prototype("distance", Double)
rng = new Prototype("rng", IPRNG)

Configure the parallelization of the random number generator. This facility is provided by the DistRNG libraries of the OpenMOLETools libraries. The TSP model has been built on top of this library.

secureRandomRNG = new SecureRandomRNG()
indexSequence = new IndexSequence(secureRandomRNG, WELL1024)

Define a complete plan for exploring 1000 independent state of the WELL1024 pseudo-random number generator.

plan = new CompletePlan()
plan.addFactor(new Factor(rng, new SampledDomain(new IteratorDomain( indexSequence ), 1000)))

Build the exploration task.

explorationTask = new ExplorationTask("exploration", plan)

Define the task for launching the tsp solver. This task has a parameter: the file describing the TSP problem, an input: the PRNG, an output: the distance of the shorter path found by the genetic algorithm. It uses one resource: the plugin containing the TSP solving classes.

// Second task consumes the variable
tspTask = new GroovyTask("TSP task")
tspTask.addImport('fr.iscpif.tsp.*')
tspTask.addImport('org.openmole.tools.distrng.prng.*')
tspTask.setCode("tsp = new Tsp(tspFile); distance = tsp.computeShorterPath(1000000,2000000000,rng).getDistance()")
tspTask.addResource(new PluginResource(tspPlugin))
tspTask.addParameter(tspFile, tspFilePath)
tspTask.addInput(rng)
tspTask.addOutput(distance)

Define a task for storing the results in a CSV file. The result is an array of double because this task stands right after the aggregation transition.

//store the results
storeTask = new StoreIntoCSVTask("storeTask", tspDir + "/distances" + System.currentTimeMillis() +".csv")
storeTask.addColumn(distance.array())

Define the capsules.

explorationTaskCaps = new ExplorationTaskCapsule(explorationTask)
tspTaskCaps = new TaskCapsule(tspTask)
storeTaskCaps = new TaskCapsule(storeTask)

Define the transitions.

new ExplorationTransition(explorationTaskCaps, tspTaskCaps)
new AggregationTransition(tspTaskCaps, storeTaskCaps)
strat = new FixedEnvironmentStrategy()

Set the computational grid as the execution environment of the task capsule.

strat.setEnvironment(tspTaskCaps,env)

Build the Mole and execute it.

ex = new Mole(explorationTaskCaps).createExecution(strat)
ex.start()

logo cemagref

logo iscpif

logo lifegrid

logo region auvergne

logo patres project