Explore with Sampling From a File

Suggest edits
Documentation > Explore > Samplings

Content:

1 - Read a sampling from a CSV file
2 - Read a sampling from an OMR file


Read a sampling from a CSV file 🔗

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
The CSVSampling is used to import your custom sampling into OpenMOLE. Here is an example of how to use this sampling 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.

Read a sampling from an OMR file 🔗

You can reload some result data and use them as a sampling using the OMRSampling:
val i = Val[Int]
val d = Val[Double]

val o = Val[Int]

// Define the sampling by specifying the OMR File and the array variables you want to load
val mySampling = OMRSampling(workDirectory / "file.omr", Seq(i, d))

// 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
DirectSampling(
  evaluation = myModel,
  sampling = mySampling
) hook display
The OMR file must contain the variable i and d, and they must respectively Array[Int] and Array[Double].