]> hydra-www.ietfng.org Git - dyna2/commitdiff
too lazy.
authorTim Vieira <tim.f.vieira@gmail.com>
Wed, 19 Jun 2013 03:05:12 +0000 (23:05 -0400)
committerTim Vieira <tim.f.vieira@gmail.com>
Wed, 19 Jun 2013 03:05:12 +0000 (23:05 -0400)
src/Dyna/Backend/Python/interpreter.py
src/Dyna/Backend/Python/repl.py
src/Dyna/Backend/Python/utils.py
test/repl/aggregator-conflict.expect

index 47e8b048934bc60298964737bc124daa780a0e22..061ff758efcbffe86035c3e15969954a30de776f 100644 (file)
@@ -7,8 +7,6 @@ TODO
  - More info in crash handler. (stack trace, repl transcript, cmd-line args,
    version control info, and dyna source is enough)
 
- - call pre/post-processors from repl.
-
  - vbench: a script which tracks performace over time (= git commits).
 
  - profiler workflow
@@ -27,15 +25,46 @@ TODO
    handlers, and indices (as Jason points out indices are just memoized
    queries).
 
- - magic templates transform for backward chaining, for example:
-
-   :- sigmoid(X) := needs(X), 1 / (1 + exp(-X)).
-   :- needs(0.5).
-
  - hook for python imports? or maybe an arbirary preamble/epilogue.
 
    :- python: from numpy import exp, sqrt, log
 
+ - Subscriptions:
+
+   - TODO: users are automatically be subscribed to errors.
+
+   - everything
+   - functor
+   - ignore variable
+
+   - output formats: vquery and query
+   - show diffs
+
+   Maybe subscription to diff is a different beast, only available as a
+   procedural world.
+
+ - New syntax for doing repl stuff (@nwf): load, subscribe, post-process
+
+   - sheebang
+
+ - Errors:
+
+   - Should errors be maintained by dyna? I guess that's an (implicit?) program
+     transform where all items in a rule have a side conditions that they are
+     not in an error state.
+
+ - crash handler
+
+   - where to errors go?
+
+     - @nwf suggests temporary measure for LSA students: time-stamped file
+       sitting in the users home directory,
+       e.g. ~/.dyna/crash/2013-06-19.crash.tar.gz
+
+ - Hide all *.plan.py files
+
+ - multi-line input in REPL. Consider using a fancier library such as cmd2 or
+   ipython's.
 
 BUGS
 ====
@@ -63,8 +92,8 @@ FASTER
  - teach planner to prefer not to use the value column, because it's not
    indexed.
 
- - Collect all query modes use by the planner. Consider indexing value column if
-   plans need it.
+ - Collect all query modes used by the planner. Consider indexing value column
+   if plans need it.
 
  - dynac should provide routines for building terms. We can hack something
    together with anf output, but this will be prety kludgy and inefficient.
@@ -142,8 +171,7 @@ NOTES
 
     - numeric approximations, stream folding (fails to get null)
 
-    - delete the hyperedge: not sure this is perfect because hyperedges aren't
-      named with numeric values of variables.
+    - delete/add the hyperedge explicitly
 
 
 JUST FOR FUN
@@ -155,14 +183,6 @@ JUST FOR FUN
  - overload everything so that values maintain provenance and we can inspect the
    entire fine-grained circuit.
 
- - play around with cool python modules:
-
-   - uncertainties (error propagation and gradients), look
-
-   - values with units (i.e dimensional analysis).
-
-   - sympy?
-
 """
 
 from __future__ import division
@@ -173,7 +193,6 @@ from time import time
 
 import load, post
 
-
 from chart import Chart, Term, _repr
 from defn import aggregator
 from utils import ip, red, green, blue, magenta, yellow, parse_attrs, \
@@ -533,8 +552,8 @@ class Interpreter(object):
             # TODO: how do I make this transactional? what if the user hits ^C
             # in the middle of the following blocK?
             #
-            #   - maybe transaction isn't want I mean. Maybe all I want (for now
-            #     is to avoid ^C.
+            #  - maybe transaction isn't want I mean. Maybe all I want (for now
+            #    is to avoid ^C.
 
             # add new updaters
             for fn, r, h in env.updaters:
@@ -593,15 +612,15 @@ def peel(fn, item):
     assert item.fn == fn
     return item.args
 
-
+from path import path
 def main():
     parser = argparse.ArgumentParser(description="The dyna interpreter!")
-    parser.add_argument('source', nargs='?',
+    parser.add_argument('source', nargs='?', type=path,
                         help='Path to Dyna source file (or plan if --plan=true).')
-    parser.add_argument('--plan', action='store_true',
-                        help='`source` specifies output of the compiler instead of dyna source code.')
     parser.add_argument('-i', dest='interactive', action='store_true',
                         help='Fire-up REPL after runing solver..')
+    parser.add_argument('--plan', action='store_true',
+                        help='`source` specifies output of the compiler instead of dyna source code.')
     parser.add_argument('-o', '--output', dest='output',
                         type=argparse.FileType('wb'),
                         help='Output chart.')
@@ -627,7 +646,7 @@ def main():
         if args.plan:
             plan = args.source
         else:
-            plan = "%s.plan.py" % args.source
+            plan = dotdynadir / 'tmp' / args.source.read_hexhash('sha1') + '.plan.py'
             dynac(args.source, plan)
 
         if args.profile:
index 225710e5d61ecfe4a93513b71ba510dc4bb5d832..72fb9c8cd253b736c7299168d1a6efd6931e1c77 100644 (file)
@@ -108,7 +108,7 @@ class REPL(cmd.Cmd, object):
             print type(e).__name__ + ':'
             print e
             print '> new rule(s) were not added to program.'
-
+            print
         else:
             self._changed(changed)
 
@@ -127,14 +127,32 @@ class REPL(cmd.Cmd, object):
         except KeyboardInterrupt:
             # Catch Control-C and resume REPL.
             print '^C'
+            readline.write_history_file(self.hist)
             self.cmdloop()
         finally:
             readline.write_history_file(self.hist)
 
+    def do_subscribe(self, line):
+        if line.endswith('.'):
+            print "Queries don't end with a dot."
+            return
+        # subscriptions are maintained via forward chaining.
+        query = 'subscribed(%s, %s) dict= %s.' % (self.lineno, _repr(line), line)
+        self.default(query)
+
+    def do_subscriptions(self, _):
+        for (_, [_, q], answers) in self.interp.chart['subscribed/2'][:,:,:]:
+            print
+            print q
+            for [value, vs] in answers:
+                print '  %s when {%s}' \
+                    % (value, ', '.join('%s=%s' % (k, _repr(v)) for k,v in vs.items()))
+        print
+
     def do_load(self, line):
         try:
             load.run(self.interp, line)
-            self.interp.dump_charts()
+#            self.interp.dump_charts()
         except:
             show_traceback()
             readline.write_history_file(self.hist)
index cc295adeaa5468c5a576b2c9bc8cfd5a4bad0dd2..c678b2dbce1fc769ac344c8fa91dc213617bb893 100644 (file)
@@ -14,7 +14,6 @@ black, red, green, yellow, blue, magenta, cyan, white = \
     map('\033[3%sm%%s\033[0m'.__mod__, range(8))
 
 
-
 def dynac(f, out):
     """
     Run compiler on file, ``f``, write results to ``out``. Raises
index 34bdc95b0c8e80eed97eceab3b45d7f0b25aefca..143f9ffc5661630e19732a4f91064f6178b2cbb5 100644 (file)
@@ -7,4 +7,5 @@ FATAL: Encountered error in input program:
  uses '|=' for a/0 but I had been lead to expect '+='.
 
 > new rule(s) were not added to program.
+
 :- exit