use of com.microsoft.z3.Z3Exception in project batfish by batfish.
the class NodFirstUnsatJob method call.
@Override
public NodFirstUnsatResult<KeyT, ResultT> call() {
long startTime = System.currentTimeMillis();
try (Context ctx = new Context()) {
ReachabilityProgram baseProgram = _query.synthesizeBaseProgram(_synthesizer);
ReachabilityProgram queryProgram = _query.getReachabilityProgram(_synthesizer.getInput());
NodProgram program = new NodProgram(ctx, baseProgram, queryProgram);
Fixedpoint fix = mkFixedpoint(program, false);
KeyT key = _query.getKey();
for (int queryNum = 0; queryNum < program.getQueries().size(); queryNum++) {
BoolExpr query = program.getQueries().get(queryNum);
Status status = fix.query(query);
switch(status) {
case SATISFIABLE:
break;
case UNKNOWN:
return new NodFirstUnsatResult<>(startTime, _logger.getHistory(), new BatfishException("Query satisfiability unknown"));
case UNSATISFIABLE:
return new NodFirstUnsatResult<>(key, queryNum, _query.getResultsByQueryIndex().get(queryNum), _logger.getHistory(), startTime);
default:
return new NodFirstUnsatResult<>(startTime, _logger.getHistory(), new BatfishException("invalid status"));
}
}
return new NodFirstUnsatResult<>(key, null, null, _logger.getHistory(), startTime);
} catch (Z3Exception e) {
return new NodFirstUnsatResult<>(startTime, _logger.getHistory(), new BatfishException("Error running NoD on concatenated data plane", e));
}
}
use of com.microsoft.z3.Z3Exception in project batfish by batfish.
the class NodSatJob method call.
@Override
public NodSatResult<KeyT> call() {
Map<KeyT, Boolean> results = new LinkedHashMap<>();
long startTime = System.currentTimeMillis();
try (Context ctx = new Context()) {
ReachabilityProgram baseProgram = _query.synthesizeBaseProgram(_synthesizer);
ReachabilityProgram queryProgram = _query.getReachabilityProgram(_synthesizer.getInput());
NodProgram program = new NodProgram(ctx, baseProgram, queryProgram);
Fixedpoint fix = mkFixedpoint(program, false);
for (int queryNum = 0; queryNum < program.getQueries().size(); queryNum++) {
BoolExpr query = program.getQueries().get(queryNum);
KeyT key = _query.getKeys().get(queryNum);
Status status = fix.query(query);
switch(status) {
case SATISFIABLE:
results.put(key, true);
break;
case UNKNOWN:
return new NodSatResult<>(startTime, _logger.getHistory(), new BatfishException("Query satisfiability unknown"));
case UNSATISFIABLE:
results.put(key, false);
break;
default:
return new NodSatResult<>(startTime, _logger.getHistory(), new BatfishException("invalid status"));
}
}
return new NodSatResult<>(results, _logger.getHistory(), startTime);
} catch (Z3Exception e) {
return new NodSatResult<>(startTime, _logger.getHistory(), new BatfishException("Error running NoD on concatenated data plane", e));
}
}
use of com.microsoft.z3.Z3Exception in project batfish by batfish.
the class AbstractNodJob method call.
@Override
public final NodJobResult call() {
long startTime = System.currentTimeMillis();
try (Context ctx = new Context()) {
SmtInput smtInput = computeSmtInput(startTime, ctx);
Map<OriginateVrf, Map<String, Long>> originateVrfConstraints = getOriginateVrfConstraints(ctx, smtInput);
Set<Flow> flows = getFlows(originateVrfConstraints);
return new NodJobResult(startTime, _logger.getHistory(), flows);
} catch (Z3Exception e) {
return new NodJobResult(startTime, _logger.getHistory(), new BatfishException("Error running NoD on concatenated data plane", e));
}
}
use of com.microsoft.z3.Z3Exception in project Dat3M by hernanponcedeleon.
the class Dartagnan method main.
public static void main(String[] args) throws Z3Exception, IOException {
List<String> MCMs = Arrays.asList("sc", "tso", "pso", "rmo", "alpha", "power", "arm");
Options options = new Options();
Option targetOpt = new Option("t", "target", true, "target MCM");
targetOpt.setRequired(true);
options.addOption(targetOpt);
Option inputOpt = new Option("i", "input", true, "input file path");
inputOpt.setRequired(true);
options.addOption(inputOpt);
options.addOption(Option.builder("unroll").hasArg().desc("Unrolling steps").build());
options.addOption(Option.builder("draw").hasArg().desc("If a buf is found, it outputs a graph \\path_to_file.dot").build());
options.addOption(Option.builder("rels").hasArgs().desc("Relations to be drawn in the graph").build());
CommandLineParser parserCmd = new DefaultParser();
HelpFormatter formatter = new HelpFormatter();
CommandLine cmd;
try {
cmd = parserCmd.parse(options, args);
} catch (ParseException e) {
System.out.println(e.getMessage());
formatter.printHelp("DARTAGNAN", options);
System.exit(1);
return;
}
String target = cmd.getOptionValue("target");
if (!MCMs.stream().anyMatch(mcms -> mcms.trim().equals(target))) {
System.out.println("Unrecognized target");
System.exit(0);
return;
}
String inputFilePath = cmd.getOptionValue("input");
if (!inputFilePath.endsWith("pts") && !inputFilePath.endsWith("litmus")) {
System.out.println("Unrecognized program format");
System.exit(0);
return;
}
File file = new File(inputFilePath);
String program = FileUtils.readFileToString(file, "UTF-8");
ANTLRInputStream input = new ANTLRInputStream(program);
Program p = new Program(inputFilePath);
if (inputFilePath.endsWith("litmus")) {
LitmusLexer lexer = new LitmusLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
LitmusParser parser = new LitmusParser(tokens);
p = parser.program(inputFilePath).p;
}
if (inputFilePath.endsWith("pts")) {
PorthosLexer lexer = new PorthosLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
PorthosParser parser = new PorthosParser(tokens);
p = parser.program(inputFilePath).p;
}
String[] rels = new String[100];
if (cmd.hasOption("rels")) {
rels = cmd.getOptionValues("rels");
}
int steps = 1;
if (cmd.hasOption("unroll")) {
steps = Integer.parseInt(cmd.getOptionValue("unroll"));
}
p.initialize(steps);
p.compile(target, false, true);
Context ctx = new Context();
Solver s = ctx.mkSolver();
s.add(p.encodeDF(ctx));
s.add(p.getAss().encode(ctx));
s.add(p.encodeCF(ctx));
s.add(p.encodeDF_RF(ctx));
s.add(Domain.encode(p, ctx));
s.add(p.encodeMM(ctx, target));
s.add(p.encodeConsistent(ctx, target));
ctx.setPrintMode(Z3_ast_print_mode.Z3_PRINT_SMTLIB_FULL);
if (s.check() == Status.SATISFIABLE) {
System.out.println("The state is reachable");
// System.out.println(" 0");
if (cmd.hasOption("draw")) {
String outputPath = cmd.getOptionValue("draw");
Utils.drawGraph(p, ctx, s.getModel(), outputPath, rels);
}
} else {
System.out.println("The state is not reachable");
// System.out.println(" 1");
}
return;
}
use of com.microsoft.z3.Z3Exception in project Dat3M by hernanponcedeleon.
the class ARM method encode.
public static BoolExpr encode(Program program, Context ctx) throws Z3Exception {
Set<Event> events = program.getEvents().stream().filter(e -> e instanceof MemEvent).collect(Collectors.toSet());
Set<Event> eventsL = program.getEvents().stream().filter(e -> e instanceof MemEvent || e instanceof Local).collect(Collectors.toSet());
BoolExpr enc = satUnion("co", "fr", events, ctx);
enc = ctx.mkAnd(enc, satUnion("com", "(co+fr)", "rf", events, ctx));
enc = ctx.mkAnd(enc, satUnion("poloc", "com", events, ctx));
enc = ctx.mkAnd(enc, satTransFixPoint("idd", eventsL, ctx));
enc = ctx.mkAnd(enc, satIntersection("data", "idd^+", "RW", events, ctx));
enc = ctx.mkAnd(enc, satEmpty("addr", events, ctx));
enc = ctx.mkAnd(enc, satUnion("dp", "addr", "data", events, ctx));
enc = ctx.mkAnd(enc, satComp("fre", "rfe", events, ctx));
enc = ctx.mkAnd(enc, satComp("coe", "rfe", events, ctx));
enc = ctx.mkAnd(enc, satIntersection("rdw", "poloc", "(fre;rfe)", events, ctx));
enc = ctx.mkAnd(enc, satIntersection("detour", "poloc", "(coe;rfe)", events, ctx));
// Base case for program order
enc = ctx.mkAnd(enc, satUnion("dp", "rdw", events, ctx));
enc = ctx.mkAnd(enc, satUnion("ii0", "(dp+rdw)", "rfi", events, ctx));
enc = ctx.mkAnd(enc, satEmpty("ic0", events, ctx));
enc = ctx.mkAnd(enc, satUnion("ci0", "ctrlisb", "detour", events, ctx));
enc = ctx.mkAnd(enc, satUnion("dp", "ctrl", events, ctx));
enc = ctx.mkAnd(enc, satComp("addr", "po", events, ctx));
enc = ctx.mkAnd(enc, satARMPPO(events, ctx));
enc = ctx.mkAnd(enc, satUnion("cc0", "(dp+ctrl)", "(addr;po)", events, ctx));
enc = ctx.mkAnd(enc, satIntersection("RR", "ii", events, ctx));
enc = ctx.mkAnd(enc, satIntersection("RW", "ic", events, ctx));
enc = ctx.mkAnd(enc, satUnion("po-arm", "(RR&ii)", "(RW&ic)", events, ctx));
// Happens before
enc = ctx.mkAnd(enc, satUnion("po-arm", "rfe", events, ctx));
enc = ctx.mkAnd(enc, satUnion("hb-arm", "(po-arm+rfe)", "ish", events, ctx));
// Prop-base
enc = ctx.mkAnd(enc, satComp("rfe", "ish", events, ctx));
enc = ctx.mkAnd(enc, satUnion("ish", "(rfe;ish)", events, ctx));
enc = ctx.mkAnd(enc, satTransRef("hb-arm", events, ctx));
enc = ctx.mkAnd(enc, satComp("prop-base", "(ish+(rfe;ish))", "(hb-arm)*", events, ctx));
// Propagation for ARM
enc = ctx.mkAnd(enc, satTransRef("com", events, ctx));
enc = ctx.mkAnd(enc, satTransRef("prop-base", events, ctx));
enc = ctx.mkAnd(enc, satComp("(com)*", "(prop-base)*", events, ctx));
enc = ctx.mkAnd(enc, satComp("((com)*;(prop-base)*)", "ish", events, ctx));
enc = ctx.mkAnd(enc, satComp("(((com)*;(prop-base)*);ish)", "(hb-arm)*", events, ctx));
enc = ctx.mkAnd(enc, satIntersection("WW", "prop-base", events, ctx));
enc = ctx.mkAnd(enc, satUnion("prop", "(WW&prop-base)", "((((com)*;(prop-base)*);ish);(hb-arm)*)", events, ctx));
enc = ctx.mkAnd(enc, satComp("fre", "prop", events, ctx));
enc = ctx.mkAnd(enc, satComp("(fre;prop)", "(hb-arm)*", events, ctx));
enc = ctx.mkAnd(enc, satUnion("co", "prop", events, ctx));
return enc;
}
Aggregations