Skip to content

Commit

Permalink
add using keyword sets
Browse files Browse the repository at this point in the history
  • Loading branch information
hyerinshelly committed Jul 3, 2024
1 parent 68c6563 commit 0461e36
Show file tree
Hide file tree
Showing 15 changed files with 505 additions and 174 deletions.
17 changes: 17 additions & 0 deletions src/main/scala/fhetest/Checker/CheckResult.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,22 @@ case class Diff(
results: List[BackendResultPair],
fails: List[BackendResultPair],
) extends CheckResult
// InvalidResults: only for printing results in debug mode
case class InvalidResults(results: List[BackendResultPair]) extends CheckResult
case class InvalidNormalResults(
results: List[BackendResultPair],
normals: List[BackendResultPair],
) extends CheckResult
case class InvalidExpectedExceptions(
results: List[BackendResultPair],
expectedExceptions: List[BackendResultPair],
) extends CheckResult
case class InvalidUnexpectedExceptions(
results: List[BackendResultPair],
unexpectedExceptions: List[BackendResultPair],
) extends CheckResult
case class InvalidErrors(
results: List[BackendResultPair],
errors: List[BackendResultPair],
) extends CheckResult
case class ParserError(results: List[BackendResultPair]) extends CheckResult
101 changes: 101 additions & 0 deletions src/main/scala/fhetest/Checker/ExceptionMsgKeyword.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package fhetest.Checker

import fhetest.Generate.ValidFilter
import fhetest.Generate.getValidFilterList //TODO
import fhetest.Generate.Utils.InvalidFilterIdx

type LibConfigArgumentName = String

val libConfigArguments: Set[LibConfigArgumentName] =
Set(
"Scheme",
"RingDim",
"MulDepth",
"PlaindMod",
"ModSize",
"FirstModSize",
"ScalingModSize",
"SecurityLevel",
"ScalingTechnique",
"Len",
"Bound",
"RotateBound",
)

// TODO: fill out
// Note: Keywords should be in lower cases!
def mapLibConfigArgument2Keywords(
argName: LibConfigArgumentName,
): Set[String] = {
val commonKeywords =
Set(" parameters", "ring dimension", " ringdim", " primes", " overflow")
val modSizeKeywords = Set(" moduli", " bit_sizes", "bit length")
val uniqueKeywords = argName match {
case "Scheme" => Set("scheme")
case "RingDim" => Set("ring dimension", " ringdim")
case "MulDepth" =>
Set(
"multiplicative depth",
" towers",
"end of modulus switching chain",
"removing last element of dcrtpoly",
"scale out of bounds",
"encoded values are too large",
)
case "PlainMod" => Set(" plain_modulus", " plaintext_modulus")
case "ModSize" => modSizeKeywords
case "FirstModSize" => modSizeKeywords ++ Set()
case "ScalingModSize" => modSizeKeywords ++ Set()
case "SecurityLevel" => Set("security level", " SecurityLevel")
case "ScalingTechnique" => Set("security mode")
case "Len" =>
Set(
"values_matrix size",
" values_size",
// "should not be greater than ringdim", // Currently, overlap with " ringDim" in commonKeywords
)
case "Bound" => Set("encoded values are too large")
case "RotateBound" => Set("out_of_range", "evalkey for index")
case s: String =>
throw new Exception(s"$s is not defined as LibConfigArgument.")
}
commonKeywords ++ uniqueKeywords
}

val validFilters =
getValidFilterList().map(filter => filter.getSimpleName.replace("$", ""))

def mapFilterName2LibConfigArgumentMap(
filterName: String,
): LibConfigArgumentName =
filterName match {
case "FilterBoundIsLessThanPlainMod" => "Bound"
case "FilterBoundIsLessThanPowerOfModSize" => "Bound"
case "FilterFirstModSizeIsLargest" => "FirstModSize"
case "FilterLenIsLessThanRingDim" => "Len"
case "FilterModSizeIsBeteween14And60bits" => "ModSize"
case "FilterMulDepthIsEnough" => "MulDepth"
case "FilterMulDepthIsNotNegative" => "MulDepth"
case "FilterOpenFHEBFVModuli" => "ModSize"
case "FilterPlainModEnableBatching" => "PlainMod"
case "FilterPlainModIsPositive" => "PlainMod"
case "FilterRingDimIsPowerOfTwo" => "RingDim"
case "FilterRotateBoundTest" => "RotateBound"
case "FilterScalingTechniqueByScheme" => "ScalingTechnique"
case s: String => throw new Exception(s"Keyword for $s is undifined.")
}

def getKeywordsFromFilters(
invalidFilterIdxList: List[InvalidFilterIdx],
): Set[String] = {
val invalidFilterNameList = invalidFilterIdxList.map {
case i => validFilters.apply(i)
}
invalidFilterNameList.foldLeft(Set[String]()) { (acc, filterName) =>
{
val argName = mapFilterName2LibConfigArgumentMap(filterName)
val keywords = mapLibConfigArgument2Keywords(argName)
acc ++ keywords
}
}
}
3 changes: 3 additions & 0 deletions src/main/scala/fhetest/Checker/ExecuteResult.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ case object PrintError extends ExecuteResult {
case class LibraryError(msg: String) extends ExecuteResult {
override def toString: String = s"LibraryError: $msg"
}
case class LibraryException(msg: String) extends ExecuteResult {
override def toString: String = s"LibraryException: $msg"
}
case object ParseError extends ExecuteResult
case object TimeoutError extends ExecuteResult {
override def toString: String = s"timeout"
Expand Down
Loading

0 comments on commit 0461e36

Please sign in to comment.