def plot_to_file_fun(basenames, spec, dataset): filenames = t.ExpressionType().asPython(basenames) spec = t.ExpressionType().asPython(spec) if isinstance(dataset, Dataset): PlotSpec(spec).plot(dataset.asPandas(), dataset.ind_names, _format_filenames(filenames, spec)) else: PlotSpec(spec).plot(dataset, list(dataset.columns.values), _format_filenames(filenames, spec))
def destructLambda(exp): import venture.lite.types as t assert isinstance(exp, list) assert len(exp) == 3 assert isQuotation(exp[1]) assert isQuotation(exp[2]) params = t.ExpressionType().asPython(textOfQuotation(exp[1])) body = t.ExpressionType().asPython(textOfQuotation(exp[2])) return (params, body)
def plot_fun(spec, dataset): spec = t.ExpressionType().asPython(spec) if isinstance(dataset, Dataset): PlotSpec(spec).plot(dataset.asPandas(), dataset.ind_names) else: # Assume a raw data frame PlotSpec(spec).plot(dataset, list(dataset.columns.values))
def eval(self, id, exp): assert id not in self.results py_exp = t.ExpressionType().asPython( vv.VentureValue.fromStackDict(exp)) rng = self.py_rng val = evaluator.eval(addr.directive_address(id), py_exp, self.env, rng) assert isinstance(val, vv.VentureValue) self.results[id] = val
for id, esrParent in zip(ids, args.esrNodes()): env.fillBinding(id, esrParent) return env def description(self, name): return "%s\n Used internally in the implementation of letrec." % name registerBuiltinSP( "fix", SP( TypedPSP( FixRequestPSP(), SPType([ t.HomogeneousArrayType(t.SymbolType()), t.HomogeneousArrayType(t.ExpressionType()) ], t.RequestType())), TypedPSP( FixOutputPSP(), SPType([ t.HomogeneousArrayType(t.SymbolType()), t.HomogeneousArrayType(t.ExpressionType()) ], EnvironmentType())))) class AssessOutputPSP(DeterministicPSP): def simulate(self, args): vals = args.operandValues() value = vals[0] if isinstance(value, SPRef): # XXX trace.madeSPRecordAt(value.makerNode)
registerBuiltinSP("extend_environment", typed_nr(ExtendEnvOutputPSP(), [env.EnvironmentType(), t.SymbolType(), t.AnyType()], env.EnvironmentType())) class EvalRequestPSP(DeterministicPSP): def simulate(self,args): (exp, en) = args.operandValues() # Point to the desugared source code location of expression. # This is not a full address, because the call stack is gone. source_loc = addr.append(addr.top_frame(args.operandNodes[0].address), 1) return Request([ESR(args.node,exp,source_loc,en)]) def description(self,name): return "%s evaluates the given expression in the given environment and returns the result. Is itself deterministic, but the given expression may involve a stochasitc computation." % name registerBuiltinSP("eval", esr_output(TypedPSP(EvalRequestPSP(), SPType([t.ExpressionType(), env.EnvironmentType()], t.RequestType("<object>"))))) class AddressOfOutputPSP(DeterministicPSP): def simulate(self,args): place = args.operandNodes[0] node = args.trace.getOutermostNonReferenceNode(place) return jsonable_address(node) def description(self,name): return "%s returns a string representing the address of the top nontrivial node of its argument" % name registerBuiltinSP("address_of", typed_nr(AddressOfOutputPSP(), [t.AnyType()], t.StringType()))
def __venture_start__(ripl): ripl.bind_foreign_inference_sp("make_plots", make_plots_sp) ripl.bind_foreign_inference_sp('unique', deterministic_typed(lambda l: list(set(l)), [t.HomogeneousListType(t.ExpressionType())], t.HomogeneousListType(t.ExpressionType())))