Commit 5e923e87 authored by Romain Reuillon's avatar Romain Reuillon
Browse files

[Plugin] enh: implement save method

parent d2e44c79
Pipeline #99 failed with stage
in 6 minutes and 22 seconds
......@@ -461,7 +461,7 @@ lazy val evolution = OsgiProject(pluginDir, "org.openmole.plugin.method.evolutio
lazy val abc = OsgiProject(pluginDir, "org.openmole.plugin.method.abc", imports = Seq("*")) dependsOn(openmoleDSL, csvTool, toolsTask, pattern) settings
(libraryDependencies += Libraries.mgo, libraryDependencies += Libraries.shapeless) settings (pluginSettings: _*)
lazy val directSampling = OsgiProject(pluginDir, "org.openmole.plugin.method.directsampling", imports = Seq("*")) dependsOn(openmoleDSL, distributionDomain, pattern, modifierDomain) settings (pluginSettings: _*)
lazy val directSampling = OsgiProject(pluginDir, "org.openmole.plugin.method.directsampling", imports = Seq("*")) dependsOn(openmoleDSL, distributionDomain, pattern, modifierDomain, fileHook) settings (pluginSettings: _*)
lazy val sensitivity = OsgiProject(pluginDir, "org.openmole.plugin.method.sensitivity", imports = Seq("*")) dependsOn(exception, workflow, workspace, openmoleDSL, lhsSampling, directSampling) settings (pluginSettings: _*)
......
......@@ -29,51 +29,51 @@ object Variable {
def openMOLENameSpace = Namespace("openmole")
/**
* implicit conversion of a tuple (prototype,value) to a Variable
* @param t
* @tparam T
* @return
*/
* implicit conversion of a tuple (prototype,value) to a Variable
* @param t
* @tparam T
* @return
*/
implicit def tupleWithValToVariable[T](t: (Val[T], T)) = apply(t._1, t._2)
/**
* implicit conversion of tuple (prototype name, value)
* @param t
* @tparam T
* @return
*/
* implicit conversion of tuple (prototype name, value)
* @param t
* @tparam T
* @return
*/
implicit def tupleToVariable[T: Manifest](t: (String, T)) = apply(Val[T](t._1), t._2)
/**
* Unsecure constructor, trying to cast the provided value to the type of the prototype
* @param p prototype
* @param v value
* @tparam T
* @return
*/
* Unsecure constructor, trying to cast the provided value to the type of the prototype
* @param p prototype
* @param v value
* @tparam T
* @return
*/
def unsecure[T](p: Val[T], v: Any) = Variable[T](p, v.asInstanceOf[T])
/**
* Variable defined by OpenMOLE
* @param name
* @return
*/
* Variable defined by OpenMOLE
* @param name
* @return
*/
def openMOLE(name: String) = Val[Long](name, namespace = openMOLENameSpace)
/**
* Seed for rng
*/
* Seed for rng
*/
val openMOLESeed = openMOLE("seed")
def copy[T](v: Variable[T])(prototype: Val[T] = v.prototype, value: T = v.value) = apply(prototype, value)
}
/**
* A Variable is a prototype with a value
* @param prototype the prototype
* @param value the value
* @tparam T type of the Variable
*/
* A Variable is a prototype with a value
* @param prototype the prototype
* @param value the value
* @tparam T type of the Variable
*/
case class Variable[T](prototype: Val[T], value: T) {
override def toString: String = prettified(Int.MaxValue)
def prettified(snipArray: Int) = prototype.name + "=" + (if (value != null) value.prettify(snipArray) else "null")
......
......@@ -21,11 +21,8 @@ package dsl {
import org.openmole.core.context._
import org.openmole.core.logconfig.LoggerConfig
import org.openmole.core.workspace._
import cats._
import org.openmole.tool.crypto.Cypher
import org.openmole.tool.types._
import squants._
import squants.information._
trait DSLPackage <: Commands
......@@ -79,6 +76,20 @@ package dsl {
type Data = File
}
object extension {
type FromContext[T] = org.openmole.core.expansion.FromContext[T]
def FromContext = org.openmole.core.expansion.FromContext
type DefinitionScope = org.openmole.core.workflow.builder.DefinitionScope
def DefinitionScope = org.openmole.core.workflow.builder.DefinitionScope
type ScalarOrSequenceOfDouble[T] = org.openmole.core.workflow.tools.ScalarOrSequenceOfDouble[T]
def ScalarOrSequenceOfDouble = org.openmole.core.workflow.tools.ScalarOrSequenceOfDouble
type Task = org.openmole.core.workflow.task.Task
def Task = org.openmole.core.workflow.task.Task
}
}
package object dsl extends DSLPackage
......@@ -30,8 +30,8 @@ import scala.collection.mutable.ListBuffer
import scala.util.Try
/**
* Methods to parse code strings
*/
* Methods to parse code strings
*/
object ExpandedString {
implicit def fromStringToVariableExpansion(s: String) = ExpandedString(s)
......@@ -103,8 +103,8 @@ object ExpandedString {
}
/**
* An ExpandedElement distinguishes between value strings and code strings
*/
* An ExpandedElement distinguishes between value strings and code strings
*/
object ExpandedElement {
def apply(code: String): ExpansionElement = {
if (code.isEmpty) ValueElement(code)
......
......@@ -69,19 +69,19 @@ trait LowPriorityFromContext {
def contextConverter[F, T](f: F)(implicit tfc: ToFromContext[F, T]): FromContext[T] = tfc(f)
/**
* implicit converter of a value to a FromContext (using implicit [[LowPriorityToFromContext]])
* @param t
* @tparam T
* @return
*/
* implicit converter of a value to a FromContext (using implicit [[LowPriorityToFromContext]])
* @param t
* @tparam T
* @return
*/
implicit def fromTToContext[T](t: T): FromContext[T] = contextConverter(t)
}
object FromContext extends LowPriorityFromContext {
/**
* A [[FromContext]] can be seen as a monad
*/
* A [[FromContext]] can be seen as a monad
*/
object asMonad {
implicit val monad: Monad[FromContext] = new Monad[FromContext] {
def tailRecM[A, B](a: A)(f: A FromContext[Either[A, B]]): FromContext[B] = {
......@@ -109,8 +109,8 @@ object FromContext extends LowPriorityFromContext {
}
/**
* Implicitly define an Applicative on FromContext
*/
* Implicitly define an Applicative on FromContext
*/
implicit val applicative: Applicative[FromContext] = new Applicative[FromContext] {
override def pure[A](x: A): FromContext[A] = FromContext.value(x)
override def ap[A, B](ff: FromContext[(A) B])(fa: FromContext[A]): FromContext[B] =
......@@ -126,12 +126,12 @@ object FromContext extends LowPriorityFromContext {
}
/**
* Convert scala code to a FromContext (code is compiled by [[ScalaCompilation]])
*
* @param code
* @tparam T
* @return
*/
* Convert scala code to a FromContext (code is compiled by [[ScalaCompilation]])
*
* @param code
* @tparam T
* @return
*/
def codeToFromContext[T: Manifest](code: String): FromContext[T] =
new FromContext[T] {
val proxy = Cache(ScalaCompilation.dynamic[T](code))
......@@ -157,11 +157,11 @@ object FromContext extends LowPriorityFromContext {
implicit def prototypeIsFromContext[T](p: Val[T]) = contextConverter[Val[T], T](p)
/**
* FromContext for a given prototype
* @param p
* @tparam T
* @return
*/
* FromContext for a given prototype
* @param p
* @tparam T
* @return
*/
def prototype[T](p: Val[T]) =
new FromContext[T] {
override def from(context: Context)(implicit rng: RandomProvider, newFile: NewFile, fileService: FileService) = context(p)
......@@ -171,11 +171,11 @@ object FromContext extends LowPriorityFromContext {
}
/**
* From context for a given value
* @param t
* @tparam T
* @return
*/
* From context for a given value
* @param t
* @tparam T
* @return
*/
def value[T](t: T): FromContext[T] =
new FromContext[T] {
def from(context: Context)(implicit rng: RandomProvider, newFile: NewFile, fileService: FileService): T = t
......@@ -183,20 +183,20 @@ object FromContext extends LowPriorityFromContext {
}
/**
* Parameters wrap a Context and implicit services
* @param context
* @param random
* @param newFile
* @param fileService
*/
* Parameters wrap a Context and implicit services
* @param context
* @param random
* @param newFile
* @param fileService
*/
case class Parameters(context: Context, implicit val random: RandomProvider, implicit val newFile: NewFile, implicit val fileService: FileService)
/**
* Construct a FromContext from a function of [[Parameters]]
* @param f
* @tparam T
* @return
*/
* Construct a FromContext from a function of [[Parameters]]
* @param f
* @tparam T
* @return
*/
def apply[T](f: Parameters T): FromContext[T] =
new FromContext[T] {
def from(context: Context)(implicit rng: RandomProvider, newFile: NewFile, fileService: FileService) = f(Parameters(context, rng, newFile, fileService))
......@@ -204,12 +204,12 @@ object FromContext extends LowPriorityFromContext {
}
/**
* Construct a FromContext from a function of [[Parameters]], with an additional list of FromContext which must be validated on inputs
* @param validated
* @param f
* @tparam T
* @return
*/
* Construct a FromContext from a function of [[Parameters]], with an additional list of FromContext which must be validated on inputs
* @param validated
* @param f
* @tparam T
* @return
*/
def withValidation[T](validated: FromContext[_]*)(f: Parameters T) =
new FromContext[T] {
def from(context: Context)(implicit rng: RandomProvider, newFile: NewFile, fileService: FileService) = f(Parameters(context, rng, newFile, fileService))
......@@ -217,9 +217,9 @@ object FromContext extends LowPriorityFromContext {
}
/**
* Operators for boolean FromContext ([[Condition]] ~ FromContext[Boolean])
* @param f
*/
* Operators for boolean FromContext ([[Condition]] ~ FromContext[Boolean])
* @param f
*/
implicit class ConditionDecorator(f: Condition) {
def unary_! = f.map(v !v)
......
......@@ -31,23 +31,23 @@ object InputOutputConfig {
}
/**
* Operator to add inputs and outputs to a config
* @param inputs
* @param outputs
* @return
*/
* Operator to add inputs and outputs to a config
* @param inputs
* @param outputs
* @return
*/
def add(inputs: Seq[Val[_]] = Seq.empty, outputs: Seq[Val[_]] = Seq.empty) =
InputOutputConfig.inputs.modify(_ ++ outputs) andThen
InputOutputConfig.outputs.modify(_ ++ outputs)
}
/**
* Input/Output configuration for tasks, hooks and sources
*
* @param inputs prototype set of inputs
* @param outputs prototype set of outputs
* @param defaults default values for prototypes
*/
* Input/Output configuration for tasks, hooks and sources
*
* @param inputs prototype set of inputs
* @param outputs prototype set of outputs
* @param defaults default values for prototypes
*/
@Lenses case class InputOutputConfig(
inputs: PrototypeSet = PrototypeSet.empty,
outputs: PrototypeSet = PrototypeSet.empty,
......
......@@ -261,6 +261,18 @@ package composition {
val delegate = container.delegate.map { t TaskNode(t, environment = container.environment, grouping = container.grouping) }
delegate ++ output
}
trait Extension[T] {
def lens: monocle.Lens[T, DSLContainer]
}
case class Extended[T](t: T)(implicit extension: Extension[T]) {
def on(environment: EnvironmentProvider) = extension.lens.modify(_.on(environment))(t)
def by(strategy: Grouping) = extension.lens.modify(_.by(strategy))(t)
def hook(hooks: Hook*) = extension.lens.modify(_.hook(hooks: _*))(t)
}
implicit def toDSLContainer[T: Extension](t: T) = implicitly[Extension[T]].lens.get(t)
}
case class DSLContainer(
......@@ -300,6 +312,11 @@ package composition {
hooks
)
def DSLContainerExtension[T](l: monocle.Lens[T, DSLContainer]): composition.DSLContainer.Extension[T] =
new composition.DSLContainer.Extension[T] {
def lens = l
}
type DSLContainer = composition.DSLContainer
def Slot(dsl: DSL) = composition.Slot(dsl)
def Capsule(node: TaskNode) = composition.Capsule(node)
......@@ -417,11 +434,16 @@ package composition {
object DSLSelector {
def apply[L <: HList](implicit selector: DSLSelector[L]): DSLSelector[L] = selector
implicit def select[T <: HList]: DSLSelector[DSL :: T] =
implicit def select1[T <: HList]: DSLSelector[DSL :: T] =
new DSLSelector[DSL :: T] {
def apply(l: DSL :: T) = l.head
}
implicit def select2[T <: HList, D: composition.DSLContainer.Extension]: DSLSelector[D :: T] =
new DSLSelector[D :: T] {
def apply(l: D :: T) = implicitly[composition.DSLContainer.Extension[D]].lens.get(l.head)
}
implicit def recurse[H, T <: HList](implicit st: DSLSelector[T]): DSLSelector[H :: T] =
new DSLSelector[H :: T] {
def apply(l: H :: T) = st(l.tail)
......@@ -486,7 +508,8 @@ package composition {
implicit def dslToDSL = ToDSL[DSL](identity)
implicit def taskToTransitionDSL = ToDSL[Task](t TaskNodeDSL(TaskNode(t)))
implicit def taskInNodeToTransitionDSL = ToDSL[TaskNode](t TaskNodeDSL(t))
implicit def transitionDSLSelectorToTransitionDSL[HL <: HList](implicit transitionDSLSelector: DSLSelector[HL]) = ToDSL[HL](t transitionDSLSelector(t))
implicit def dslExtensionToDSL[T](implicit ext: composition.DSLContainer.Extension[T]) = ToDSL(ext.lens.get)
implicit def transitionDSLSelectorToTransitionDSL[HL <: HList](implicit dslSelector: DSLSelector[HL]) = ToDSL[HL](t dslSelector(t))
}
trait ToDSL[-T] {
......@@ -527,6 +550,8 @@ package composition {
implicit def toMole[T: ToMole](t: T) = implicitly[ToMole[T]].apply(t)
implicit def toMoleExecution[T: ToMoleExecution](t: T) = implicitly[ToMoleExecution[T]].apply(t)
implicit def dslContainerExtension[T: composition.DSLContainer.Extension](t: T) = composition.DSLContainer.Extended(t)
implicit class DSLDecorator(t1: DSL) {
def &(t2: DSL) = new &(t1, t2)
......
......@@ -55,11 +55,11 @@ case class TaskExecutionContext(
object Task {
/**
* Construct a Random Number Generator for the task. The rng is constructed by [[org.openmole.tool.random.Random]] with the seed provided from the context (seed being defined as an OpenMOLE variable)
*
* @param context
* @return
*/
* Construct a Random Number Generator for the task. The rng is constructed by [[org.openmole.tool.random.Random]] with the seed provided from the context (seed being defined as an OpenMOLE variable)
*
* @param context
* @return
*/
def buildRNG(context: Context): scala.util.Random = random.Random(context(Variable.openMOLESeed)).toScala
def definitionScope(t: Task) = t.info.definitionScope
}
......@@ -89,15 +89,15 @@ trait Task <: Name with Id {
protected def process(executionContext: TaskExecutionContext): FromContext[Context]
/**
* Configuration for inputs/outputs
* @return
*/
* Configuration for inputs/outputs
* @return
*/
def config: InputOutputConfig
/**
* Information on the task (name, scope)
* @return
*/
* Information on the task (name, scope)
* @return
*/
def info: InfoConfig
def inputs = config.inputs
......
......@@ -42,9 +42,9 @@ object DefaultSet {
}
/**
* A set of default values for prototypes
* @param defaults
*/
* A set of default values for prototypes
* @param defaults
*/
case class DefaultSet(defaults: Iterable[Default[_]]) {
@transient lazy val defaultMap =
......
......@@ -26,25 +26,25 @@ import org.openmole.core.workspace.NewFile
import org.openmole.tool.random._
/**
* Methods for the validation of inputs/outputs
*/
* Methods for the validation of inputs/outputs
*/
object InputOutputCheck {
trait InputError
/**
* Missing input
* @param input
*/
* Missing input
* @param input
*/
case class InputNotFound(input: Val[_]) extends InputError {
override def toString = s"Input data '$input' has not been found"
}
/**
* Wrong type for an input
* @param input
* @param found
*/
* Wrong type for an input
* @param input
* @param found
*/
case class InputTypeMismatch(input: Val[_], found: Val[_]) extends InputError {
override def toString = s"Input data named '$found' is of an incompatible with the required '$input'"
}
......@@ -52,18 +52,18 @@ object InputOutputCheck {
trait OutputError
/**
* Missing output
* @param output
*/
* Missing output
* @param output
*/
case class OutputNotFound(output: Val[_]) extends OutputError {
override def toString = s"Output data '$output' has not been found"
}
/**
* Wrong type for an output
* @param output
* @param variable
*/
* Wrong type for an output
* @param output
* @param variable
*/
case class OutputTypeMismatch(output: Val[_], variable: Variable[_]) extends OutputError {
override def toString = s"""Type mismatch the content of the output value '${output.name}' of type '${variable.value.getClass}' is incompatible with the output variable '${output}'."""
}
......@@ -89,22 +89,22 @@ object InputOutputCheck {
}
/**
* Given a prototype set and a context, construct a [[Context]] with these prototypes only
*
* @param outputs
* @param context
* @return
*/
* Given a prototype set and a context, construct a [[Context]] with these prototypes only
*
* @param outputs
* @param context
* @return
*/
def filterOutput(outputs: PrototypeSet, context: Context): Context =
Context(outputs.toList.flatMap(o context.variable(o): Option[Variable[_]]): _*)
/**
* Extend a context with default values (taken into account if overriding is activated or variable is missing in previous context)
*
* @param defaults default value
* @param context context to be extended
* @return the new context
*/
* Extend a context with default values (taken into account if overriding is activated or variable is missing in previous context)
*
* @param defaults default value
* @param context context to be extended
* @return the new context
*/
def initializeInput(defaults: DefaultSet, context: Context)(implicit randomProvider: RandomProvider, newFile: NewFile, fileService: FileService): Context =
context ++
defaults.flatMap {
......
......@@ -17,14 +17,29 @@
package org.openmole.plugin.method
import monocle.macros.Lenses
import org.openmole.core.dsl._
import org.openmole.core.