use of com.dat3m.dartagnan.encoding.SymmetryEncoder in project Dat3M by hernanponcedeleon.
the class RefinementSolver method run.
// TODO: We do not yet use Witness information. The problem is that WitnessGraph.encode() generates
// constraints on hb, which is not encoded in Refinement.
public static Result run(SolverContext ctx, ProverEnvironment prover, RefinementTask task) throws InterruptedException, SolverException, InvalidConfigurationException {
task.preprocessProgram();
if (task.getProgram().getAss() instanceof AssertTrue) {
logger.info("Verification finished: assertion trivially holds");
return PASS;
}
task.performStaticProgramAnalyses();
task.performStaticWmmAnalyses();
task.initializeEncoders(ctx);
ProgramEncoder programEncoder = task.getProgramEncoder();
PropertyEncoder propertyEncoder = task.getPropertyEncoder();
WmmEncoder baselineEncoder = task.getBaselineWmmEncoder();
SymmetryEncoder symmEncoder = task.getSymmetryEncoder();
Program program = task.getProgram();
WMMSolver solver = new WMMSolver(task);
Refiner refiner = new Refiner(task);
CAATSolver.Status status = INCONSISTENT;
logger.info("Starting encoding using " + ctx.getVersion());
prover.addConstraint(programEncoder.encodeFullProgram(ctx));
prover.addConstraint(baselineEncoder.encodeFullMemoryModel(ctx));
prover.addConstraint(symmEncoder.encodeFullSymmetry(ctx));
prover.push();
prover.addConstraint(propertyEncoder.encodeSpecification(task.getProperty(), ctx));
// ------ Just for statistics ------
List<DNF<CoreLiteral>> foundCoreReasons = new ArrayList<>();
List<WMMSolver.Statistics> statList = new ArrayList<>();
int iterationCount = 0;
long lastTime = System.currentTimeMillis();
long curTime;
long totalNativeSolvingTime = 0;
long totalCaatTime = 0;
// ---------------------------------
logger.info("Refinement procedure started.");
while (!prover.isUnsat()) {
if (iterationCount == 0 && logger.isDebugEnabled()) {
String smtStatistics = "\n ===== SMT Statistics (after first iteration) ===== \n";
for (String key : prover.getStatistics().keySet()) {
smtStatistics += String.format("\t%s -> %s\n", key, prover.getStatistics().get(key));
}
logger.debug(smtStatistics);
}
iterationCount++;
curTime = System.currentTimeMillis();
totalNativeSolvingTime += (curTime - lastTime);
logger.debug("Solver iteration: \n" + " ===== Iteration: {} =====\n" + "Solving time(ms): {}", iterationCount, curTime - lastTime);
curTime = System.currentTimeMillis();
WMMSolver.Result solverResult;
try (Model model = prover.getModel()) {
solverResult = solver.check(model, ctx);
} catch (SolverException e) {
logger.error(e);
throw e;
}
WMMSolver.Statistics stats = solverResult.getStatistics();
statList.add(stats);
logger.debug("Refinement iteration:\n{}", stats);
status = solverResult.getStatus();
if (status == INCONSISTENT) {
DNF<CoreLiteral> reasons = solverResult.getCoreReasons();
foundCoreReasons.add(reasons);
prover.addConstraint(refiner.refine(reasons, ctx));
if (REFINEMENT_GENERATE_GRAPHVIZ_DEBUG_FILES) {
generateGraphvizFiles(task, solver.getExecution(), iterationCount, reasons);
}
if (logger.isTraceEnabled()) {
// Some statistics
StringBuilder message = new StringBuilder().append("Found inconsistency reasons:");
for (Conjunction<CoreLiteral> cube : reasons.getCubes()) {
message.append("\n").append(cube);
}
logger.trace(message);
}
} else {
// No violations found, we can't refine
break;
}
totalCaatTime += (System.currentTimeMillis() - curTime);
lastTime = System.currentTimeMillis();
}
iterationCount++;
curTime = System.currentTimeMillis();
totalNativeSolvingTime += (curTime - lastTime);
logger.debug("Final solver iteration:\n" + " ===== Final Iteration: {} =====\n" + "Native Solving/Proof time(ms): {}", iterationCount, curTime - lastTime);
if (logger.isInfoEnabled()) {
String message;
switch(status) {
case INCONCLUSIVE:
message = "CAAT Solver was inconclusive (bug?).";
break;
case CONSISTENT:
message = "Violation verified.";
break;
case INCONSISTENT:
message = "Bounded safety proven.";
break;
default:
throw new IllegalStateException("Unknown result type returned by CAAT Solver.");
}
logger.info(message);
}
if (status == INCONCLUSIVE) {
// CAATSolver got no result (should not be able to happen), so we cannot proceed further.
return UNKNOWN;
}
Result veriResult;
long boundCheckTime = 0;
if (prover.isUnsat()) {
// ------- CHECK BOUNDS -------
lastTime = System.currentTimeMillis();
prover.pop();
// Add bound check
prover.addConstraint(propertyEncoder.encodeBoundEventExec(ctx));
// Add back the constraints found during Refinement (TODO: We might need to perform a second refinement)
for (DNF<CoreLiteral> reason : foundCoreReasons) {
prover.addConstraint(refiner.refine(reason, ctx));
}
veriResult = !prover.isUnsat() ? UNKNOWN : PASS;
boundCheckTime = System.currentTimeMillis() - lastTime;
} else {
veriResult = FAIL;
}
if (logger.isInfoEnabled()) {
logger.info(generateSummary(statList, iterationCount, totalNativeSolvingTime, totalCaatTime, boundCheckTime));
}
if (logger.isDebugEnabled()) {
String smtStatistics = "\n ===== SMT Statistics (after final iteration) ===== \n";
for (String key : prover.getStatistics().keySet()) {
smtStatistics += String.format("\t%s -> %s\n", key, prover.getStatistics().get(key));
}
logger.debug(smtStatistics);
}
veriResult = program.getAss().getInvert() ? veriResult.invert() : veriResult;
logger.info("Verification finished with result " + veriResult);
return veriResult;
}
use of com.dat3m.dartagnan.encoding.SymmetryEncoder in project Dat3M by hernanponcedeleon.
the class AssumeSolver method run.
public static Result run(SolverContext ctx, ProverEnvironment prover, VerificationTask task) throws InterruptedException, SolverException, InvalidConfigurationException {
Result res = Result.UNKNOWN;
task.preprocessProgram();
if (task.getProgram().getAss() instanceof AssertTrue) {
logger.info("Verification finished: assertion trivially holds");
return PASS;
}
task.performStaticProgramAnalyses();
task.performStaticWmmAnalyses();
task.initializeEncoders(ctx);
ProgramEncoder programEncoder = task.getProgramEncoder();
PropertyEncoder propertyEncoder = task.getPropertyEncoder();
WmmEncoder wmmEncoder = task.getWmmEncoder();
SymmetryEncoder symmEncoder = task.getSymmetryEncoder();
logger.info("Starting encoding using " + ctx.getVersion());
prover.addConstraint(programEncoder.encodeFullProgram(ctx));
prover.addConstraint(wmmEncoder.encodeFullMemoryModel(ctx));
// For validation this contains information.
// For verification graph.encode() just returns ctx.mkTrue()
prover.addConstraint(task.getWitness().encode(task.getProgram(), ctx));
prover.addConstraint(symmEncoder.encodeFullSymmetry(ctx));
BooleanFormulaManager bmgr = ctx.getFormulaManager().getBooleanFormulaManager();
BooleanFormula assumptionLiteral = bmgr.makeVariable("DAT3M_spec_assumption");
BooleanFormula assumedSpec = bmgr.implication(assumptionLiteral, propertyEncoder.encodeSpecification(task.getProperty(), ctx));
prover.addConstraint(assumedSpec);
logger.info("Starting first solver.check()");
if (prover.isUnsatWithAssumptions(singletonList(assumptionLiteral))) {
prover.addConstraint(propertyEncoder.encodeBoundEventExec(ctx));
logger.info("Starting second solver.check()");
res = prover.isUnsat() ? PASS : Result.UNKNOWN;
} else {
res = FAIL;
}
if (logger.isDebugEnabled()) {
String smtStatistics = "\n ===== SMT Statistics ===== \n";
for (String key : prover.getStatistics().keySet()) {
smtStatistics += String.format("\t%s -> %s\n", key, prover.getStatistics().get(key));
}
logger.debug(smtStatistics);
}
res = task.getProgram().getAss().getInvert() ? res.invert() : res;
logger.info("Verification finished with result " + res);
return res;
}
use of com.dat3m.dartagnan.encoding.SymmetryEncoder in project Dat3M by hernanponcedeleon.
the class IncrementalSolver method run.
public static Result run(SolverContext ctx, ProverEnvironment prover, VerificationTask task) throws InterruptedException, SolverException, InvalidConfigurationException {
Result res = Result.UNKNOWN;
task.preprocessProgram();
if (task.getProgram().getAss() instanceof AssertTrue) {
logger.info("Verification finished: assertion trivially holds");
return PASS;
}
task.performStaticProgramAnalyses();
task.performStaticWmmAnalyses();
task.initializeEncoders(ctx);
ProgramEncoder programEncoder = task.getProgramEncoder();
PropertyEncoder propertyEncoder = task.getPropertyEncoder();
WmmEncoder wmmEncoder = task.getWmmEncoder();
SymmetryEncoder symmEncoder = task.getSymmetryEncoder();
logger.info("Starting encoding using " + ctx.getVersion());
prover.addConstraint(programEncoder.encodeFullProgram(ctx));
prover.addConstraint(wmmEncoder.encodeFullMemoryModel(ctx));
// For validation this contains information.
// For verification graph.encode() just returns ctx.mkTrue()
prover.addConstraint(task.getWitness().encode(task.getProgram(), ctx));
prover.addConstraint(symmEncoder.encodeFullSymmetry(ctx));
logger.info("Starting push()");
prover.push();
prover.addConstraint(propertyEncoder.encodeSpecification(task.getProperty(), ctx));
logger.info("Starting first solver.check()");
if (prover.isUnsat()) {
prover.pop();
prover.addConstraint(propertyEncoder.encodeBoundEventExec(ctx));
logger.info("Starting second solver.check()");
res = prover.isUnsat() ? PASS : Result.UNKNOWN;
} else {
res = FAIL;
}
if (logger.isDebugEnabled()) {
String smtStatistics = "\n ===== SMT Statistics ===== \n";
for (String key : prover.getStatistics().keySet()) {
smtStatistics += String.format("\t%s -> %s\n", key, prover.getStatistics().get(key));
}
logger.debug(smtStatistics);
}
res = task.getProgram().getAss().getInvert() ? res.invert() : res;
logger.info("Verification finished with result " + res);
return res;
}
use of com.dat3m.dartagnan.encoding.SymmetryEncoder in project Dat3M by hernanponcedeleon.
the class TwoSolvers method run.
public static Result run(SolverContext ctx, ProverEnvironment prover1, ProverEnvironment prover2, VerificationTask task) throws InterruptedException, SolverException, InvalidConfigurationException {
Result res = Result.UNKNOWN;
task.preprocessProgram();
if (task.getProgram().getAss() instanceof AssertTrue) {
logger.info("Verification finished: assertion trivially holds");
return PASS;
}
task.performStaticProgramAnalyses();
task.performStaticWmmAnalyses();
task.initializeEncoders(ctx);
ProgramEncoder programEncoder = task.getProgramEncoder();
PropertyEncoder propertyEncoder = task.getPropertyEncoder();
WmmEncoder wmmEncoder = task.getWmmEncoder();
SymmetryEncoder symmEncoder = task.getSymmetryEncoder();
logger.info("Starting encoding using " + ctx.getVersion());
BooleanFormula encodeProg = programEncoder.encodeFullProgram(ctx);
prover1.addConstraint(encodeProg);
prover2.addConstraint(encodeProg);
BooleanFormula encodeWmm = wmmEncoder.encodeFullMemoryModel(ctx);
prover1.addConstraint(encodeWmm);
prover2.addConstraint(encodeWmm);
// For validation this contains information.
// For verification graph.encode() just returns ctx.mkTrue()
BooleanFormula encodeWitness = task.getWitness().encode(task.getProgram(), ctx);
prover1.addConstraint(encodeWitness);
prover2.addConstraint(encodeWitness);
BooleanFormula encodeSymm = symmEncoder.encodeFullSymmetry(ctx);
prover1.addConstraint(encodeSymm);
prover2.addConstraint(encodeSymm);
prover1.addConstraint(propertyEncoder.encodeSpecification(task.getProperty(), ctx));
logger.info("Starting first solver.check()");
if (prover1.isUnsat()) {
prover2.addConstraint(propertyEncoder.encodeBoundEventExec(ctx));
logger.info("Starting second solver.check()");
res = prover2.isUnsat() ? PASS : Result.UNKNOWN;
} else {
res = FAIL;
}
if (logger.isDebugEnabled()) {
String smtStatistics = "\n ===== SMT Statistics ===== \n";
for (String key : prover1.getStatistics().keySet()) {
smtStatistics += String.format("\t%s -> %s\n", key, prover1.getStatistics().get(key));
}
logger.debug(smtStatistics);
}
res = task.getProgram().getAss().getInvert() ? res.invert() : res;
logger.info("Verification finished with result " + res);
return res;
}
Aggregations