probcomp / Venturecxx

Primary implementation of the Venture probabilistic programming system
http://probcomp.csail.mit.edu/venture/
GNU General Public License v3.0
28 stars 6 forks source link

Error messages for subproblem selection failure #643

Open marcoct opened 8 years ago

marcoct commented 8 years ago

If you try to select random choices that don't exist, there is a key error, but the context in which this error occurred is not made clear by the current error messages:

assume x = mem((i) -> { normal(0, 1) #x:i });
observe x(integer(1)) = 1.123;
define i = integer(2);
infer mh(minimal_subproblem(/?x==i));

Error message:

(venturedp_env) dhcp-18-189-8-106:dpm-dha marco$ venture -f test.vnts 
Tracing models with the Lite backend
Initial random seed is 1680290670 (to reproduce run, use -s 1680290670)
Warning: skipping annotating did 23, assumed to be from the inference prelude
Traceback (most recent call last):
  File "/Users/marco/venturedp_env/bin/venture", line 196, in <module>
    lite(args)
  File "/Users/marco/venturedp_env/bin/venture", line 57, in lite
    local_ripl(args, v.Lite())
  File "/Users/marco/venturedp_env/bin/venture", line 61, in local_ripl
    (interactive, r, files, plugins) = build()
  File "/Users/marco/venturedp_env/bin/venture", line 94, in build
    r.execute_program_from_file(f)
  File "/Users/marco/venturedp_env/lib/python2.7/site-packages/venture/ripl/ripl.py", line 400, in execute_program_from_file
    self.execute_program(f.read())
  File "/Users/marco/venturedp_env/lib/python2.7/site-packages/venture/ripl/ripl.py", line 376, in execute_program
    res = self.execute_parsed_program(self.parse_program(program_string))
  File "/Users/marco/venturedp_env/lib/python2.7/site-packages/venture/ripl/ripl.py", line 388, in execute_parsed_program
    vals.append(self.execute_instruction(instruction))
  File "/Users/marco/venturedp_env/lib/python2.7/site-packages/venture/ripl/ripl.py", line 274, in execute_instruction
    self._raise_annotated(e, instruction)
  File "/Users/marco/venturedp_env/lib/python2.7/site-packages/venture/ripl/ripl.py", line 270, in execute_instruction
    stringable_instruction)
  File "/Users/marco/venturedp_env/lib/python2.7/site-packages/venture/ripl/ripl.py", line 285, in _execute_parsed_instruction
    ans = self.sivm.execute_instruction(parsed_instruction)
  File "/Users/marco/venturedp_env/lib/python2.7/site-packages/venture/sivm/venture_sivm.py", line 94, in execute_instruction
    response = self._call_core_sivm_instruction(instruction)
  File "/Users/marco/venturedp_env/lib/python2.7/site-packages/venture/sivm/venture_sivm.py", line 193, in _call_core_sivm_instruction
    response = self.core_sivm.execute_instruction(desugared_instruction)
  File "/Users/marco/venturedp_env/lib/python2.7/site-packages/venture/sivm/core_sivm.py", line 63, in execute_instruction
    return f(instruction)
  File "/Users/marco/venturedp_env/lib/python2.7/site-packages/venture/sivm/core_sivm.py", line 202, in _do_infer
    (did, val) = self.engine.infer(e)
  File "/Users/marco/venturedp_env/lib/python2.7/site-packages/venture/engine/engine.py", line 294, in infer
    return self.raw_evaluate([v.sym("run"), program])
  File "/Users/marco/venturedp_env/lib/python2.7/site-packages/venture/engine/engine.py", line 217, in raw_evaluate
    did = self._do_raw_evaluate(program)
  File "/Users/marco/venturedp_env/lib/python2.7/site-packages/venture/engine/engine.py", line 225, in _do_raw_evaluate
    self.infer_trace.eval(did, program)
  File "/Users/marco/venturedp_env/lib/python2.7/site-packages/venture/untraced/trace.py", line 61, in eval
    val = evaluator.eval(addr.directive_address(id), py_exp, self.env, rng)
  File "/Users/marco/venturedp_env/lib/python2.7/site-packages/venture/untraced/evaluator.py", line 57, in eval
    val = apply(address, nodes, env, rng)
  File "/Users/marco/venturedp_env/lib/python2.7/site-packages/venture/untraced/evaluator.py", line 81, in apply
    req_nodes = [evalRequest(req_args, spr, r, rng) for r in requests.esrs]
  File "/Users/marco/venturedp_env/lib/python2.7/site-packages/venture/untraced/evaluator.py", line 130, in evalRequest
    ans = node.Node(new_addr, eval(new_addr, r.exp, r.env, rng))
  File "/Users/marco/venturedp_env/lib/python2.7/site-packages/venture/untraced/evaluator.py", line 53, in eval
    v = eval(addr2,subexp,env,rng)
  File "/Users/marco/venturedp_env/lib/python2.7/site-packages/venture/untraced/evaluator.py", line 57, in eval
    val = apply(address, nodes, env, rng)
  File "/Users/marco/venturedp_env/lib/python2.7/site-packages/venture/untraced/evaluator.py", line 83, in apply
    return applyPSP(spr.sp.outputPSP, OutputArgs(address, nodes[1:], env, rng.randint(1, 2**31 - 1), req_nodes, requests))
  File "/Users/marco/venturedp_env/lib/python2.7/site-packages/venture/untraced/evaluator.py", line 120, in applyPSP
    val = psp.simulate(args)
  File "/Users/marco/venturedp_env/lib/python2.7/site-packages/venture/lite/psp.py", line 492, in simulate
    self.psp.simulate(self.f_type.unwrap_args(args)))
  File "/Users/marco/venturedp_env/lib/python2.7/site-packages/venture/lite/inference_sps.py", line 84, in simulate
    ans = engine.primitive_infer(self.exp)
  File "/Users/marco/venturedp_env/lib/python2.7/site-packages/venture/engine/inference.py", line 125, in primitive_infer
    def primitive_infer(self, exp): return self.engine.primitive_infer(exp)
  File "/Users/marco/venturedp_env/lib/python2.7/site-packages/venture/engine/engine.py", line 326, in primitive_infer
    def primitive_infer(self, exp): return self.model.primitive_infer(exp)
  File "/Users/marco/venturedp_env/lib/python2.7/site-packages/venture/engine/trace_set.py", line 340, in primitive_infer
    return self.traces.map('primitive_infer', exp)
  File "/Users/marco/venturedp_env/lib/python2.7/site-packages/venture/multiprocess.py", line 197, in map
    for pipe in self.pipes: pipe.send((cmd, args, kwargs, None))
  File "/Users/marco/venturedp_env/lib/python2.7/site-packages/venture/multiprocess.py", line 565, in send
    self.other.emplace(obj)
  File "/Users/marco/venturedp_env/lib/python2.7/site-packages/venture/multiprocess.py", line 570, in emplace
    cb()
  File "/Users/marco/venturedp_env/lib/python2.7/site-packages/venture/multiprocess.py", line 378, in poll
    res = [getattr(o, cmd)(*args, **kwargs) for o in self.objs]
  File "/Users/marco/venturedp_env/lib/python2.7/site-packages/venture/multiprocess.py", line 351, in <lambda>
    return lambda *args, **kwargs: Success(getattr(self.obj, attrname)(*args, **kwargs))
  File "/Users/marco/venturedp_env/lib/python2.7/site-packages/venture/lite/trace.py", line 507, in primitive_infer
    return infer.primitive_infer(self, exp)
  File "/Users/marco/venturedp_env/lib/python2.7/site-packages/venture/lite/infer/dispatch.py", line 135, in primitive_infer
    return transloop(trace, transitions, scaffolder_loop(scaffolders, doit))
  File "/Users/marco/venturedp_env/lib/python2.7/site-packages/venture/lite/infer/dispatch.py", line 111, in transloop
    ct += operate()
  File "/Users/marco/venturedp_env/lib/python2.7/site-packages/venture/lite/infer/dispatch.py", line 125, in doit
    ct += operate(scaffolder)
  File "/Users/marco/venturedp_env/lib/python2.7/site-packages/venture/lite/infer/dispatch.py", line 134, in doit
    return mixMH(trace, scaffolder, MHOperator())
  File "/Users/marco/venturedp_env/lib/python2.7/site-packages/venture/lite/infer/mh.py", line 60, in mixMH
    index = indexer.sampleIndex(trace)
  File "/Users/marco/venturedp_env/lib/python2.7/site-packages/venture/untraced/trace_search.py", line 90, in sampleIndex
    (scaffold, _weight) = interpret(self.prog, trace)
  File "/Users/marco/venturedp_env/lib/python2.7/site-packages/venture/untraced/trace_search.py", line 158, in interpret
    (nodes, wt) = interpret(prog.source, trace)
  File "/Users/marco/venturedp_env/lib/python2.7/site-packages/venture/untraced/trace_search.py", line 139, in interpret
    (thing2, wt2) = interpret(Extent(prog.edge.datum), trace)
  File "/Users/marco/venturedp_env/lib/python2.7/site-packages/venture/untraced/trace_search.py", line 147, in interpret
    (thing, wt) = interpret(prog.source, trace)
  File "/Users/marco/venturedp_env/lib/python2.7/site-packages/venture/untraced/trace_search.py", line 129, in interpret
    return (d[prog.key], w)
  File "/Users/marco/venturedp_env/lib/python2.7/site-packages/venture/lite/smap.py", line 26, in __getitem__
    return self.a[self.d[k]][1]
venture.exception.VentureException: *** evaluation: VentureInteger(2)
(run (mh (minimal_subproblem (by_walk (by_top) (by_tag_value (quasiquote x) i)))))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Caused by
VentureInteger(2)

I have run into this sort of issue frequently when using subproblem selection, and it often takes a long time to track down.