Search in sources :

Example 1 with RuntimeInterruptedException

use of catdata.RuntimeInterruptedException in project fql by CategoricalData.

the class ProgramProver method step.

private KBExp<C, V> step(KBExp<C, V> ee) {
    if (Thread.currentThread().isInterrupted()) {
        throw new RuntimeInterruptedException(new InterruptedException());
    }
    if (ee.isVar) {
        return step1(ee);
    } else {
        KBApp<C, V> e = ee.getApp();
        List<KBExp<C, V>> args0 = new LinkedList<>();
        for (KBExp<C, V> arg : e.args) {
            // needs to be step for correctness
            args0.add(step(arg));
        }
        KBApp<C, V> ret = new KBApp<>(e.f, args0);
        return step1(ret);
    }
}
Also used : KBApp(catdata.provers.KBExp.KBApp) RuntimeInterruptedException(catdata.RuntimeInterruptedException) RuntimeInterruptedException(catdata.RuntimeInterruptedException) LinkedList(java.util.LinkedList)

Example 2 with RuntimeInterruptedException

use of catdata.RuntimeInterruptedException in project fql by CategoricalData.

the class AqlProver method create.

// these provers say that x = y when that is true when all java symbols are treated as free,
// or if x and y reduce to the same java normal form.  as such, the provers won't actually
// decide, for example, that e = 2 -> e + 1 = 3.  So the DP is not necessarily a decision
// procedure for the input theory + java - or even any theory at all, because you may not have
// x = y and y = z -> x = z when java is involved.
public static <Ty, En, Sym, Fk, Att, Gen, Sk> DP<Ty, En, Sym, Fk, Att, Gen, Sk> create(AqlOptions ops, Collage<Ty, En, Sym, Fk, Att, Gen, Sk> col1, AqlJs<Ty, Sym> js) {
    ProverName name = (ProverName) ops.getOrDefault(AqlOption.prover);
    long timeout = (Long) ops.getOrDefault(AqlOption.timeout);
    if (name.equals(ProverName.auto)) {
        name = auto(ops, col1.simplify().first);
    }
    try {
        switch(name) {
            case auto:
                throw new RuntimeException("Anomaly: please report");
            case fail:
                return new KBtoDP<>(js, x -> {
                    throw new RuntimeException();
                }, new FailProver<>());
            case free:
                return new KBtoDP<>(js, col1.simplify().second, new FreeProver<>(col1.simplify().first.toKB()));
            case congruence:
                return new KBtoDP<>(js, col1.simplify().second, new CongruenceProver<>(col1.simplify().first.toKB()));
            case program:
                boolean check = !(Boolean) ops.getOrDefault(AqlOption.dont_verify_is_appropriate_for_prover_unsafe);
                boolean allowNonTerm = (Boolean) ops.getOrDefault(AqlOption.program_allow_nontermination_unsafe);
                try {
                    if (!allowNonTerm) {
                        col1 = reorient(col1);
                    }
                } catch (Exception ex) {
                    throw new RuntimeException(ex.getMessage() + "\n\nPossible solution: add options program_allow_nontermination_unsafe=true, or prover=completion");
                }
                // use
                return new KBtoDP<>(js, col1.simplify().second, new ProgramProver<>(check, Var.it, col1.simplify().first.toKB()));
            case completion:
                return new KBtoDP<>(js, col1.simplify().second, new CompletionProver<>(col1.toKB().syms.keySet(), ops, col1.simplify().first));
            case monoidal:
                // use																																					// simplified
                return new MonoidalFreeDP<>(js, col1.simplify().second, col1.simplify().first);
            case maedmax:
                String exePath = (String) ops.getOrDefault(AqlOption.maedmax_path);
                Boolean b = (Boolean) ops.getOrDefault(AqlOption.maedmax_allow_empty_sorts_unsafe);
                // use
                return new KBtoDP<>(js, col1.simplify().second, new MaedmaxProver<>(exePath, col1.simplify().first.toKB(), b, timeout));
            default:
                throw new RuntimeException("Anomaly: please report");
        }
    } catch (InterruptedException exn) {
        throw new RuntimeInterruptedException(exn);
    }
}
Also used : RuntimeInterruptedException(catdata.RuntimeInterruptedException) RuntimeInterruptedException(catdata.RuntimeInterruptedException) RuntimeInterruptedException(catdata.RuntimeInterruptedException)

Example 3 with RuntimeInterruptedException

use of catdata.RuntimeInterruptedException in project fql by CategoricalData.

the class AqlMultiDriver method call.

@Override
public Unit call() {
    String k2 = "";
    String n = "";
    try {
        while (true) {
            n = null;
            synchronized (this) {
                if (/*stop == true ||*/
                todo.isEmpty() || Thread.currentThread().isInterrupted()) {
                    break;
                }
                n = nextAvailable();
                if (n == null) {
                    update();
                    // just in case
                    wait(5000);
                    continue;
                }
                processing.add(n);
                todo.remove(n);
                update();
            }
            Exp<?> exp = env.prog.exps.get(n);
            Kind k = exp.kind();
            k2 = k.toString();
            long time1 = System.currentTimeMillis();
            Object val = Util.timeout(() -> exp.eval(env), (Long) exp.getOrDefault(env, AqlOption.timeout) * 1000);
            if (val == null) {
                throw new RuntimeException("anomaly, please report: null result on " + exp);
            } else if (k.equals(Kind.PRAGMA)) {
                ((Pragma) val).execute();
            }
            long time2 = System.currentTimeMillis();
            synchronized (this) {
                env.defs.put(n, k, val);
                env.performance.put(n, (time2 - time1) / (1000f));
                processing.remove(n);
                completed.add(n);
                update();
                notifyAll();
            }
        }
    } catch (InterruptedException exp) {
        exn.add(new RuntimeInterruptedException(exp));
    } catch (RuntimeInterruptedException exp) {
        exn.add(exp);
    } catch (Exception e) {
        e.printStackTrace();
        synchronized (this) {
            if (e instanceof LocException) {
                exn.add((LocException) e);
            } else {
                exn.add(new LineException(e.getMessage(), n, k2));
            }
            notifyAll();
            interruptAll();
        }
    }
    update();
    return notifyOfDeath();
}
Also used : Kind(catdata.aql.Kind) RuntimeInterruptedException(catdata.RuntimeInterruptedException) LineException(catdata.LineException) RuntimeInterruptedException(catdata.RuntimeInterruptedException) RuntimeInterruptedException(catdata.RuntimeInterruptedException) LineException(catdata.LineException)

Example 4 with RuntimeInterruptedException

use of catdata.RuntimeInterruptedException in project fql by CategoricalData.

the class CongruenceProver method merge1.

private static <C, V> void merge1(Map<KBExp<C, V>, Set<KBExp<C, V>>> pred, UnionFind<KBExp<C, V>> uf, KBExp<C, V> u, KBExp<C, V> v) {
    if (Thread.currentThread().isInterrupted()) {
        try {
            throw new InterruptedException();
        } catch (InterruptedException ex) {
            throw new RuntimeInterruptedException(ex);
        }
    }
    if (uf.connected(u, v)) {
        return;
    }
    Set<KBExp<C, V>> pu = new HashSet<>();
    for (KBExp<C, V> exp : pred.keySet()) {
        if (uf.connected(u, exp)) {
            pu.addAll(pred.get(exp));
        }
    }
    Set<KBExp<C, V>> pv = new HashSet<>();
    for (KBExp<C, V> exp : pred.keySet()) {
        if (uf.connected(v, exp)) {
            pv.addAll(pred.get(exp));
        }
    }
    uf.union(u, v);
    for (KBExp<C, V> x : pu) {
        for (KBExp<C, V> y : pv) {
            if (!uf.connected(x, y) && congruent(uf, x, y)) {
                merge1(pred, uf, x, y);
            }
        }
    }
}
Also used : RuntimeInterruptedException(catdata.RuntimeInterruptedException) RuntimeInterruptedException(catdata.RuntimeInterruptedException) HashSet(java.util.HashSet)

Aggregations

RuntimeInterruptedException (catdata.RuntimeInterruptedException)4 LineException (catdata.LineException)1 Kind (catdata.aql.Kind)1 KBApp (catdata.provers.KBExp.KBApp)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1