Skip to content

Commit

Permalink
fix dumpJson for invalids & fix minor
Browse files Browse the repository at this point in the history
  • Loading branch information
hyerinshelly committed Mar 26, 2024
1 parent e98dffd commit 653e6bb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
14 changes: 11 additions & 3 deletions src/main/scala/fhetest/Checker/Utils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ case class ResultInvalidInfo(
programId: Int,
program: T2Program,
result: String,
outputs: List[Failure],
invalidFilters: List[String],
SEAL: String,
OpenFHE: String,
Expand Down Expand Up @@ -160,10 +161,11 @@ implicit val resultValidInfoDecoder: Decoder[ResultValidInfo] =
)(ResultValidInfo.apply)

implicit val resultInvalidInfoEncoder: Encoder[ResultInvalidInfo] =
Encoder.forProduct6(
Encoder.forProduct7(
"programId",
"program",
"result",
"outputs",
"invalidFilters",
"SEAL",
"OpenFHE",
Expand All @@ -172,16 +174,18 @@ implicit val resultInvalidInfoEncoder: Encoder[ResultInvalidInfo] =
ri.programId,
ri.program,
ri.result,
ri.outputs,
ri.invalidFilters,
ri.SEAL,
ri.OpenFHE,
),
)
implicit val resultInvalidInfoDecoder: Decoder[ResultInvalidInfo] =
Decoder.forProduct6(
Decoder.forProduct7(
"programId",
"program",
"result",
"outputs",
"invalidFilters",
"SEAL",
"OpenFHE",
Expand Down Expand Up @@ -211,18 +215,22 @@ object DumpUtil {
): Unit = res match {
case InvalidResults(results) => {
val resultString = "InvalidResults"
val outputs = results.map(backendResultPair =>
Failure(backendResultPair.backend, backendResultPair.result.toString()),
)
val validFilters = classOf[ValidFilter].getDeclaredClasses.toList
.filter { cls =>
classOf[ValidFilter]
.isAssignableFrom(cls) && cls != classOf[ValidFilter]
}
val invalidFilters = program.invalidFilterIdxList.map {
case i => validFilters.apply(i).toString()
case i => validFilters.apply(i).getSimpleName.replace("$", "")
}
val resultValidInfo = ResultInvalidInfo(
i,
program,
resultString,
outputs,
invalidFilters,
sealVersion,
openfheVersion,
Expand Down
15 changes: 6 additions & 9 deletions src/main/scala/fhetest/Generate/LibConfigGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import fhetest.Utils.*
import fhetest.Generate.Utils.*
import scala.util.Random
import scala.util.control.Breaks._
import cats.conversions.all

val ringDimCandidates: List[Int] = // also in ValidFilter
List(8192, 16384, 32768)
Expand Down Expand Up @@ -87,15 +88,15 @@ case class InvalidLibConfigGenerator(encType: ENC_TYPE)
val totalNumOfFilters = validFilters.length
val allCombinations =
(1 to totalNumOfFilters).toList.flatMap(combinations(_, totalNumOfFilters))
// TODO: currently generate only 1 test case for each class
// val numOfTC = 10
val allCombinations_lazy = LazyList.from(allCombinations)
// TODO: currently generate only 1 test case for each class in each iteration
val numOfTC = 1
val allCombinationsNtimes = allCombinations.flatMap { List.fill(numOfTC)(_) }
val allCombinations_lazy = LazyList.from(allCombinationsNtimes)
def getLibConfigGenerators()
: LazyList[List[AbsStmt] => Option[(LibConfig, List[InvalidFilterIdx])]] =
for {
combination <- allCombinations_lazy
} yield {
println(combination)
val libConfigGeneratorFromAbsStmts = (absStmts: List[AbsStmt]) => {
val randomScheme =
if encType == ENC_TYPE.ENC_INT then Scheme.values(Random.nextInt(2))
Expand All @@ -113,16 +114,13 @@ case class InvalidLibConfigGenerator(encType: ENC_TYPE)
f.getFilteredLibConfigDomain()
}
})
println(s"* Indexes of valid filters which are negated: $combination")
val libConfigOpt = randomLibConfigFromDomain(
false,
absStmts,
randomScheme,
filteredLibConfigDomain,
)
libConfigOpt match {
case None => println("NO DOMAIN")
case Some(_) => ()
}
libConfigOpt match {
case None => None
case Some(libConfig) => Some((libConfig, combination))
Expand Down Expand Up @@ -151,7 +149,6 @@ def randomLibConfigFromDomain(
val realMulDepth: Int = absStmts.count {
case Mul(_, _) | MulP(_, _) => true; case _ => false
}
println(s"realMulDepth: $realMulDepth")
getRandomElementOrBreak(
(filteredLibConfigDomain.mulDepth)(realMulDepth),
)
Expand Down
16 changes: 8 additions & 8 deletions src/main/scala/fhetest/Generate/ValidFilter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import fhetest.Utils.*
// * defined & used in LibConfigGenerator
// * automatically arranged in alphabetical order
// val validFilters = List(
// FilterBoundIsLessThanPlainMod, // 0
// FilterBoundIsLessThanPowerOfModSize, // 1
// FilterFirstModSizeIsLargest, // 2
// FilterLenIsLessThanRingDim, // 3
// FilterModSizeIsBeteween14And60bits, // 4
// FilterMulDepthIsEnough, // 5
// FilterOpenFHEBFVModuli, // 6
// FilterBoundIsLessThanPlainMod,
// FilterBoundIsLessThanPowerOfModSize,
// FilterFirstModSizeIsLargest,
// FilterLenIsLessThanRingDim,
// FilterModSizeIsBeteween14And60bits,
// FilterMulDepthIsEnough,
// FilterOpenFHEBFVModuli,
// FilterPlainModEnableBatching, /* commented */
// FilterPlainModIsPositive, /* commented */
// FilterRingDimIsPowerOfTwo, /* commented */
// FilterScalingTechniqueByScheme // 7
// FilterScalingTechniqueByScheme
// )

trait ValidFilter(prev: LibConfigDomain, validFilter: Boolean) {
Expand Down

0 comments on commit 653e6bb

Please sign in to comment.