Skip to content

Commit

Permalink
add one valid filter && fix Replay
Browse files Browse the repository at this point in the history
  • Loading branch information
hyerinshelly committed Mar 27, 2024
1 parent 653e6bb commit 8e7373c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
20 changes: 15 additions & 5 deletions src/main/scala/fhetest/Checker/Utils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ import java.io.{File, PrintWriter}
import java.nio.file.{Files, Path, Paths, StandardCopyOption}

case class Failure(library: String, failedResult: String)

trait ResultInfo {
val programId: Int
val program: T2Program
val result: String
val SEAL: String
val OpenFHE: String
}
case class ResultValidInfo(
programId: Int,
program: T2Program,
Expand All @@ -24,7 +32,7 @@ case class ResultValidInfo(
expected: String,
SEAL: String,
OpenFHE: String,
)
) extends ResultInfo
case class ResultInvalidInfo(
programId: Int,
program: T2Program,
Expand All @@ -33,7 +41,7 @@ case class ResultInvalidInfo(
invalidFilters: List[String],
SEAL: String,
OpenFHE: String,
)
) extends ResultInfo

// Define en/decoders using Circe
// Scheme
Expand Down Expand Up @@ -277,10 +285,12 @@ object DumpUtil {
}
}

def readResult(filePath: String): ResultValidInfo = {
def readResult(filePath: String): ResultInfo = {
val fileContents = readFile(filePath)
val resultValidInfo = decode[ResultValidInfo](fileContents)
resultValidInfo match {
val resultInfo =
if (filePath contains "invalid") decode[ResultInvalidInfo](fileContents)
else decode[ResultValidInfo](fileContents)
resultInfo match {
case Right(info) => info
case Left(error) => throw new Exception(s"Error: $error")
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/fhetest/Command.scala
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ case object CmdTest extends BackendCommand("test") {
}

case object CmdReplay extends Command("replay") {
val help = "Replay the given json."
val help =
"Replay the given json with specified backend (default: interpreter)."
val examples = List(
"fhetest replay -fromjson:logs/test/success/2.json",
"fhetest replay -fromjson:logs/test/success/2.json -b:OpenFHE",
Expand Down
27 changes: 27 additions & 0 deletions src/main/scala/fhetest/Generate/ValidFilter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import fhetest.Utils.*
// FilterLenIsLessThanRingDim,
// FilterModSizeIsBeteween14And60bits,
// FilterMulDepthIsEnough,
// FilterMulDepthIsNotNegative,
// FilterOpenFHEBFVModuli,
// FilterPlainModEnableBatching, /* commented */
// FilterPlainModIsPositive, /* commented */
Expand Down Expand Up @@ -61,6 +62,32 @@ object ValidFilter {
)
}

case class FilterMulDepthIsNotNegative(
prev: LibConfigDomain,
validFilter: Boolean,
) extends ValidFilter(prev, validFilter) {
def getFilteredLibConfigDomain(): LibConfigDomain =
LibConfigDomain(
scheme = prev.scheme,
ringDim = prev.ringDim,
mulDepth =
if (validFilter)
(realMulDepth => (prev.mulDepth)(realMulDepth).filter(_ >= 0))
else
(realMulDepth => (prev.mulDepth)(realMulDepth).filterNot(_ >= 0)),
plainMod = prev.plainMod,
firstModSize = prev.firstModSize,
scalingModSize = prev.scalingModSize,
securityLevel = prev.securityLevel,
scalingTechnique = prev.scalingTechnique,
lenMin = prev.lenMin,
lenMax = prev.lenMax,
boundMin = prev.boundMin,
boundMax = prev.boundMax,
rotateBound = prev.rotateBound,
)
}

// TODO: There are 2 options for this implementation
// * Current implementation filters scalingModSize which is not greater than firstModSize
// * Another option is to filter firstModSize to be not smaller than scalingModeSize
Expand Down

0 comments on commit 8e7373c

Please sign in to comment.