fix defaults

This commit is contained in:
2025-10-06 17:29:33 +02:00
parent 3d981d16ed
commit 5218ed37b1
8 changed files with 26 additions and 26 deletions

View File

@@ -12,12 +12,12 @@ trait BaseOption[T](using conv: ValueConverter[T]) extends ConfigElement {
scallop = createScallop(scallopConf, group) scallop = createScallop(scallopConf, group)
} }
def default: () => T def default: () => Option[T]
def get: T = scallop.getOrElse(default()) def get: Option[T] = scallop.toOption.orElse(default())
def apply(): T = get def apply(): T = get.get
def getToolParameters: Seq[Shellable] = if (scallop.isDefined) Seq(s"$toolName", getToolArg) else Seq() def getToolParameters: Seq[Shellable] = if (get.isDefined) Seq(s"$toolName", getToolArg) else Seq()
def toolName: String def toolName: String
def getToolArg: String = get.toString def getToolArg: String = get.toString

View File

@@ -5,7 +5,7 @@ import org.rogach.scallop.*
enum Color: enum Color:
case Red, Green, Blue case Red, Green, Blue
class ChoiceOption(choices: Seq[String], cliName: String, val toolName: String, descr: String, val default: () => String, required: Boolean, cliShort: Char) extends BaseOption[String] { class ChoiceOption(choices: Seq[String], cliName: String, val toolName: String, descr: String, val default: () => Option[String], required: Boolean, cliShort: Char) extends BaseOption[String] {
override protected def createScallop(conf: ScallopConf, group: ScallopOptionGroup): ScallopOption[String] = { override protected def createScallop(conf: ScallopConf, group: ScallopOptionGroup): ScallopOption[String] = {
conf.choice(choices, name = cliName, short = cliShort, descr = descr, required = required, group = group) conf.choice(choices, name = cliName, short = cliShort, descr = descr, required = required, group = group)
} }

View File

@@ -34,19 +34,19 @@ trait BaseGroup extends ConfigElement with ValidationBase[BaseOption] with Valid
} }
} }
def value[T](cliName: String, toolName: String, descr: String = "", default: () => T, required: Boolean = false, cliShort: Char = '\u0000')(using conv: ValueConverter[T]): ValueOption[T] = add(ValueOption(cliName, toolName, descr, default, required, cliShort)) def value[T](cliName: String, toolName: String, descr: String = "", default: () => Option[T] = () => None, required: Boolean = false, cliShort: Char = '\u0000')(using conv: ValueConverter[T]): ValueOption[T] = add(ValueOption(cliName, toolName, descr, default, required, cliShort))
def valueS[T](name: String, descr: String = "", default: () => T, required: Boolean = false, cliShort: Char = '\u0000')(using conv: ValueConverter[T]): ValueOption[T] = add(ValueOption(name, name, descr, default, required, cliShort)) def valueS[T](name: String, descr: String = "", default: () => Option[T] = () => None, required: Boolean = false, cliShort: Char = '\u0000')(using conv: ValueConverter[T]): ValueOption[T] = add(ValueOption(name, name, descr, default, required, cliShort))
def trail[T](toolName: String, descr: String = "", default: () => T, required: Boolean = false)(using conv: ValueConverter[T]): TrailOption[T] = add(TrailOption(toolName, descr, default, required)) def trail[T](toolName: String, descr: String = "", default: () => Option[T] = () => None, required: Boolean = false)(using conv: ValueConverter[T]): TrailOption[T] = add(TrailOption(toolName, descr, default, required))
def choice(choices: Seq[String], cliName: String, toolName: String, descr: String = "", default: () => String, required: Boolean = false, cliShort: Char = '\u0000'): ChoiceOption = add(ChoiceOption(choices, cliName, toolName, descr, default, required, cliShort)) def choice(choices: Seq[String], cliName: String, toolName: String, descr: String = "", default: () => Option[String] = () => None, required: Boolean = false, cliShort: Char = '\u0000'): ChoiceOption = add(ChoiceOption(choices, cliName, toolName, descr, default, required, cliShort))
def choiceS(choices: Seq[String], name: String, descr: String = "", default: () => String, required: Boolean = false, cliShort: Char = '\u0000'): ChoiceOption = add(ChoiceOption(choices, name, name, descr, default, required, cliShort)) def choiceS(choices: Seq[String], name: String, descr: String = "", default: () => Option[String] = () => None, required: Boolean = false, cliShort: Char = '\u0000'): ChoiceOption = add(ChoiceOption(choices, name, name, descr, default, required, cliShort))
def tally(cliName: String, toolName: String, descr: String = "", required: Boolean = false, cliShort: Char = '\u0000'): TallyOption = add(TallyOption(cliName, toolName, descr, required, cliShort)) def tally(cliName: String, toolName: String, descr: String = "", required: Boolean = false, cliShort: Char = '\u0000'): TallyOption = add(TallyOption(cliName, toolName, descr, required, cliShort))
def tallyS(name: String, descr: String = "", required: Boolean = false, cliShort: Char = '\u0000'): TallyOption = add(TallyOption(name, name, descr, required, cliShort)) def tallyS(name: String, descr: String = "", required: Boolean = false, cliShort: Char = '\u0000'): TallyOption = add(TallyOption(name, name, descr, required, cliShort))
def toggle(cliName: String, toolName: String, descr: String = "", default: () => Boolean = () => false, required: Boolean = false, cliShort: Char = '\u0000'): ToggleOption = add(ToggleOption(cliName, toolName, descr, default, required, cliShort)) def toggle(cliName: String, toolName: String, descr: String = "", default: () => Option[Boolean] = () => None, required: Boolean = false, cliShort: Char = '\u0000'): ToggleOption = add(ToggleOption(cliName, toolName, descr, default, required, cliShort))
def toggleS(name: String, descr: String = "", default: () => Boolean, required: Boolean = false, cliShort: Char = '\u0000'): ToggleOption = add(ToggleOption(name, name, descr, default, required, cliShort)) def toggleS(name: String, descr: String = "", default: () => Option[Boolean] = () => None, required: Boolean = false, cliShort: Char = '\u0000'): ToggleOption = add(ToggleOption(name, name, descr, default, required, cliShort))
} }
trait OptionGroup extends BaseGroup { trait OptionGroup extends BaseGroup {

View File

@@ -7,5 +7,5 @@ class TallyOption(cliName: String, val toolName: String, descr: String, required
conf.tally(name = cliName, short = cliShort, descr = descr, group = group) conf.tally(name = cliName, short = cliShort, descr = descr, group = group)
} }
override def default: () => Int = () => 0 override def default: () => Option[Int] = () => None
} }

View File

@@ -2,7 +2,7 @@ package com.minres.tgc.hammer.options
import org.rogach.scallop.* import org.rogach.scallop.*
class ToggleOption(cliName: String, val toolName: String, descr: String, val default: () => Boolean, required: Boolean, cliShort: Char) extends BaseOption[Boolean] { class ToggleOption(cliName: String, val toolName: String, descr: String, val default: () => Option[Boolean], required: Boolean, cliShort: Char) extends BaseOption[Boolean] {
override protected def createScallop(conf: ScallopConf, group: ScallopOptionGroup): ScallopOption[Boolean] = { override protected def createScallop(conf: ScallopConf, group: ScallopOptionGroup): ScallopOption[Boolean] = {
conf.toggle(name = cliName, short = cliShort, descrYes = descr, required = required, group = group) conf.toggle(name = cliName, short = cliShort, descrYes = descr, required = required, group = group)

View File

@@ -2,7 +2,7 @@ package com.minres.tgc.hammer.options
import org.rogach.scallop.* import org.rogach.scallop.*
class TrailOption[T](val toolName: String, descr: String, val default: () => T, required: Boolean)(using conv: ValueConverter[T]) extends BaseOption[T] { class TrailOption[T](val toolName: String, descr: String, val default: () => Option[T], required: Boolean)(using conv: ValueConverter[T]) extends BaseOption[T] {
override protected def createScallop(conf: ScallopConf, group: ScallopOptionGroup): ScallopOption[T] = { override protected def createScallop(conf: ScallopConf, group: ScallopOptionGroup): ScallopOption[T] = {
conf.trailArg[T](descr = descr, required = required, group = group) conf.trailArg[T](descr = descr, required = required, group = group)
} }

View File

@@ -2,7 +2,7 @@ package com.minres.tgc.hammer.options
import org.rogach.scallop.* import org.rogach.scallop.*
class ValueOption[T](cliName: String, val toolName: String, descr: String, val default: () => T, required: Boolean, cliShort: Char)(using conv: ValueConverter[T]) extends BaseOption[T] { class ValueOption[T](cliName: String, val toolName: String, descr: String, val default: () => Option[T], required: Boolean, cliShort: Char)(using conv: ValueConverter[T]) extends BaseOption[T] {
override protected def createScallop(conf: ScallopConf, group: ScallopOptionGroup): ScallopOption[T] = { override protected def createScallop(conf: ScallopConf, group: ScallopOptionGroup): ScallopOption[T] = {
conf.opt[T](name = cliName, short = cliShort, descr = descr, required = required, group = group) conf.opt[T](name = cliName, short = cliShort, descr = descr, required = required, group = group)
} }

View File

@@ -10,25 +10,25 @@ class SchedulingParameters extends OptionGroup {
override def name: String = "Longnail Scheduling Args" override def name: String = "Longnail Scheduling Args"
class PrepareOptions extends CommandGroup("--prepare-schedule-lil") { class PrepareOptions extends CommandGroup("--prepare-schedule-lil") {
val schedulingAlgo = choiceS(Seq("LEGACY", "MS", "PAMS", "PARAMS", "MI_MS", "MI_PAMS", "MI_PARAMS"), name = "schedulingAlgo", default = () => "LEGACY", descr = val schedulingAlgo = choiceS(Seq("LEGACY", "MS", "PAMS", "PARAMS", "MI_MS", "MI_PAMS", "MI_PARAMS"), name = "schedulingAlgo", default = () => Some("LEGACY"), descr =
"Scheduling algorithm used by Longnail; Modulo Scheduling (MS) can be extended with Predicate-aware (PA) and Resource-aware (RA), Inter-Instruction sharing is activated in the MI variants") "Scheduling algorithm used by Longnail; Modulo Scheduling (MS) can be extended with Predicate-aware (PA) and Resource-aware (RA), Inter-Instruction sharing is activated in the MI variants")
val cellLibrary = value[Path](cliName = "cellLibrary", toolName = "library", descr = "The cell library used by Longnail (example: longnail/test/LILToHW/longnail*.yaml", default = () => Path("")) val cellLibrary = value[Path](cliName = "cellLibrary", toolName = "library", descr = "The cell library used by Longnail (example: longnail/test/LILToHW/longnail*.yaml")
val opTyLibrary = valueS[Path](name = "opTyLibrary", descr = "The operator type model used for detailed data (e.g. from OL SKY130 in longnail/opTyLibraries/OL2.yaml)", default = () => Path("")) val opTyLibrary = valueS[Path](name = "opTyLibrary", descr = "The operator type model used for detailed data (e.g. from OL SKY130 in longnail/opTyLibraries/OL2.yaml)")
check(cellLibrary)(checkPathIsFile) check(cellLibrary)(checkPathIsFile)
check(opTyLibrary)(checkPathIsFile) check(opTyLibrary)(checkPathIsFile)
} }
val prepare = add(new PrepareOptions) val prepare = add(new PrepareOptions)
class ScheduleOptions extends CommandGroup("--schedule-lil") { class ScheduleOptions extends CommandGroup("--schedule-lil") {
val schedulingTimeout = valueS[Int](name = "schedulingTimeout", default = () => 10, descr = "Longnail scheduling timeout in seconds") val schedulingTimeout = valueS[Int](name = "schedulingTimeout", default = () => Some(10), descr = "Longnail scheduling timeout in seconds")
val schedulingRefineTimeout = value[Int](cliName = "schedulingRefineTimeout", toolName = "schedRefineTimeout", default = () => 10, descr = "Longnail schedule refinement timeout in seconds") val schedulingRefineTimeout = value[Int](cliName = "schedulingRefineTimeout", toolName = "schedRefineTimeout", default = () => Some(10), descr = "Longnail schedule refinement timeout in seconds")
val schedulingSelectionFile = value[Path](cliName = "schedulingKconf", toolName = "solSelKconfPath", default = () => OUT_DIR / "scheduling.KConfig", descr = "Path for the created KConfig file for selecting a scheduling solution") val schedulingSelectionFile = value[Path](cliName = "schedulingKconf", toolName = "solSelKconfPath", default = () => Some(OUT_DIR / "scheduling.KConfig"), descr = "Path for the created KConfig file for selecting a scheduling solution")
val ilpSolver = choice(Seq("CBC", "GLPK", "SCIP", "HIGHS", "GUROBI", "CPLEX", "XPRESS", "COPT"), cliName = "ilpSolver", toolName = "solver", default = () => "CBC", descr = "The ILP solver used by Longnail; currently only CBC is tested") val ilpSolver = choice(Seq("CBC", "GLPK", "SCIP", "HIGHS", "GUROBI", "CPLEX", "XPRESS", "COPT"), cliName = "ilpSolver", toolName = "solver", default = () => Some("CBC"), descr = "The ILP solver used by Longnail; currently only CBC is tested")
val verboseSched = toggle(cliName = "verboseSched", toolName = "verbose", descr = "Enable verbose ILP solver messages") val verboseSched = toggle(cliName = "verboseSched", toolName = "verbose", descr = "Enable verbose ILP solver messages")
val clockPeriod = value[Int](cliName = "clockPeriod", toolName = "clockTime", descr = "The target clock period; uses same time unit as delays in opTyLibrary", default = () => 10) val clockPeriod = value[Int](cliName = "clockPeriod", toolName = "clockTime", descr = "The target clock period; uses same time unit as delays in opTyLibrary", default = () => Some(10))
} }
val schedule = add(new ScheduleOptions) val schedule = add(new ScheduleOptions)
val maxLoopUnrollFactor = value[Int](cliName = "--maxLoopUnrollFactor", toolName = "max-unroll-factor", default = () => 16, descr = "Longnail max loop unroll factor") val maxLoopUnrollFactor = value[Int](cliName = "--maxLoopUnrollFactor", toolName = "max-unroll-factor", default = () => Some(16), descr = "Longnail max loop unroll factor")
val schedulingSolutionFile = value[Path](cliName = "--schedulingMLIR", toolName = "o", default = () => OUT_DIR / "scheduling_solutions.mlir", descr = "Output file with different scheduling solutions") val schedulingSolutionFile = value[Path](cliName = "--schedulingMLIR", toolName = "o", default = () => Some(OUT_DIR / "scheduling_solutions.mlir"), descr = "Output file with different scheduling solutions")
} }