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

Fix config auto-generation #131

Merged
merged 11 commits into from
Apr 12, 2022
37 changes: 4 additions & 33 deletions gradle/scripts/tscfg.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ task genConfigClass {
doLast {
def tscfgJarFile = project.file('build/tscfg-' + tscfgVersion + '.jar')
if (!tscfgJarFile.exists() || !tscfgJarFile.isFile()) {
download {
download.run {
ckittl marked this conversation as resolved.
Show resolved Hide resolved
src 'https://github.com/carueda/tscfg/releases/download/v' + tscfgVersion + '/tscfg-' + tscfgVersion + '.jar'
dest buildDir
}
Expand All @@ -15,7 +15,7 @@ task genConfigClass {
args = [
"build/tscfg-${tscfgVersion}.jar",
"--spec",
"src/main/resources/config/simona-config-template.conf",
"src/main/resources/config/config-template.conf",
sebastian-peter marked this conversation as resolved.
Show resolved Hide resolved
"--scala",
"--durations",
"--pn",
Expand All @@ -29,35 +29,6 @@ task genConfigClass {
}
}

task genExperimentsConfigClass {
doLast {
def tscfgJarFile = project.file('build/tscfg-' + tscfgVersion + '.jar')
if (!tscfgJarFile.exists() || !tscfgJarFile.isFile()) {
download {
src 'https://github.com/carueda/tscfg/releases/download/v' + tscfgVersion + '/tscfg-' + tscfgVersion + '.jar'
dest buildDir
}
}
javaexec {
main = "-jar"
args = [
"build/tscfg-${tscfgVersion}.jar",
"--spec",
"src/main/resources/config/experiments-config-template.conf",
"--scala",
"--durations",
"--pn",
"edu.ie3.simona.config",
"--cn",
"ExperimentsConfig",
"--dd",
"src/main/scala/edu/ie3/simona/config/"
]
}
}
}


Comment on lines -32 to -60
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? Does not relate to #130 nor #148

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just recognized in the discussion with sebastian that this is code, that was meant to be introduced with #66, but due to some error already is in code base right now.

////////////////////////////////////////////////////////////////////////////
// Generate sample config file reflecting the application.conf template file
// This can be used to setup a new simulation configuration
Expand All @@ -66,7 +37,7 @@ task genConfigSample {
doLast {
def tscfgJarFile = project.file('build/tscfg-' + tscfgVersion + '.jar')
if (!tscfgJarFile.exists() || !tscfgJarFile.isFile()) {
download {
download.run {
src 'https://github.com/carueda/tscfg/releases/download/v' + tscfgVersion + '/tscfg-' + tscfgVersion + '.jar'
dest buildDir
}
Expand All @@ -78,7 +49,7 @@ task genConfigSample {
"--spec",
"src/main/resources/config/config-template.conf",
"--tpl",
"configs/simona/simonaSample.conf"
"input/samples/configSample.conf"
]
}
}
Expand Down
4 changes: 2 additions & 2 deletions input/samples/vn_146_lv_small/vn_146_lv_small.conf
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ simona.event.listener = []


simona.gridConfig.refSystems = [
{sNom="100 kVA", vNom="0.4 kV", voltLvls = ["{NS, 0.4 kV}"]},
{sNom="500 MVA", vNom="20 kV", voltLvls = ["{MS, 20 kV}"]}
{sNom="100 kVA", vNom="0.4 kV", voltLvls = [{id = "NS", vNom = "0.4 kV"}]},
{sNom="500 MVA", vNom="20 kV", voltLvls = [{id = "MS", vNom = "20 kV"}]}
]

##################################################################
Expand Down
8 changes: 4 additions & 4 deletions input/samples/vn_simona/vn_simona.conf
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ simona.event.listener = []
##################################################################

simona.gridConfig.refSystems = [
{sNom = "100 kVA", vNom = "0.4 kV", voltLvls = ["{NS, 0.4 kV}"]},
{sNom = "60 MVA", vNom = "20 kV", voltLvls = ["{MS, 20 kV}"]},
{sNom = "600 MVA", vNom = "110 kV", voltLvls = ["{HS, 110 kV}"]},
{sNom = "1000 MVA", vNom = "380 kV", voltLvls = ["{HoeS, 380 kV}"]}
{sNom = "100 kVA", vNom = "0.4 kV", voltLvls = [{id = "NS", vNom = "0.4 kV"}]},
{sNom = "60 MVA", vNom = "20 kV", voltLvls = [{id = "MS", vNom = "20 kV"}]},
{sNom = "600 MVA", vNom = "110 kV", voltLvls = [{id = "HS", vNom = "110 kV"}]},
{sNom = "1000 MVA", vNom = "380 kV", voltLvls = [{id = "HoeS", vNom = "380 kV"}]}
]

##################################################################
Expand Down
5 changes: 0 additions & 5 deletions src/main/scala/edu/ie3/simona/config/ConfigConventions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ import scala.util.matching.Regex
* are used in several places)
*/
object ConfigConventions {
/*
* Regex matches e.g. {MV, 10 kV} and captures "MV" and "10 kV"
*/
val voltLvlRegex: Regex = """\{([\wäöüÄÖÜß-]+),[ ]+(.+)}""".r.unanchored

// regex matches
// / 1,2,3,12,5-10,6-10,10-5,10...100,100...1000,10-5
// val gridIdsRegex: Regex = """(\d+-\d+|\d+\.\.\.\d+|^\d{1}$)""".r.unanchored
Expand Down
18 changes: 14 additions & 4 deletions src/main/scala/edu/ie3/simona/config/ConfigFailFast.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ import edu.ie3.simona.util.ConfigUtil.DatabaseConfigUtil.checkInfluxDb1xParams
import edu.ie3.simona.util.ConfigUtil.{CsvConfigUtil, NotifierIdentifier}
import edu.ie3.util.scala.ReflectionTools
import edu.ie3.util.{StringUtils, TimeUtil}
import tech.units.indriya.quantity.Quantities
import tech.units.indriya.unit.Units

import java.security.InvalidParameterException
import java.time.temporal.ChronoUnit
import java.util.UUID
import javax.measure.quantity.ElectricPotential
import scala.util.{Failure, Success, Try}

/** Sanity checks for [[SimonaConfig]] that should lead to a fast failure during
Expand Down Expand Up @@ -385,7 +388,8 @@ case object ConfigFailFast extends LazyLogging {
*/
private def checkRefSystem(refSystem: RefSystemConfig): Unit = {

val voltLvls = refSystem.voltLvls.getOrElse(List.empty[String])
val voltLvls =
refSystem.voltLvls.getOrElse(List.empty[SimonaConfig.VoltLvlConfig])
val gridIds = refSystem.gridIds.getOrElse(List.empty[String])

if (voltLvls.isEmpty && gridIds.isEmpty)
Expand All @@ -396,10 +400,16 @@ case object ConfigFailFast extends LazyLogging {
)

voltLvls.foreach { voltLvl =>
{
if (!ConfigConventions.voltLvlRegex.matches(voltLvl))
Try(Quantities.getQuantity(voltLvl.vNom)) match {
case Success(quantity) =>
if (!quantity.getUnit.isCompatible(Units.VOLT))
throw new InvalidConfigParameterException(
s"The given nominal voltage '${voltLvl.vNom}' cannot be parsed to electrical potential!"
ckittl marked this conversation as resolved.
Show resolved Hide resolved
)
case Failure(exception) =>
throw new InvalidConfigParameterException(
s"The definition string for voltLvl '$voltLvl' does not comply with the definition {<id>, <rated voltage>}!"
s"The given nominal voltage '${voltLvl.vNom}' cannot be parsed to Quantity.",
exception
ckittl marked this conversation as resolved.
Show resolved Hide resolved
)
}
}
Expand Down
10 changes: 1 addition & 9 deletions src/main/scala/edu/ie3/simona/config/RefSystemParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,7 @@ object RefSystemParser {
case Some(voltLvls) =>
voltLvls.foldLeft(Vector.empty[(VoltageLevel, RefSystem)])(
(voltLvlRefSystems, voltLvlDef) => {
val voltLvl = voltLvlDef match {
case ConfigConventions.voltLvlRegex(id, vNom) =>
VoltLvlParser.parse(id, vNom)
case invalid =>
throw new InvalidConfigParameterException(
s"Got invalid voltage level string $invalid. Has to look like this: {MV, 10 kV}"
)
}
voltLvlRefSystems :+ (voltLvl, refSystem)
voltLvlRefSystems :+ (VoltLvlParser.from(voltLvlDef), refSystem)
}
)
case None => List.empty[(VoltageLevel, RefSystem)]
Expand Down
26 changes: 23 additions & 3 deletions src/main/scala/edu/ie3/simona/config/SimonaConfig.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* © 2021. TU Dortmund University,
* © 2022. TU Dortmund University,
* Institute of Energy Systems, Energy Efficiency and Energy Economics,
* Research group Distribution grid planning and operation
*/
Expand Down Expand Up @@ -377,7 +377,7 @@ object SimonaConfig {
gridIds: scala.Option[scala.List[java.lang.String]],
sNom: java.lang.String,
vNom: java.lang.String,
voltLvls: scala.Option[scala.List[java.lang.String]]
voltLvls: scala.Option[scala.List[SimonaConfig.VoltLvlConfig]]
)
object RefSystemConfig {
def apply(
Expand All @@ -397,11 +397,31 @@ object SimonaConfig {
voltLvls =
if (c.hasPathOrNull("voltLvls"))
scala.Some(
$_L$_str(c.getList("voltLvls"), parentPath, $tsCfgValidator)
$_LSimonaConfig_VoltLvlConfig(
c.getList("voltLvls"),
parentPath,
$tsCfgValidator
)
)
else None
)
}
private def $_LSimonaConfig_VoltLvlConfig(
cl: com.typesafe.config.ConfigList,
parentPath: java.lang.String,
$tsCfgValidator: $TsCfgValidator
): scala.List[SimonaConfig.VoltLvlConfig] = {
import scala.jdk.CollectionConverters._
cl.asScala
.map(cv =>
SimonaConfig.VoltLvlConfig(
cv.asInstanceOf[com.typesafe.config.ConfigObject].toConfig,
parentPath,
$tsCfgValidator
)
)
.toList
}
private def $_reqStr(
parentPath: java.lang.String,
c: com.typesafe.config.Config,
Expand Down
29 changes: 7 additions & 22 deletions src/main/scala/edu/ie3/simona/config/VoltLvlParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,16 @@ import tech.units.indriya.quantity.Quantities
*/
object VoltLvlParser {

/** Parses the voltage level from given config element
/** Create a voltage level definition from config entry
*
* @param configElement
* Config element to parse
* @param config
* Config entry to parse
* @return
* Common voltage level
* A suitable [[VoltageLevel]]
*/
def parse(configElement: VoltLvlConfig): VoltageLevel = {
val id = configElement.id
val vNominal = parseNominalVoltage(configElement.vNom)
parse(id, vNominal)
}

/** Parses a common voltage level from Strings denoting id and nominal voltage
*
* @param id
* Identifier
* @param vNom
* Nominal voltage
* @return
* Common voltage level
*/
def parse(id: String, vNom: String): VoltageLevel = {
val vNominal = parseNominalVoltage(vNom)
parse(id, vNominal)
def from(config: SimonaConfig.VoltLvlConfig): VoltageLevel = {
val vNom = parseNominalVoltage(config.vNom)
parse(config.id, vNom)
}

/** Looks up a common voltage level with the given parameters
Expand Down
Loading