Skip to content

Commit 0924d2c

Browse files
committed
Adapted everything for thesis hand-in. Readme is updated, thesis documents are online.
1 parent 7a77049 commit 0924d2c

23 files changed

Lines changed: 210 additions & 87 deletions

MOISCore/src/main/scala/ed/mois/core/storm/StormSim.scala

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ abstract class StormSim {
4343
/**
4444
* Tells the simulator if gnu plot should be called in the end to plot observables.
4545
*/
46-
val printGnu = false
46+
val printGnu = true
4747

4848
/**
4949
* Overwrite to define the model to be simulated.
@@ -77,12 +77,9 @@ abstract class StormSim {
7777
println(s"""Simulation '${model.title}' took ${time.toDouble / 1000} seconds and resulted in ${endSim.size} data vectors of size ${endSim.head._2.fields.size}.""")
7878

7979
// Logging
80-
// if (!endSim.isEmpty)
81-
// loggingStrategy.writeDataHeader(endSim.head._2.fields.map(f => model.stateVector.fieldNames(f._1)).toArray)
82-
// endSim.foreach{ es =>
83-
// loggingStrategy.writeStormDataPoints(es)
84-
// //loggingStrategy.writeDataPoints(es._1, es._2.fields.map(_._2).toArray)
85-
// }
80+
if (!endSim.isEmpty) {
81+
loggingStrategy.writeStormData(model, endSim)
82+
}
8683

8784
println("Finished logging to disk, starting Gnuplot.")
8885

MOISCore/src/main/scala/ed/mois/core/storm/strategies/DistrSimPosStepAdaptionStrategy.scala

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,6 @@ class DistrSimPosStepAdaptionStrategy(val model: StormModel, maxTime: Double, dt
4040
val tPrev = Array.fill(processes.size)(0.0)
4141
val tNext = Array.fill(processes.size)(dt)
4242
val pDt = Array.fill(processes.size)(dt)
43-
/*pDt(1) = 0.1
44-
pDt(2) = 0.2
45-
pDt(3) = 0.3
46-
pDt(4) = 0.4
47-
tNext(1) = 0.1
48-
tNext(2) = 0.2
49-
tNext(3) = 0.3
50-
tNext(4) = 0.4*/
5143

5244
// Set of running processes, and where in time they are
5345
var running = collection.mutable.Set.empty[Tuple3[Int, Double, Double]]
@@ -164,16 +156,6 @@ class DistrSimPosStepAdaptionStrategy(val model: StormModel, maxTime: Double, dt
164156
}
165157
}
166158

167-
// Calculate next time step (if process isn't already running)
168-
/*if (tCurr(i) < maxTime && !isRunning(i)) {
169-
running += Tuple3(i, tCurr(i), pDt(i))
170-
processes(i) ! Evolve(m(tCurr(i)).dupl, tCurr(i), pDt(i))
171-
} else if (running.size == 0) {
172-
// If nothing is running, just stop everything
173-
orig.foreach(_ ! TreeMap(m.toMap.toArray:_*))
174-
context.stop(self)
175-
}*/
176-
177159
t = tCurr.min
178160
if (t > maxTime) {
179161
running = collection.mutable.Set.empty[Tuple3[Int, Double, Double]]
@@ -201,7 +183,6 @@ class DistrSimPosStepAdaptionStrategy(val model: StormModel, maxTime: Double, dt
201183
mm.filter{case (t, s) => t >= startTime}.foreach{case (t, s) => model.calcDependencies(s)}
202184
//println(TreeMap(mm.toMap.toArray:_*))
203185
//println
204-
//println
205186
mm
206187
}
207188

@@ -214,7 +195,7 @@ class DistrSimPosStepAdaptionStrategy(val model: StormModel, maxTime: Double, dt
214195

215196
def simulate(mod: StormModel): TreeMap[Double, StormState[_]] = {
216197
processes.foreach{ p =>
217-
println(s"${p._1} calculated with 0.0 -> ${pDt(p._1)}")
198+
//println(s"${p._1} calculated with 0.0 -> ${pDt(p._1)}")
218199
running += (Tuple3(p._1, 0.0, pDt(p._1)))
219200
p._2 ! Evolve(model.stateVector.dupl, 0.0, pDt(p._1))
220201
}

MOISCore/src/main/scala/ed/mois/core/storm/strategies/IndepTimeScaleStrategy.scala

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,15 @@ class IndepTimeScaleStrategy(maxTime: Double, dt: Double) extends SimulationStra
3131

3232
// Step through whole simulation
3333
var t = 0.0
34-
var stopper = 0
3534
// Add to result vector
3635
m += (t -> model.stateVector.dupl)
3736
if (debug) println(printStates(t, model.stateVector, 6))
3837

3938
while (t < maxTime) {
40-
stopper += 1
41-
// if (stopper > 982){
4239
// println("tNext: " + tNext.mkString("[ ", ", ", " ]"))
4340
// println("tCurr: " + tCurr.mkString("[ ", ", ", " ]"))
4441
// println("tPrev: " + tPrev.mkString("[ ", ", ", " ]"))
45-
// println("pDt: " + pDt.mkString("[ ", ", ", " ]"))}
42+
// println("pDt: " + pDt.mkString("[ ", ", ", " ]"))
4643
// Calculate internal model dependencies
4744
model.calcDependencies(model.stateVector)
4845

@@ -61,7 +58,7 @@ class IndepTimeScaleStrategy(maxTime: Double, dt: Double) extends SimulationStra
6158
tNext(i) = tCurr(i) + pDt(i)
6259
// Adjust all other processes' time step. Get ids first
6360
val violProcIds = violators.get._3.map(_.origin).distinct.filter(_ != i)
64-
println("Violating! Mainly " + violProcIds.mkString("(", ", ", ")") + " plus i=" + i)
61+
// println("Violating! Mainly " + violProcIds.mkString("(", ", ", ")") + " plus i=" + i)
6562
// And adjust all dt's, tCurr's, ...
6663
violProcIds.foreach { pid =>
6764
pDt(pid) = tCurr(i) - tPrev(pid) + pDt(i)
@@ -89,8 +86,6 @@ class IndepTimeScaleStrategy(maxTime: Double, dt: Double) extends SimulationStra
8986
}
9087
//println(s"keys at $t are: " + m.keys.toList.sorted.mkString(", "))
9188
//m.foreach(x => println(printStates(x._1, x._2, 6)))
92-
//println(stopper + ": " + t + ": " + i)
93-
if (stopper > 10000) t = maxTime
9489
//println
9590
}
9691

MOISCore/src/main/scala/ed/mois/core/util/DataToFileWriter.scala

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ package ed.mois.core.util
99

1010
import scalax.io._
1111
import ed.mois.core.storm._
12+
import scala.collection.immutable.TreeMap
1213

1314
class DataToFileWriter {
14-
val clearOutput = Resource.fromOutputStream(new java.io.FileOutputStream("data.dat"))
15+
val fileName = "data.dat"
16+
17+
val clearOutput = Resource.fromOutputStream(new java.io.FileOutputStream(fileName))
1518
clearOutput.write("")
16-
val output = Resource.fromFile("data.dat")
19+
val output: Output = Resource.fromFile("data.dat")
1720

1821
def writeDataHeader(dh: Array[String]) {
1922
output.write("t " + dh.mkString(" ") + "\n")
@@ -24,4 +27,18 @@ class DataToFileWriter {
2427
def writeStormDataPoints(p: Tuple2[Double, StormState[_]]) {
2528
output.write(p._1 + " " + p._2.fields.map(_._2).mkString(" ") + "\n")
2629
}
30+
31+
def writeStormData(model: StormModel, d: TreeMap[Double, StormState[_]]) {
32+
for {
33+
outProcessor <- Resource.fromOutputStream(new java.io.FileOutputStream(fileName)).outputProcessor
34+
out = outProcessor.asOutput
35+
} {
36+
// Write data header
37+
out.write("t " + d.head._2.fields.map(f => model.stateVector.fieldNames(f._1)).toArray.mkString(" ") + "\n")
38+
// Write data
39+
d.foreach{ p =>
40+
out.write(p._1 + " " + p._2.fields.map(_._2).mkString(" ") + "\n")
41+
}
42+
}
43+
}
2744
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Authors:
3+
* - Dominik Bucher, ETH Zurich, Github: dominikbucher
4+
*/
5+
package ed.mois.test
6+
7+
import akka.actor._
8+
import akka.pattern.ask
9+
import akka.util.Timeout
10+
11+
import scala.collection.immutable.TreeMap
12+
import scala.concurrent._
13+
import scala.concurrent.duration._
14+
import ExecutionContext.Implicits.global
15+
16+
/**
17+
* Tests some aggregation stuff (speed, needed for some arguments in the thesis).
18+
*/
19+
object AggregationTests extends App {
20+
var a = Array.ofDim[Double](28, 2500)
21+
val startTime = System.currentTimeMillis
22+
23+
(0 to 10000).foreach { i =>
24+
var n = 0
25+
var p = 0
26+
while(n < 2500) {
27+
// (0 to 2499).foreach { n =>
28+
var res = 0.0
29+
// (0 to 27).foreach { p =>
30+
while (p < 28) {
31+
res += a(p)(n)
32+
p += 1
33+
}
34+
p = 0
35+
n += 1
36+
res
37+
}
38+
}
39+
40+
//println(System.currentTimeMillis - startTime)
41+
println((System.currentTimeMillis - startTime).toDouble / 10000.0)
42+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Authors:
3+
* - Dominik Bucher, ETH Zurich, Github: dominikbucher
4+
*/
5+
package ed.mois.test
6+
7+
import akka.actor._
8+
import akka.pattern.ask
9+
import akka.util.Timeout
10+
11+
import scala.collection.immutable.TreeMap
12+
import scala.concurrent._
13+
import scala.concurrent.duration._
14+
import ExecutionContext.Implicits.global
15+
16+
/**
17+
* Tests some aggregation stuff (communication speed, needed for some arguments in the thesis).
18+
*/
19+
object AkkaTests extends App {
20+
case class Msg {
21+
var a = Array.ofDim[Any](2500)
22+
}
23+
24+
class Measurer(responder: ActorRef) extends Actor {
25+
val startTime = System.currentTimeMillis
26+
var counter = 1
27+
def receive = {
28+
case "start" => {
29+
(1 to 10000).foreach(i => responder ! Msg())
30+
}
31+
case a => {
32+
counter += 1
33+
if (counter == 10000) {
34+
println(System.currentTimeMillis - startTime)
35+
system.shutdown
36+
}
37+
}
38+
}
39+
}
40+
41+
class Responder extends Actor {
42+
def receive = {
43+
case a => sender ! a
44+
}
45+
}
46+
47+
48+
val system = ActorSystem("system")
49+
val responder = system.actorOf(Props(new Responder()))
50+
val measurer = system.actorOf(Props(new Measurer(responder)))
51+
52+
measurer ! "start"
53+
}

MOISKnowledgeBase/src/main/scala/ed/mois/kb/Constants.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
package ed.mois.kb
77

88
object Constants {
9-
val USERNAME = "dominik"
10-
val PASSWORD = "larix14"
9+
val USERNAME = "<replace with own>"
10+
val PASSWORD = "<replace with own>"
1111
}

MOISKnowledgeBase/src/main/scala/ed/mois/kb/KnowledgeBase.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import org.squeryl.PrimitiveTypeMode._
1111
import org.squeryl._
1212
import org.squeryl.KeyedEntity
1313

14+
/**
15+
* Scala adapter for the Karr Whole Cell Knowledgebase (SQL version).
16+
*/
1417
object KnowledgeBase extends Schema {
1518

1619
val userprofile = table[Public_UserProfile]

MOISKnowledgeBase/src/main/scala/ed/mois/kb/LoadKnowledgeBase.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import org.squeryl._
1010
import org.squeryl.adapters.MySQLAdapter
1111
import org.squeryl.PrimitiveTypeMode._
1212

13+
/**
14+
* Scala adapter for the Karr Whole Cell Knowledgebase (SQL version).
15+
*/
1316
object LoadKnowledgeBase {
1417
import KnowledgeBase._
1518

MOISMacros/src/main/scala/ed/mois/macr/ChangeModelMacros.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ import scala.reflect.internal.Names
113113
}*/
114114

115115
object ChangeModelMacros extends ReflectionUtils {
116+
/**
117+
* Automatically converts a field to a trackable field by adding the corresponding trait.
118+
* Method not used as of 2013-08.
119+
*/
116120
def trackable[T](value: Any) = macro trackable_impl[T]
117121

118122
def trackable_impl[T: c.WeakTypeTag](c: Context)(value: c.Expr[Any]): c.Expr[T] = {
@@ -132,6 +136,10 @@ object ChangeModelMacros extends ReflectionUtils {
132136
e
133137
}
134138

139+
/**
140+
* Sets up necessary messages by analyzing code.
141+
* Method not used as of 2013-08.
142+
*/
135143
def setUpMessages: PropRefs = macro setUpMessages_impl
136144

137145
def setUpMessages_impl(c: Context) = {
@@ -189,6 +197,10 @@ object ChangeModelMacros extends ReflectionUtils {
189197

190198
//def instantiateSkeleton[T <: t: ClassManifest](stateName: String): T = macro instantiateSkeleton_impl[T]
191199

200+
/**
201+
* Instantiates a state skeleton by changing fields to trackables and more.
202+
* Method not used as of 2013-08.
203+
*/
192204
def instantiateSkeleton_impl[T: c.WeakTypeTag](c: Context)(stateName: c.Expr[String]): c.Expr[T] = {
193205
import c.universe._
194206

0 commit comments

Comments
 (0)