Read Infer Predict Layer: module venture.ripl.ripl

The Read, Infer, Predict Layer.

The RIPL is the primary interface to using Venture as a Python library. One object of the Ripl class represents a distinct Venture session and offers a programmatic interface to the underlying Venture Stochastic Inference Virtual Machine (SIVM). The remainder of this document assumes a basic familiarity with the Venture language and programming model.

The methods of Ripl generally correspond to Venture instructions. Any necessary expressions can be passed in either as strings in concrete Venture syntax or as Python objects in abstract Venture syntax, or a mixture of both. Providing pre-parsed instructions is more efficient (Venture’s under-optimized parser currently imposes significant overhead), but strings in concrete syntax are likely to be more readable.

Typical usage begins by using one of the factory functions in the venture.shortcuts module:

import venture.shortcuts as s
r = s.make_ripl()
# r is a fresh Ripl
r.assume(...)
r.observe(...)
r.infer(...)
class venture.ripl.ripl.Ripl(sivm, parsers)

The Read, Infer, Predict Layer of one running Venture instance.

addr2Source(addr)

Takes an address and gives the corresponding (unparsed) source code and expression index.

assume(name, expression, label=None, type=False)

Declare a Venture variable and initialize it by evaluating the given expression. Return its value.

The label argument, if supplied, can later be passed as an argument to report, forget, or freeze to refer to this assume directive.

The type argument, if supplied and given a true value, causes the value to be returned as a dict annotating its Venture type.

backend()

Return the name of backend powering this Ripl. Either "lite" or "puma".

bind_callback(name, callback)
bind_foreign_inference_sp(name, sp)
bind_foreign_sp(name, sp)
bind_methods_as_callbacks(obj, prefix='')

Bind every public method of the given object as a callback of the same name.

bulk_observe(exp, items, label=None)

Observe many evaluations of an expression.

Syntax: ripl.bulk_observe(“<expr>”, <iterable>)

Semantics: Operationally equivalent to:

for x in iterable:
  ripl.observe("<expr>", x)

but appreciably faster. See also open considerations and details of the semantics in observe_dataset.

character_index_to_expression_index(directive_id, character_index)
clear()
configure(options=None)
continuous_inference_status()
defaultInferProgram(program)
define(name, expression, type=False)
disable_error_annotation()
draw_subproblem(scaffold_dict, type=False)
enable_error_annotation()
evaluate(program, type=False)
execute_instruction(instruction=None)
execute_instructions(instructions=None)
execute_parsed_program(instructions, _positions)
execute_program(program_string)
execute_program_from_file(filename)
expression_index_to_text_index(directive_id, expression_index)
force(expression, value)
forget(label_or_did, type=False)
freeze(label_or_did, type=False)
get_current_exception()
get_directive(label_or_did)
get_global_logscore()
get_inference_timeout()
get_mode()
get_seed()
get_state()
get_text(directive_id)
humanReadable(exp=None, did=None, index=None, **kwargs)

Take a parsed expression and index and turn it into unparsed form with text indeces.

infer(params=None, type=False)
list_available_modes()
list_directives(type=False, include_prelude=False, instructions=[])
load(fname)
load_plugin(name, *args, **kwargs)
load_prelude()

Load the library of Venture helper functions

observe(expression, value, label=None, type=False)
observe_dataset(proc_expression, iterable, label=None)

Observe a general dataset.

Syntax: ripl.observe_dataset(“<expr>”, <iterable>)

  • The <expr> must evaluate to a (presumably stochastic) Venture procedure. We expect in typical usage expr would just look up a recent assume.
  • The <iterable> is a Python iterable each of whose elements must be a nonempty list of valid Venture values.
  • There is no Venture syntax for this; it is accessible only when using Venture as a library.

Semantics:

  • As to its effect on the distribution over traces, this is equivalent to looping over the contents of the given iterable, calling ripl.observe on each element as ripl.observe("(<expr> *item[:-1])", item[-1]). In other words, the first elements of each item of the iterable give the arguments to the procedure given by <expr>, and the last element gives the value to observe.
  • The ripl method returns a list of directive ids, which correspond to the individual observes thus generated.

Open issues:

  • If the <expr> is itself stochastic, it is unspecified whether we notionally evaluate it once per bulk_observe or once per data item.
  • This is not the same as directly observing sufficient statistics only.
  • It is currently not possible to forget the whole bulk_observe at once.
  • Currently, list_directives will not respect the nesting structure of observations implied by bulk_observe. How can we improve this? Do we represent the bulk_observe as one directive? If so, we can hardly return a useful representation of the iterable representing the data set. If not, we will hardly win anything because list_directives will generate all those silly per-datapoint observes (every time it’s called!)
parse_program(program_string)
predict(expression, label=None, type=False)
print_directives(*instructions, **kwargs)
profile_data()
profiler_address_to_source_code_location(address)
profiler_clear()
profiler_configure(options=None)
profiler_disable()
profiler_enable()
profiler_get_acceptance_rate(address)
profiler_get_proposal_time(address)
profiler_list_random_choices()
profiler_make_random_choice()
pyeval(code)
pyexec(code)
register_foreign_sp(name, sp)
reinit_inference_problem(num_particles=None)
report(label_or_did, type=False)
rollback()
sample(expression, type=False)
sample_all(expression, type=False)
save(fname)
set_inference_timeout(inference_timeout)
set_mode(mode)
set_seed(seed)
split_program(program_string)
start_continuous_inference(program=None)
stop_continuous_inference()
venture.ripl.ripl.load_library(name)

Previous topic

Entry Point: package venture.shortcuts

Next topic

Programmatic values and expressions: module venture.value.dicts

This Page