Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration towards pureconfig #900

Draft
wants to merge 20 commits into
base: dev
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ dependencies {
implementation 'com.typesafe:config:1.4.3'
implementation "com.github.carueda:tscfg_2.13:$tscfgVersion"
implementation "com.github.scopt:scopt_${scalaVersion}:4.1.0" // cmd args parser
//TODO: Remove carueda version
implementation "com.github.pureconfig:pureconfig_2.13:0.17.4"

// JTS
implementation ("org.locationtech.jts:jts-core:${jtsVersion}"){
Expand Down
4 changes: 2 additions & 2 deletions input/samples/vn_simona/vn_simona.conf
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ simona.output.thermal = {
##################################################################
# Runtime Configuration // todo refactor as this naming is misleading and partly unneeded
##################################################################
simona.runtime.selected_subgrids = []
simona.runtime.selected_volt_lvls = []
simona.runtime.selectedSubgrids = []
simona.runtime.selectedVoltLvls = []

simona.runtime.participant.load = {
defaultConfig = {
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/edu/ie3/simona/agent/em/EmAgent.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import edu.ie3.datamodel.models.input.EmInput
import edu.ie3.datamodel.models.result.system.{EmResult, FlexOptionsResult}
import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ApparentPower
import edu.ie3.simona.agent.participant.statedata.BaseStateData.FlexControlledData
import edu.ie3.simona.config.SimonaConfig.EmRuntimeConfig
import edu.ie3.simona.config.RuntimeConfig.EmRuntimeConfig
import edu.ie3.simona.event.ResultEvent
import edu.ie3.simona.event.ResultEvent.{
FlexOptionsResultEvent,
Expand Down
14 changes: 8 additions & 6 deletions src/main/scala/edu/ie3/simona/agent/grid/DBFSAlgorithm.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import org.apache.pekko.util.{Timeout => PekkoTimeout}
import org.slf4j.Logger
import squants.Each

import java.time.{Duration, ZonedDateTime}
import java.time.{ZonedDateTime, Duration => JavaDuration}
import java.util.UUID
import scala.concurrent.{ExecutionContext, Future}
import scala.util.{Failure, Success}
Expand Down Expand Up @@ -1161,7 +1161,7 @@ trait DBFSAlgorithm extends PowerFlowSupport with GridResultsSupport {
sweepValueStore: Option[SweepValueStore],
nodeToAssetAgents: Map[UUID, Set[ActorRef[ParticipantMessage]]],
refSystem: RefSystem,
askTimeout: Duration,
askTimeout: JavaDuration,
)(implicit
ctx: ActorContext[GridAgent.Request]
): Boolean = {
Expand Down Expand Up @@ -1239,11 +1239,12 @@ trait DBFSAlgorithm extends PowerFlowSupport with GridResultsSupport {
currentSweepNo: Int,
subGridGateToActorRef: Map[SubGridGate, ActorRef[GridAgent.Request]],
inferiorGridGates: Seq[SubGridGate],
askTimeout: Duration,
askTimeout: JavaDuration,
)(implicit
ctx: ActorContext[GridAgent.Request]
): Boolean = {
implicit val timeout: PekkoTimeout = PekkoTimeout.create(askTimeout)
implicit val timeout: PekkoTimeout =
PekkoTimeout.create(JavaDuration.ofSeconds(askTimeout.toSeconds))
implicit val ec: ExecutionContext = ctx.executionContext
implicit val scheduler: Scheduler = ctx.system.scheduler

Expand Down Expand Up @@ -1310,11 +1311,12 @@ trait DBFSAlgorithm extends PowerFlowSupport with GridResultsSupport {
currentSweepNo: Int,
subGridGateToActorRef: Map[SubGridGate, ActorRef[GridAgent.Request]],
superiorGridGates: Vector[SubGridGate],
askTimeout: Duration,
askTimeout: JavaDuration,
)(implicit
ctx: ActorContext[GridAgent.Request]
): Boolean = {
implicit val timeout: PekkoTimeout = PekkoTimeout.create(askTimeout)
implicit val timeout: PekkoTimeout =
PekkoTimeout.create(JavaDuration.ofSeconds(askTimeout.toSeconds))
implicit val ec: ExecutionContext = ctx.executionContext
implicit val scheduler: Scheduler = ctx.system.scheduler

Expand Down
26 changes: 12 additions & 14 deletions src/main/scala/edu/ie3/simona/agent/grid/GridAgent.scala
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,10 @@ object GridAgent extends DBFSAlgorithm {
context.messageAdapter[Activation](msg => WrappedActivation(msg))

// val initialization
val resolution: Long = simonaConfig.simona.powerflow.resolution.get(
ChronoUnit.SECONDS
) // this determines the agents regular time bin it wants to be triggered e.g one hour
val resolution: Long = simonaConfig.powerflow.resolution.toSeconds

val simStartTime: ZonedDateTime = TimeUtil.withDefaults
.toZonedDateTime(simonaConfig.simona.time.startDateTime)
.toZonedDateTime(simonaConfig.time.startDateTime)

val agentValues = GridAgentConstantData(
environmentRefs,
Expand Down Expand Up @@ -128,10 +126,10 @@ object GridAgent extends DBFSAlgorithm {
subGridContainer,
refSystem,
TimeUtil.withDefaults.toZonedDateTime(
constantData.simonaConfig.simona.time.startDateTime
constantData.simonaConfig.time.startDateTime
),
TimeUtil.withDefaults.toZonedDateTime(
constantData.simonaConfig.simona.time.endDateTime
constantData.simonaConfig.time.endDateTime
),
simonaConfig,
)
Expand All @@ -142,9 +140,9 @@ object GridAgent extends DBFSAlgorithm {
constantData.environmentRefs,
constantData.simStartTime,
TimeUtil.withDefaults
.toZonedDateTime(constantData.simonaConfig.simona.time.endDateTime),
constantData.simonaConfig.simona.runtime.participant,
constantData.simonaConfig.simona.output.participant,
.toZonedDateTime(constantData.simonaConfig.time.endDateTime),
constantData.simonaConfig.runtime.participant,
constantData.simonaConfig.output.participant,
constantData.resolution,
constantData.listener,
ctx.log,
Expand Down Expand Up @@ -174,11 +172,11 @@ object GridAgent extends DBFSAlgorithm {
gridAgentInitData.superiorGridNodeUuids,
gridAgentInitData.inferiorGridGates,
PowerFlowParams(
constantData.simonaConfig.simona.powerflow.maxSweepPowerDeviation,
constantData.simonaConfig.simona.powerflow.newtonraphson.epsilon.toVector.sorted,
constantData.simonaConfig.simona.powerflow.newtonraphson.iterations,
constantData.simonaConfig.simona.powerflow.sweepTimeout,
constantData.simonaConfig.simona.powerflow.stopOnFailure,
constantData.simonaConfig.powerflow.maxSweepPowerDeviation,
constantData.simonaConfig.powerflow.newtonraphson.epsilon.toVector.sorted,
constantData.simonaConfig.powerflow.newtonraphson.iterations,
constantData.simonaConfig.powerflow.sweepTimeOut,
constantData.simonaConfig.powerflow.resolution,
),
SimonaActorNaming.actorName(ctx.self),
)
Expand Down
32 changes: 16 additions & 16 deletions src/main/scala/edu/ie3/simona/agent/grid/GridAgentController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import edu.ie3.simona.agent.participant.pv.PvAgent
import edu.ie3.simona.agent.participant.statedata.ParticipantStateData.ParticipantInitializeStateData
import edu.ie3.simona.agent.participant.storage.StorageAgent
import edu.ie3.simona.agent.participant.wec.WecAgent
import edu.ie3.simona.config.SimonaConfig
import edu.ie3.simona.config.SimonaConfig._
import edu.ie3.simona.config.OutputConfig.ParticipantOutputConfig
import edu.ie3.simona.config.RuntimeConfig._
import edu.ie3.simona.event.ResultEvent
import edu.ie3.simona.event.notifier.NotifierConfig
import edu.ie3.simona.exceptions.CriticalFailureException
Expand Down Expand Up @@ -75,8 +75,8 @@ class GridAgentController(
environmentRefs: EnvironmentRefs,
simulationStartDate: ZonedDateTime,
simulationEndDate: ZonedDateTime,
participantsConfig: SimonaConfig.Simona.Runtime.Participant,
outputConfig: SimonaConfig.Simona.Output.Participant,
participantsConfig: RuntimeParticipantsConfig,
outputConfig: ParticipantOutputConfig,
resolution: Long,
listener: Iterable[ActorRef[ResultEvent]],
log: Logger,
Expand Down Expand Up @@ -174,8 +174,8 @@ class GridAgentController(
* A map from coupling point to set of actor references
*/
private def buildParticipantToActorRef(
participantsConfig: SimonaConfig.Simona.Runtime.Participant,
outputConfig: SimonaConfig.Simona.Output.Participant,
participantsConfig: RuntimeParticipantsConfig,
outputConfig: ParticipantOutputConfig,
participants: Vector[SystemParticipantInput],
thermalIslandGridsByBusId: Map[UUID, ThermalGrid],
environmentRefs: EnvironmentRefs,
Expand Down Expand Up @@ -355,7 +355,7 @@ class GridAgentController(
case input: PvInput =>
buildPv(
input,
participantConfigUtil.getOrDefault[PvRuntimeConfig](
participantConfigUtil.getOrDefault[SimpleRuntimeConfig](
input.getUuid
),
environmentRefs.primaryServiceProxy,
Expand All @@ -370,7 +370,7 @@ class GridAgentController(
case input: WecInput =>
buildWec(
input,
participantConfigUtil.getOrDefault[WecRuntimeConfig](
participantConfigUtil.getOrDefault[SimpleRuntimeConfig](
input.getUuid
),
environmentRefs.primaryServiceProxy,
Expand All @@ -385,7 +385,7 @@ class GridAgentController(
case input: EvcsInput =>
buildEvcs(
input,
participantConfigUtil.getOrDefault[EvcsRuntimeConfig](
participantConfigUtil.getOrDefault[SimpleRuntimeConfig](
input.getUuid
),
environmentRefs.primaryServiceProxy,
Expand All @@ -407,7 +407,7 @@ class GridAgentController(
buildHp(
hpInput,
thermalGrid,
participantConfigUtil.getOrDefault[HpRuntimeConfig](
participantConfigUtil.getOrDefault[SimpleRuntimeConfig](
hpInput.getUuid
),
environmentRefs.primaryServiceProxy,
Expand All @@ -424,7 +424,7 @@ class GridAgentController(
case input: StorageInput =>
buildStorage(
input,
participantConfigUtil.getOrDefault[StorageRuntimeConfig](
participantConfigUtil.getOrDefault[SimpleRuntimeConfig](
input.getUuid
),
environmentRefs.primaryServiceProxy,
Expand Down Expand Up @@ -587,7 +587,7 @@ class GridAgentController(
*/
private def buildPv(
pvInput: PvInput,
modelConfiguration: PvRuntimeConfig,
modelConfiguration: SimpleRuntimeConfig,
primaryServiceProxy: ClassicRef,
weatherService: ClassicRef,
simulationStartDate: ZonedDateTime,
Expand Down Expand Up @@ -647,7 +647,7 @@ class GridAgentController(
*/
private def buildEvcs(
evcsInput: EvcsInput,
modelConfiguration: EvcsRuntimeConfig,
modelConfiguration: SimpleRuntimeConfig,
primaryServiceProxy: ClassicRef,
evMovementsService: ClassicRef,
simulationStartDate: ZonedDateTime,
Expand Down Expand Up @@ -707,7 +707,7 @@ class GridAgentController(
private def buildHp(
hpInput: HpInput,
thermalGrid: ThermalGrid,
modelConfiguration: HpRuntimeConfig,
modelConfiguration: SimpleRuntimeConfig,
primaryServiceProxy: ClassicRef,
weatherService: ClassicRef,
requestVoltageDeviationThreshold: Double,
Expand Down Expand Up @@ -765,7 +765,7 @@ class GridAgentController(
*/
private def buildWec(
wecInput: WecInput,
modelConfiguration: WecRuntimeConfig,
modelConfiguration: SimpleRuntimeConfig,
primaryServiceProxy: ClassicRef,
weatherService: ClassicRef,
simulationStartDate: ZonedDateTime,
Expand Down Expand Up @@ -823,7 +823,7 @@ class GridAgentController(
*/
private def buildStorage(
storageInput: StorageInput,
modelConfiguration: SimonaConfig.StorageRuntimeConfig,
modelConfiguration: SimpleRuntimeConfig,
primaryServiceProxy: ClassicRef,
simulationStartDate: ZonedDateTime,
simulationEndDate: ZonedDateTime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ import edu.ie3.simona.agent.state.ParticipantAgentState.{
Calculate,
HandleInformation,
}
import edu.ie3.simona.config.RuntimeConfig.{
BaseRuntimeConfig,
SimpleRuntimeConfig,
}
import edu.ie3.simona.agent.{SimonaAgent, ValueStore}
import edu.ie3.simona.config.SimonaConfig
import edu.ie3.simona.event.notifier.NotifierConfig
Expand All @@ -47,9 +51,9 @@ import edu.ie3.simona.model.participant.{
}
import edu.ie3.simona.ontology.messages.Activation
import edu.ie3.simona.ontology.messages.flex.FlexibilityMessage.{
FlexActivation,
FlexResponse,
IssueFlexControl,
FlexActivation,
}
import edu.ie3.simona.ontology.messages.services.ServiceMessage.RegistrationResponseMessage.RegistrationSuccessfulMessage
import edu.ie3.simona.ontology.messages.services.ServiceMessage.{
Expand Down Expand Up @@ -94,7 +98,7 @@ abstract class ParticipantAgent[
MS <: ModelState,
D <: ParticipantStateData[PD],
I <: SystemParticipantInput,
MC <: SimonaConfig.BaseRuntimeConfig,
MC <: BaseRuntimeConfig,
M <: SystemParticipant[CD, PD, MS],
](
scheduler: ActorRef,
Expand Down Expand Up @@ -262,7 +266,7 @@ abstract class ParticipantAgent[
RegistrationSuccessfulMessage(serviceRef, maybeNextDataTick),
ParticipantInitializingStateData(
inputModel: InputModelContainer[I],
modelConfig: MC,
modelConfig: SimpleRuntimeConfig,
_,
simulationStartDate,
simulationEndDate,
Expand Down Expand Up @@ -290,7 +294,7 @@ abstract class ParticipantAgent[
RegistrationResponseMessage.RegistrationFailedMessage(_),
ParticipantInitializingStateData(
inputModel: InputModelContainer[I],
modelConfig: MC,
modelConfig: SimpleRuntimeConfig,
secondaryDataServices,
simulationStartDate,
simulationEndDate,
Expand Down Expand Up @@ -509,7 +513,7 @@ abstract class ParticipantAgent[
*/
def initializeParticipantForPrimaryDataReplay(
inputModel: InputModelContainer[I],
modelConfig: MC,
modelConfig: SimpleRuntimeConfig,
simulationStartDate: ZonedDateTime,
simulationEndDate: ZonedDateTime,
resolution: Long,
Expand Down Expand Up @@ -546,7 +550,7 @@ abstract class ParticipantAgent[
*/
def initializeParticipantForModelCalculation(
inputModel: InputModelContainer[I],
modelConfig: MC,
modelConfig: SimpleRuntimeConfig,
services: Iterable[SecondaryDataService[_ <: SecondaryData]],
simulationStartDate: ZonedDateTime,
simulationEndDate: ZonedDateTime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ import edu.ie3.simona.agent.state.ParticipantAgentState.{
Calculate,
HandleInformation,
}
import edu.ie3.simona.config.SimonaConfig
import edu.ie3.simona.config.RuntimeConfig.{
BaseRuntimeConfig,
SimpleRuntimeConfig,
}
import edu.ie3.simona.event.ResultEvent
import edu.ie3.simona.event.ResultEvent.{
FlexOptionsResultEvent,
Expand Down Expand Up @@ -108,7 +111,7 @@ protected trait ParticipantAgentFundamentals[
MS <: ModelState,
D <: ParticipantStateData[PD],
I <: SystemParticipantInput,
MC <: SimonaConfig.BaseRuntimeConfig,
MC <: BaseRuntimeConfig,
M <: SystemParticipant[CD, PD, MS],
] extends ServiceRegistration[PD, CD, MS, D, I, MC, M] {
this: ParticipantAgent[PD, CD, MS, D, I, MC, M] =>
Expand All @@ -117,7 +120,7 @@ protected trait ParticipantAgentFundamentals[

override def initializeParticipantForPrimaryDataReplay(
inputModel: InputModelContainer[I],
modelConfig: MC,
modelConfig: SimpleRuntimeConfig,
simulationStartDate: ZonedDateTime,
simulationEndDate: ZonedDateTime,
resolution: Long,
Expand Down Expand Up @@ -170,7 +173,7 @@ protected trait ParticipantAgentFundamentals[
*/
private def determineFromOutsideBaseStateData(
inputModel: InputModelContainer[I],
modelConfig: MC,
modelConfig: SimpleRuntimeConfig,
simulationStartDate: ZonedDateTime,
simulationEndDate: ZonedDateTime,
resolution: Long,
Expand Down Expand Up @@ -222,7 +225,7 @@ protected trait ParticipantAgentFundamentals[
*/
def buildModel(
inputModel: InputModelContainer[I],
modelConfig: MC,
modelConfig: SimpleRuntimeConfig,
simulationStartDate: ZonedDateTime,
simulationEndDate: ZonedDateTime,
): M
Expand Down Expand Up @@ -257,7 +260,7 @@ protected trait ParticipantAgentFundamentals[
*/
override def initializeParticipantForModelCalculation(
inputModel: InputModelContainer[I],
modelConfig: MC,
modelConfig: SimpleRuntimeConfig,
services: Iterable[SecondaryDataService[_ <: SecondaryData]],
simulationStartDate: ZonedDateTime,
simulationEndDate: ZonedDateTime,
Expand Down Expand Up @@ -337,7 +340,7 @@ protected trait ParticipantAgentFundamentals[
*/
def determineModelBaseStateData(
inputModel: InputModelContainer[I],
modelConfig: MC,
modelConfig: SimpleRuntimeConfig,
services: Iterable[SecondaryDataService[_ <: SecondaryData]],
simulationStartDate: ZonedDateTime,
simulationEndDate: ZonedDateTime,
Expand Down
Loading