diff --git a/src/main/scala/fhetest/Command.scala b/src/main/scala/fhetest/Command.scala index 6754277..f80adb1 100644 --- a/src/main/scala/fhetest/Command.scala +++ b/src/main/scala/fhetest/Command.scala @@ -144,6 +144,7 @@ case object CmdExecute extends Command("execute") { } } +// TODO : Get Strategy from the command line /** `gen` command */ case object CmdGen extends Command("gen") { val help = "Generate random T2 programs." @@ -189,20 +190,21 @@ case object CmdCheck extends Command("check") { case object CmdTest extends Command("test") { val help = "Check after Generate random T2 programs." val examples = List( - "fhetest test --INT", - "fhetest test --INT 10", - "fhetest test --DOUBLE 10", + "fhetest test --INT --random", + "fhetest test --INT --random 10", + "fhetest test --DOUBLE --exhaust 10", ) def apply(args: List[String]): Unit = args match { case Nil => println("No argument given.") - case encTypeString :: remain => { + case encTypeString :: stgString :: remain => { val nOpt = remain match { case nString :: _ => Some(nString.toInt) case _ => None } val encType = parseEncType(encTypeString) - val generator = Generate(encType) + val strategy = parseStrategy(stgString) + val generator = Generate(encType, strategy) val programs = generator(nOpt).map(T2Program(_)) val backendList = List(Backend.SEAL, Backend.OpenFHE) // TODO: temporary encParams. Fix after having parameter genernation. @@ -216,5 +218,6 @@ case object CmdTest extends Command("test") { println("=" * 80) } } + case _ => println("EncType and Strategy are required.") } } diff --git a/src/main/scala/fhetest/Generate/TemplateGenerator.scala b/src/main/scala/fhetest/Generate/TemplateGenerator.scala index 975b1dc..9df5ac5 100644 --- a/src/main/scala/fhetest/Generate/TemplateGenerator.scala +++ b/src/main/scala/fhetest/Generate/TemplateGenerator.scala @@ -1,5 +1,7 @@ package fhetest.Generate +import scala.util.Random + // Template Generation Strategy enum Strategy: case Exhaustive, Random @@ -32,6 +34,9 @@ object ExhaustiveGenerator extends TemplateGenerator { object RandomGenerator extends TemplateGenerator { def generateTemplates(): LazyList[Template] = { - ??? + def randomTemplateOfSize(n: Int): Template = { + (1 to n).map(_ => Random.shuffle(allAbsStmts).head).toList + } + LazyList.from(1).map(randomTemplateOfSize) } } diff --git a/src/main/scala/fhetest/Phase/Generate.scala b/src/main/scala/fhetest/Phase/Generate.scala index 5ac8ff1..1f74877 100644 --- a/src/main/scala/fhetest/Phase/Generate.scala +++ b/src/main/scala/fhetest/Phase/Generate.scala @@ -37,6 +37,7 @@ case class Generate( val allTemplates = tempGen.generateTemplates() def apply(nOpt: Option[Int]): LazyList[String] = { + println(s"Genrating Strategy: $strategy") val templates = nOpt match { case Some(n) => allTemplates.take(n) case None => allTemplates diff --git a/src/main/scala/fhetest/Utils/Utils.scala b/src/main/scala/fhetest/Utils/Utils.scala index 27be177..a850004 100644 --- a/src/main/scala/fhetest/Utils/Utils.scala +++ b/src/main/scala/fhetest/Utils/Utils.scala @@ -10,6 +10,7 @@ import scala.util.Try import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.Future import java.util.concurrent.atomic.AtomicInteger +import fhetest.Generate.Strategy enum Backend(val name: String): case SEAL extends Backend("SEAL") @@ -61,6 +62,11 @@ def parseWordSizeAndEncParams(args: List[String]): (Option[Int], EncParams) = { (wordSizeOpt, EncParams(ringDim, mulDepth, plainMod)) } +def parseStrategy(sString: String): Strategy = + parsePrefixedArg(sString) match + case Some("exhaust") => Strategy.Exhaustive + case Some("random") => Strategy.Random + case _ => throw new Exception("Invalid strategy") def getWorkspaceDir(backend: Backend): String = backend match case Backend.SEAL => fhetest.SEAL_DIR