val cormasModelFile = Val[File] val cormasResults = Val[File] def CormasTask( image: String, modelFile: File, initSelector: String, stepSelector: String, maxSteps: Int, stopCondition: String, seed: Val[Int], parameters: Seq[(Val[_], String)], probes: Seq[(Val[Double], String)] ) = { val parameterArguments = parameters .map { case (v, name) => s"parameter:$name=$${${v.name}}" } .mkString(" ") val probeArguments = probes .map { case (_, name) => s"probe:$name" } .mkString(" ") val command = s"/app/run.sh /work/model.cmx " + s"initSelector=$initSelector " + s"stepSelector=$stepSelector " + s"maxSteps=$maxSteps " + s"stopCondition=$stopCondition " + s"seed=$${${seed.name}} " + parameterArguments + " " + probeArguments val run = ContainerTask( image, command ) set ( inputs += seed, inputs ++= parameters.map(_._1), inputFiles += (cormasModelFile, "model.cmx"), outputFiles += ("/app/results.json", cormasResults), cormasModelFile := modelFile ) val probeDeclarations = probes.map { case (v, _) => s"var ${v.name} = 0.0" }.mkString("\n") val probeAssignments = probes.map { case (v, jsonName) => s"""${v.name} = number("$jsonName")""" }.mkString("\n") val parse = ScalaTask(s""" $probeDeclarations val text = scala.io.Source.fromFile(cormasResults).mkString def number(name: String): Double = { val afterName = text.split(name)(1) val afterColon = afterName.split(":")(1).trim val rawNumber = afterColon.takeWhile(c => c.isDigit || c == '.' || c == '-' || c == '+' || c == 'E' || c == 'e' ) rawNumber.toDouble } $probeAssignments """) set ( inputs += cormasResults, outputs ++= probes.map(_._1) ) run -- parse }