Search in sources :

Example 1 with Kind

use of catdata.aql.Kind in project fql by CategoricalData.

the class AqlDisplay method report.

private JComponent report(Program<Exp<?>> prog, AqlEnv env, List<String> order, float c1, float c2, String pre) {
    DecimalFormat df = new DecimalFormat("#.#");
    df.setRoundingMode(RoundingMode.CEILING);
    List<String> l = new LinkedList<>();
    Object[][] rowData = new Object[env.defs.insts.size()][3];
    int i = 0;
    List<String> missing = new LinkedList<>();
    for (String k : order) {
        if (env.defs.insts.containsKey(k)) {
            Instance<?, ?, ?, ?, ?, ?, ?, ?, ?> I = (Instance<?, ?, ?, ?, ?, ?, ?, ?, ?>) env.get(Kind.INSTANCE, k);
            String s = k + "\t" + I.size() + "\t" + env.performance.get(k);
            l.add(s);
            rowData[i][0] = k;
            rowData[i][1] = I.size();
            rowData[i][2] = env.performance.get(k);
            i++;
        } else if (prog.exps.get(k).kind().equals(Kind.INSTANCE)) {
            missing.add(k);
        }
    }
    JPanel t = GuiUtil.makeTable(BorderFactory.createEmptyBorder(), "", rowData, "instance", "rows", "seconds");
    JPanel pan = new JPanel(new GridLayout(1, 1));
    pan.add(new JScrollPane(t));
    String tsv = "instance\trows\tseconds\n" + Util.sep(l, "\n");
    JTabbedPane jtb = new JTabbedPane();
    String text = pre;
    if (!missing.isEmpty()) {
        text += "\n\nInstances not computed: " + Util.sep(Util.alphabetical(missing), ", ");
    }
    text += "\n\nComputation wall-clock time: " + df.format(c1) + "s\nGUI building time: " + df.format(c2) + "s\n";
    Map<Kind, Float> perfs = new HashMap<>();
    for (Kind k : Kind.values()) {
        perfs.put(k, 0f);
    }
    for (String s : env.performance.keySet()) {
        Kind k = prog.exps.get(s).kind();
        perfs.put(k, perfs.get(k) + env.performance.get(s));
    }
    for (Kind k : Kind.values()) {
        if (perfs.get(k) < .05f) {
            continue;
        }
        text += "\n" + k + " computation total time: " + df.format(perfs.get(k)) + "s";
    }
    if (!prog.options.isEmpty()) {
        text += "\n\nGlobal options:\n";
        text += Util.sep(prog.options, " = ", "\n");
    }
    jtb.addTab("Text", new CodeTextPanel("", text));
    jtb.addTab("Performance", pan);
    jtb.addTab("TSV", new CodeTextPanel("", tsv));
    // jtb.addTab("Tree", viewTree(prog));
    return jtb;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) Instance(catdata.aql.Instance) HashMap(java.util.HashMap) DecimalFormat(java.text.DecimalFormat) JTabbedPane(javax.swing.JTabbedPane) LinkedList(java.util.LinkedList) Point(java.awt.Point) GridLayout(java.awt.GridLayout) CodeTextPanel(catdata.ide.CodeTextPanel) Kind(catdata.aql.Kind)

Example 2 with Kind

use of catdata.aql.Kind in project fql by CategoricalData.

the class AqlMultiDriver method init.

private void init() {
    if (last_env == null || !last_env.prog.options.equals(env.prog.options)) {
        todo.addAll(env.prog.order);
        return;
    }
    for (String n : env.prog.order) {
        if (/* (!last_env.defs.keySet().contains(n)) || */
        changed(n)) {
            todo.add(n);
        } else {
            Kind k = env.prog.exps.get(n).kind();
            env.defs.put(n, k, last_env.defs.get(n, k));
            env.performance.put(n, last_env.performance.get(n));
            completed.add(n);
        }
    }
}
Also used : Kind(catdata.aql.Kind)

Example 3 with Kind

use of catdata.aql.Kind 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)

Aggregations

Kind (catdata.aql.Kind)3 LineException (catdata.LineException)1 RuntimeInterruptedException (catdata.RuntimeInterruptedException)1 Instance (catdata.aql.Instance)1 CodeTextPanel (catdata.ide.CodeTextPanel)1 GridLayout (java.awt.GridLayout)1 Point (java.awt.Point)1 DecimalFormat (java.text.DecimalFormat)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 JPanel (javax.swing.JPanel)1 JScrollPane (javax.swing.JScrollPane)1 JTabbedPane (javax.swing.JTabbedPane)1