Explore: CSV Sampling

Suggest edits
Documentation > Explore > Samplings


CSV Sampling 🔗

You can inject your own sampling in OpenMOLE through a CSV file. Considering a CSV file like this:
colD,  colFileName,    i
0.7,    fic1,           8
0.9,    fic2,           19
0.8,    fic2,           19
Here is an example of the CSVSampling used in a simple workflow to sample values stored in a file :
val i = Val[Int]
val o = Val[Int]
val d = Val[Double]
val f = Val[File]

val s = CSVSampling("/path/to/a/file.csv") set (
  columns += i,
  columns += ("colD", d),
  fileColumns += ("colFileName", "/path/of/the/base/dir/", f),
  // comma ',' is the default separator, but you can specify a different one using
  separator := ','

//Defines the "model" task, here it just takes i as input
val myModel =
  ScalaTask("val o = i * 2 ") set (
    inputs += i,
    outputs += (i,o)

// Define the exploration of myModel for various i values sampled in the file.
val exploration = DirectSampling(
  evaluation = myModel hook DisplayHook() ,
  sampling = s


In this example the column i in the CSV file is mapped to the variable i of OpenMOLE. The column name colD is mapped to the variable d. The column named colFileName is appended to the base directory "/path/of/the/base/dir/" and used as a file in OpenMOLE. As a sampling, the CSVSampling can directly be injected in an DirectSampling task. It will generate a different task for each entry in the file.