Skip to content

Commit

Permalink
Use given backend version if any
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeho committed Mar 11, 2024
1 parent 17e71f6 commit 300a276
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
27 changes: 16 additions & 11 deletions src/main/scala/fhetest/Command.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ abstract class BackendCommand(
/** run command with command-line arguments */
override def apply(args: List[String]) = {
val config = Config(args)
val sealVersion = config.sealVersion
val openfheVersion = config.openfheVersion
val sealVersion = config.sealVersion.getOrElse(SEAL_VERSIONS.head)
val openfheVersion = config.openfheVersion.getOrElse(OPENFHE_VERSIONS.head)
updateBackendVersion(Backend.SEAL, sealVersion)
updateBackendVersion(Backend.OpenFHE, openfheVersion)
runJob(config)
Expand Down Expand Up @@ -186,8 +186,8 @@ case object CmdCheck extends BackendCommand("check") {
val encParamsOpt = config.libConfigOpt.map(_.encParams)
val backends = List(Backend.SEAL, Backend.OpenFHE)
val toJson = config.toJson
val sealVersion = config.sealVersion
val openfheVersion = config.openfheVersion
val sealVersion = config.sealVersion.getOrElse(SEAL_VERSIONS.head)
val openfheVersion = config.openfheVersion.getOrElse(OPENFHE_VERSIONS.head)
val outputs =
Check(dir, backends, encParamsOpt, toJson, sealVersion, openfheVersion)
for output <- outputs do {
Expand All @@ -214,8 +214,8 @@ case object CmdTest extends BackendCommand("test") {
val backendList = List(Backend.SEAL, Backend.OpenFHE)
val encParamsOpt = config.libConfigOpt.map(_.encParams)
val toJson = config.toJson
val sealVersion = config.sealVersion
val openfheVersion = config.openfheVersion
val sealVersion = config.sealVersion.getOrElse(SEAL_VERSIONS.head)
val openfheVersion = config.openfheVersion.getOrElse(OPENFHE_VERSIONS.head)
if (config.debug) {
println(s"EncType : $encType")
println(s"SEAL version : $sealVersion")
Expand Down Expand Up @@ -246,22 +246,27 @@ case object CmdTest extends BackendCommand("test") {
}
}

case object CmdReplay extends BackendCommand("replay") {
case object CmdReplay extends Command("replay") {
val help = "Replay the given json."
val examples = List(
"fhetest replay -fromjson:logs/test/success/2.json",
"fhetest replay -fromjson:logs/test/success/2.json -b:OpenFHE",
"fhetest replay -fromjson:logs/test/success/2.json -b:OpenFHE -openfhe:1.0.4",
)
def runJob(config: Config): Unit =
val jsonFileName = config.fromJson.getOrElseThrow("No json file given.")
val resultInfo = DumpUtil.readResult(jsonFileName)
val sealVersion = resultInfo.SEAL
val openfheVersion = resultInfo.OpenFHE
val sealVersion = config.sealVersion.getOrElse(resultInfo.SEAL)
val openfheVersion = config.openfheVersion.getOrElse(resultInfo.OpenFHE)
if (config.debug) {
println(s"SEAL version : $sealVersion")
println(s"OpenFHE version : $openfheVersion")
}
updateBackendVersion(Backend.SEAL, sealVersion)
updateBackendVersion(Backend.OpenFHE, openfheVersion)
val t2Program = resultInfo.program
val libConfig = t2Program.libConfig
val encParams = libConfig.encParams
updateBackendVersion(Backend.SEAL, sealVersion)
updateBackendVersion(Backend.OpenFHE, openfheVersion)
config.backend match {
case Some(backend) =>
given DirName = getWorkspaceDir(backend)
Expand Down
19 changes: 13 additions & 6 deletions src/main/scala/fhetest/Config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class Config(
var genStrategy: Option[Strategy] = None,
var genCount: Option[Int] = None,
var toJson: Boolean = false,
var sealVersion: String = SEAL_VERSIONS.head,
var openfheVersion: String = OPENFHE_VERSIONS.head,
var sealVersion: Option[String] = None,
var openfheVersion: Option[String] = None,
var libConfigOpt: Option[LibConfig] = None,
var fromJson: Option[String] = None,
var filter: Boolean = true,
Expand Down Expand Up @@ -48,12 +48,19 @@ object Config {
case "count" => config.genCount = Some(value.toInt)
case "json" => config.toJson = value.toBoolean
case "seal" =>
if SEAL_VERSIONS.contains(value) then config.sealVersion = value
else throw new Error(s"Unknown SEAL version: $value")
if SEAL_VERSIONS.contains(value) then
config.sealVersion = Some(value)
else
throw new Error(
s"Unknown SEAL version: $value, use one of ${SEAL_VERSIONS.mkString(", ")}",
)
case "openfhe" =>
if OPENFHE_VERSIONS.contains(value) then
config.openfheVersion = value
else throw new Error(s"Unknown OpenFHE version: $value")
config.openfheVersion = Some(value)
else
throw new Error(
s"Unknown OpenFHE version: $value, use one of ${OPENFHE_VERSIONS.mkString(", ")}",
)
// FIXME: temperalily added
case "libconfig" =>
config.libConfigOpt = Some(LibConfig())
Expand Down

0 comments on commit 300a276

Please sign in to comment.