Commit a22541da authored by Romain Reuillon's avatar Romain Reuillon
Browse files

[Plugin] enh: first implementation of direct sampling omr

parent 64c42c0b
......@@ -561,7 +561,6 @@ package composition {
implicit def by[T, B, P](implicit isContainer: ExplorationMethodSetter[T, P]): ExplorationMethodSetter[By[T, B], P] = (t, h) t.copy(value = isContainer(t.value, h))
implicit def on[T, B, P](implicit isContainer: ExplorationMethodSetter[T, P]): ExplorationMethodSetter[On[T, B], P] = (t, h) t.copy(value = isContainer(t.value, h))
implicit def hooked[T, P](implicit isContainer: ExplorationMethodSetter[T, P]): ExplorationMethodSetter[Hooked[T], P] = (t, h) t.copy(value = isContainer(t.value, h))
}
trait ExplorationMethodSetter[T, P] {
......
......@@ -58,6 +58,8 @@ object CSVOutputFormat {
}
override def validate(format: CSVOutputFormat) = format.header.option.toSeq.map(_.validate)
override def appendable(format: CSVOutputFormat): Boolean = format.append
}
}
......
......@@ -20,4 +20,5 @@ object OutputFormat {
trait OutputFormat[T, -M] {
def write(executionContext: HookExecutionContext)(format: T, output: WritableOutput, content: OutputFormat.OutputContent, method: M): FromContext[Unit]
def validate(format: T): Validate
def appendable(format: T) = false
}
\ No newline at end of file
......@@ -2,19 +2,23 @@ package org.openmole.core.workflow.hook
import org.openmole.core.context._
import org.openmole.core.exception.UserBadDataError
import org.openmole.core.expansion.FromContext
import org.openmole.core.expansion.{ FromContext, StringFromContext }
import org.openmole.core.workflow.builder._
import org.openmole.core.workflow.dsl._
import org.openmole.core.workflow.format.OutputFormat.PlainContent
import org.openmole.core.workflow.format._
object FormattedFileHook {
val experiment = Val[Long]("experiment", Variable.openMOLENameSpace)
def apply[T, M](
format: T,
output: WritableOutput,
values: Seq[Val[_]] = Vector.empty,
exclude: Seq[Val[_]] = Vector.empty,
metadata: M = None,
fileName: Option[String] = None,
name: Option[String] = None)(implicit valName: sourcecode.Name, definitionScope: DefinitionScope, fileFormat: OutputFormat[T, M]): FromContextHook =
Hook(name getOrElse "FileFormatHook") { parameters
......@@ -22,9 +26,12 @@ object FormattedFileHook {
val excludeSet = exclude.map(_.name).toSet
val ps = { if (values.isEmpty) context.variables.values.map { _.prototype }.toVector else values }.filter { v !excludeSet.contains(v.name) }
val variables = ps.map(p context.variable(p).getOrElse(throw new UserBadDataError(s"Variable $p not found in hook $this")))
fileFormat.write(executionContext)(format, output, variables, metadata).from(context)
val experimentContext: Context = context + Variable(experiment, executionContext.ticket.content)
val variables = (ps ++ Seq(experiment)).map(p experimentContext.variable(p).getOrElse(throw new UserBadDataError(s"Variable $p not found in hook $this")))
val content = PlainContent(variables = variables, name = fileName.map(StringFromContext.fromString))
fileFormat.write(executionContext)(format, output, content, metadata).from(experimentContext)
context
} withValidate { WritableOutput.file(output).toSeq.flatMap(_.validate) ++ fileFormat.validate(format) } set (inputs += (values: _*))
......
......@@ -176,7 +176,8 @@ package object directsampling {
val dsl = method(t)
implicit val defScope = dsl.scope
val metadata = DirectSamplingMetadata.DirectSampling(dsl.method.sampled.map(_.name), dsl.method.aggregation.map(DirectSamplingMetadata.aggregation))
Hooked(t, FormattedFileHook(output = output, values = values, format = format, metadata = metadata))
def fileName = if (outputFormat.appendable(format)) None else Some("experiment${" + FormattedFileHook.experiment.name + "}")
Hooked(t, FormattedFileHook(output = output, values = values, format = format, metadata = metadata, fileName = fileName))
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment