Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leiqi concrete simulator #260

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

lichye
Copy link
Contributor

@lichye lichye commented Feb 18, 2025

This pull request will merge the concrete engine into the master respority.
The code does not change the main work flow of the Uclid5.
When "-c" is called, we will run concrete Simulator to simulate the uclid file.
There is still lots of util to be supported , but a early version will be helpful for testing.

@lichye lichye requested a review from polgreen as a code owner February 18, 2025 12:38
@lichye lichye force-pushed the leiqi-concreteSimulator branch 2 times, most recently from a816b70 to d8c1f73 Compare February 21, 2025 13:53
@lichye lichye force-pushed the leiqi-concreteSimulator branch from 95353a9 to 6cd8952 Compare February 21, 2025 14:08
Copy link
Contributor

@polgreen polgreen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I have some questions about the comments that have been left in, and specifically what is a ConcreteUndef, and when do we encounter this.

Also, please add tests for

  • all configuration options of the simulator
  • testing violated assertions
  • testing assumptions
  • printing the trace

var varMap: scala.collection.mutable.Map[Identifier, ConcreteValue] = collection.mutable.Map();
var varTypeMap: scala.collection.mutable.Map[Identifier, Type] = collection.mutable.Map();
//var functionMap: scala.collection.mutable.Map[Identifier, ConcreteValue] = collection.mutable.Map();
var inputMap: scala.collection.mutable.Map[Identifier, ConcreteValue] = collection.mutable.Map();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the functionMap no longer needed? If so, can you delete this commented out line please

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was in the todo list. So, I left the function Map here.

sealed abstract class ConcreteValue{
def valueClone: ConcreteValue;
}
case class ConcreteUndef () extends ConcreteValue{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is an Undef? Could you add a comment above this saying what it is? (The others are all obvious)


object ConcreteSimulator {
//debug useful flag
var isPrintResult: Boolean = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

debug printing should go via a logger (see the logger in symbolic simulator:

val defaultLog = Logger(classOf[SymbolicSimulator])
)

defaultLog.debug("eqStates: {}", eqStates.toString())

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or you can use UclidMain.printError, UclidMain.printStatus etc

def write (variable: Identifier, value: ConcreteValue) {
if (varMap.contains(variable)) varMap(variable) = value
else if (inputMap.contains(variable)) inputMap(variable) = value
// else throw new Error(f"Variable ${variable.toString} not found in context")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we still be throwing this error?

}
// TODO: ... fill in
case ArrayType(inType, outType) => {
// TODO: outType could be complex type like another array or record
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this TODO still relevant? If not, can you delete it

new smt.SynthLibInterface(config.synthesizer, config.sygusFormat)
val isConcrete = config.simulate && module.cmds.exists(p => p.name.toString == "concrete")
if (isConcrete) {
UclidMain.printVerbose("Begining Concrete Simulation")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: Beginning

property jump_a: a!=3;

control {
v = bmc(5);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test does bmc, not concrete

@@ -113,6 +114,10 @@ object UclidMain {
(exec, c) => c.copy(synthesizer = exec.split(" ").toList)
}.text("Command line to invoke SyGuS synthesizer.")

opt[String]('c', "simulate").valueName("<Cmd>").action{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So to use this, we have to use simulate and the command "concrete" in the control block? What happens if i use simulate without the command "concrete" in the control block?

control {
v = concrete (5);
check;
// v.print_concrete_trace(a,numbers);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

none of your tests actually run print_concrete_trace.

ConcreteSpec.expectedFails("./test/concrete/concrete-9.ucl", 1)
}
"concrete-10.ucl" should "fail one assertion." in {
ConcreteSpec.expectedFails("./test/concrete/concrete-10.ucl", 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a test that prints the concrete trace, and checks the length of it at least (there are some tests in VerifierSpec that do this that you can copy).

Also make sure at least one test runs each of the configuration options

Also, test what should happen if an assertion is violated by the concrete trace

And test that assumptions block the concrete values correctly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants