Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Simplify conversion of flex options and setpoints between SIMONA and its API [#1785](https://github.com/ie3-institute/simona/issues/1785)
- `CommonLossObjectiveFactory.PriceObjectiveFactory`: Applying soft constraint only when necessary [#1848](https://github.com/ie3-institute/simona/issues/1848)
- Replaced implicit classes with scala 3 extension methods [#1833](https://github.com/ie3-institute/simona/issues/1833)
- Refactored simulation setup [#1858](https://github.com/ie3-institute/simona/issues/1858)

### Fixed
- Fixes in Documentation, ScalaDocs, Code Style and more [#1397](https://github.com/ie3-institute/simona/issues/1397)
Expand Down
9 changes: 9 additions & 0 deletions docs/readthedocs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ To create the output directory name, the name of the simulation is used as a str

`simona.simulationName = "vn_simona"`

The simulation timeout defines the time after a simulation is automatically stopped. For long running simulations this parameter
needs to be adapted.

`simona.simulationTimeout = 12h`

## Time parameters
Starting date and time of the simulation in ISO-8601 date and time format with offset

Expand Down Expand Up @@ -435,6 +440,10 @@ Maximum Voltage Limit in p.u.:

## Default configuration values

```
simulationTimeout: FiniteDuration = 12h
```

### Time
```
simona.time.schedulerReadyCheckWindow = None
Expand Down
164 changes: 82 additions & 82 deletions gradlew.bat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/main/scala/edu/ie3/simona/config/SimonaConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ final case class SimonaConfig(
runtime: RuntimeConfig = RuntimeConfig(),
simulationName: String,
time: Time,
simulationTimeout: FiniteDuration = 12.hours,
) derives ConfigConvert {

/** Returns the values of this config.
Expand Down
6 changes: 0 additions & 6 deletions src/main/scala/edu/ie3/simona/main/RunSimona.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ package edu.ie3.simona.main
import com.typesafe.scalalogging.LazyLogging
import edu.ie3.simona.sim.setup.SimonaSetup
import edu.ie3.util.scala.quantities.QuantityUtil
import org.apache.pekko.util.Timeout

import java.nio.file.Path
import java.util.Locale
import scala.concurrent.duration.FiniteDuration
import scala.util.Random

/** Trait to be mixed in all implementations that should be used to run a simona
Expand All @@ -24,10 +22,6 @@ import scala.util.Random
*/
trait RunSimona[T <: SimonaSetup] extends LazyLogging {

// timeout parameter
implicit val timeout: Timeout
implicit lazy val timeoutDuration: FiniteDuration = timeout.duration

def main(args: Array[String]): Unit = {
Locale.setDefault(Locale.ENGLISH)

Expand Down
45 changes: 26 additions & 19 deletions src/main/scala/edu/ie3/simona/main/RunSimonaStandalone.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,57 +9,64 @@ package edu.ie3.simona.main
import edu.ie3.simona.config.{ArgsParser, ConfigFailFast, SimonaConfig}
import edu.ie3.simona.main.RunSimona.*
import edu.ie3.simona.sim.SimonaSim
import edu.ie3.simona.sim.setup.SimonaStandaloneSetup
import edu.ie3.simona.util.ResultFileHierarchy
import edu.ie3.simona.sim.setup.SimonaSetup
import org.apache.pekko.actor.typed.scaladsl.AskPattern.*
import org.apache.pekko.actor.typed.{ActorSystem, Scheduler}
import org.apache.pekko.util.Timeout

import scala.concurrent.Await
import scala.concurrent.duration.DurationInt
import scala.concurrent.{Await, TimeoutException}

/** Run a standalone simulation of simona
*
* @since 01.07.20
*/
object RunSimonaStandalone extends RunSimona[SimonaStandaloneSetup] {
object RunSimonaStandalone extends RunSimona[SimonaSetup] {

override implicit val timeout: Timeout = Timeout(12.hours)

override def setup(args: Array[String]): SimonaStandaloneSetup = {
override def setup(args: Array[String]): SimonaSetup = {
// get the config and prepare it with the provided args
val (arguments, parsedConfig) = ArgsParser.prepareConfig(args)

// config fail fast check
val simonaConfig = SimonaConfig(parsedConfig)
ConfigFailFast.check(parsedConfig, simonaConfig)

SimonaStandaloneSetup(
SimonaSetup(
parsedConfig,
simonaConfig,
ResultFileHierarchy(parsedConfig, simonaConfig),
mainArgs = arguments.mainArgs,
arguments.mainArgs,
)
}

override def run(simonaSetup: SimonaStandaloneSetup): Boolean = {
override def run(simonaSetup: SimonaSetup): Boolean = {
val simonaSim = ActorSystem(
SimonaSim(simonaSetup),
name = "Simona",
config = simonaSetup.typeSafeConfig,
)

implicit val scheduler: Scheduler = simonaSim.scheduler
given scheduler: Scheduler = simonaSim.scheduler
given timeout: Timeout = simonaSetup.simonaConfig.simulationTimeout

// run the simulation
val terminated = simonaSim.ask[SimonaEnded](ref => SimonaSim.Start(ref))
try {
// run the simulation
val terminated = simonaSim.ask[SimonaEnded](ref => SimonaSim.Start(ref))

Await.result(terminated, timeout.duration) match {
case SimonaEnded(successful) =>
simonaSim.terminate()
Await.result(terminated, timeout.duration) match {
case SimonaEnded(successful) =>
simonaSim.terminate()

successful
successful
}
} catch {
case te: TimeoutException =>
simonaSim.terminate()
logger.error(
s"Simulation timeout reached! Stopping the simulation.",
te,
)
false
}

}

}
11 changes: 9 additions & 2 deletions src/main/scala/edu/ie3/simona/sim/SimonaSim.scala
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,24 @@ object SimonaSim {
extSimulationData.evDataService,
)

/* start participant agents */
val participantAgents =
simonaSetup.participantAgents(using ctx, environmentRefs)

/* start grid agents */
val gridAgentCoordinator =
simonaSetup.gridAgentCoordinator(using ctx, environmentRefs)
simonaSetup.gridAgentCoordinator(participantAgents)(using
ctx,
environmentRefs,
)

val otherActors = Iterable[ActorRef[?]](
timeAdvancer,
scheduler,
primaryServiceProxy,
weatherService,
gridAgentCoordinator,
) ++ extSimulationData.allServiceRefs ++ priceService.toSeq
) ++ extSimulationData.allServiceRefs ++ priceService.toSeq ++ participantAgents.values.flatten

/* watch all actors */
allResultEventListeners.foreach(ctx.watch)
Expand Down
Loading