Search in sources :

Example 1 with CoreLiteral

use of com.dat3m.dartagnan.solver.caat4wmm.coreReasoning.CoreLiteral 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;
}
Also used : PropertyEncoder(com.dat3m.dartagnan.encoding.PropertyEncoder) CAATSolver(com.dat3m.dartagnan.solver.caat.CAATSolver) ProgramEncoder(com.dat3m.dartagnan.encoding.ProgramEncoder) WmmEncoder(com.dat3m.dartagnan.encoding.WmmEncoder) WMMSolver(com.dat3m.dartagnan.solver.caat4wmm.WMMSolver) ArrayList(java.util.ArrayList) Result(com.dat3m.dartagnan.utils.Result) SymmetryEncoder(com.dat3m.dartagnan.encoding.SymmetryEncoder) Refiner(com.dat3m.dartagnan.solver.caat4wmm.Refiner) Program(com.dat3m.dartagnan.program.Program) AssertTrue(com.dat3m.dartagnan.asserts.AssertTrue) CoreLiteral(com.dat3m.dartagnan.solver.caat4wmm.coreReasoning.CoreLiteral) Model(org.sosy_lab.java_smt.api.Model) ExecutionModel(com.dat3m.dartagnan.verification.model.ExecutionModel) SolverException(org.sosy_lab.java_smt.api.SolverException) DNF(com.dat3m.dartagnan.utils.logic.DNF)

Example 2 with CoreLiteral

use of com.dat3m.dartagnan.solver.caat4wmm.coreReasoning.CoreLiteral in project Dat3M by hernanponcedeleon.

the class Refiner method refine.

// This method computes a refinement clause from a set of violations.
// Furthermore, it computes symmetric violations if symmetry learning is enabled.
public BooleanFormula refine(DNF<CoreLiteral> coreReasons, SolverContext context) {
    // TODO: A specialized algorithm that computes the orbit under permutation may be better,
    // since most violations involve only few threads and hence the orbit is far smaller than the full
    // set of permutations.
    BooleanFormulaManager bmgr = context.getFormulaManager().getBooleanFormulaManager();
    BooleanFormula refinement = bmgr.makeTrue();
    // For each symmetry permutation, we will create refinement clauses
    for (Function<Event, Event> perm : symmPermutations) {
        for (Conjunction<CoreLiteral> reason : coreReasons.getCubes()) {
            BooleanFormula permutedClause = reason.getLiterals().stream().map(lit -> bmgr.not(permuteAndConvert(lit, perm, context))).reduce(bmgr.makeFalse(), bmgr::or);
            refinement = bmgr.and(refinement, permutedClause);
        }
    }
    return refinement;
}
Also used : EquivalenceClass(com.dat3m.dartagnan.utils.equivalence.EquivalenceClass) ThreadSymmetry(com.dat3m.dartagnan.program.analysis.ThreadSymmetry) CoreLiteral(com.dat3m.dartagnan.solver.caat4wmm.coreReasoning.CoreLiteral) ExecLiteral(com.dat3m.dartagnan.solver.caat4wmm.coreReasoning.ExecLiteral) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) Set(java.util.Set) DNF(com.dat3m.dartagnan.utils.logic.DNF) Relation(com.dat3m.dartagnan.wmm.relation.Relation) Thread(com.dat3m.dartagnan.program.Thread) Function(java.util.function.Function) MemEvent(com.dat3m.dartagnan.program.event.core.MemEvent) RelLiteral(com.dat3m.dartagnan.solver.caat4wmm.coreReasoning.RelLiteral) ArrayList(java.util.ArrayList) BooleanFormulaManager(org.sosy_lab.java_smt.api.BooleanFormulaManager) AddressLiteral(com.dat3m.dartagnan.solver.caat4wmm.coreReasoning.AddressLiteral) List(java.util.List) Conjunction(com.dat3m.dartagnan.utils.logic.Conjunction) REFINEMENT_SYMMETRY_LEARNING(com.dat3m.dartagnan.GlobalSettings.REFINEMENT_SYMMETRY_LEARNING) SolverContext(org.sosy_lab.java_smt.api.SolverContext) Event(com.dat3m.dartagnan.program.event.core.Event) RefinementTask(com.dat3m.dartagnan.verification.RefinementTask) Comparator(java.util.Comparator) Utils.generalEqual(com.dat3m.dartagnan.expression.utils.Utils.generalEqual) BooleanFormulaManager(org.sosy_lab.java_smt.api.BooleanFormulaManager) MemEvent(com.dat3m.dartagnan.program.event.core.MemEvent) Event(com.dat3m.dartagnan.program.event.core.Event) CoreLiteral(com.dat3m.dartagnan.solver.caat4wmm.coreReasoning.CoreLiteral) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula)

Aggregations

CoreLiteral (com.dat3m.dartagnan.solver.caat4wmm.coreReasoning.CoreLiteral)2 DNF (com.dat3m.dartagnan.utils.logic.DNF)2 ArrayList (java.util.ArrayList)2 REFINEMENT_SYMMETRY_LEARNING (com.dat3m.dartagnan.GlobalSettings.REFINEMENT_SYMMETRY_LEARNING)1 AssertTrue (com.dat3m.dartagnan.asserts.AssertTrue)1 ProgramEncoder (com.dat3m.dartagnan.encoding.ProgramEncoder)1 PropertyEncoder (com.dat3m.dartagnan.encoding.PropertyEncoder)1 SymmetryEncoder (com.dat3m.dartagnan.encoding.SymmetryEncoder)1 WmmEncoder (com.dat3m.dartagnan.encoding.WmmEncoder)1 Utils.generalEqual (com.dat3m.dartagnan.expression.utils.Utils.generalEqual)1 Program (com.dat3m.dartagnan.program.Program)1 Thread (com.dat3m.dartagnan.program.Thread)1 ThreadSymmetry (com.dat3m.dartagnan.program.analysis.ThreadSymmetry)1 Event (com.dat3m.dartagnan.program.event.core.Event)1 MemEvent (com.dat3m.dartagnan.program.event.core.MemEvent)1 CAATSolver (com.dat3m.dartagnan.solver.caat.CAATSolver)1 Refiner (com.dat3m.dartagnan.solver.caat4wmm.Refiner)1 WMMSolver (com.dat3m.dartagnan.solver.caat4wmm.WMMSolver)1 AddressLiteral (com.dat3m.dartagnan.solver.caat4wmm.coreReasoning.AddressLiteral)1 ExecLiteral (com.dat3m.dartagnan.solver.caat4wmm.coreReasoning.ExecLiteral)1