Explore with Custom Sampling

Suggest edits
Documentation > Explore > Samplings

Content:

1 - Write your own sampling
2 - Use your custom sampling in OpenMOLE


Write your own sampling 🔗

You can define a custom sampling in a CSV file and inject it in OpenMOLE. The provided CSV file must be formatted according to the following template:

colD, i
0.7,  8
0.9,  19
0.8,  19

Use your custom sampling in OpenMOLE 🔗

The CSVSampling task is used to import your custom sampling into OpenMOLE. Here is an example of how to use this task in a simple workflow:

val i = Val[Int]
val o = Val[Int]
val d = Val[Double]

// Define the sampling by mapping the columns of the CSV file to OpenMOLE variables
// comma ',' is the default separator, but you can specify a different one using
val mySampling = CSVSampling(workDirectory / "file.csv", separator = ',') set (
  outputs += i.mapped,
  outputs += d mapped "colD",

)

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

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

exploration

In this example the column i in the CSV file is mapped to the OpenMOLE variable i and colD is mapped to the OpenMOLE variable d.
As a sampling, the CSVSampling task can directly be injected in a DirectSampling task under the sampling parameter. It will generate a different task for each entry in the file.