Exemplo n.º 1
0
 def _collect_value_of(self, directive, type=False):
     inst = {
         'instruction': 'report',
         'directive_id': directive['directive_id'],
     }
     value = self.execute_instruction(inst)['value']
     directive['value'] = value if type else u.strip_types(value)
Exemplo n.º 2
0
 def evaluate(self, program, type=False):
     o = self.execute_instruction({
         'instruction': 'evaluate',
         'expression': program
     })
     value = o["value"]
     return value if type else u.strip_types(value)
Exemplo n.º 3
0
 def infer(self, params=None, type=False):
     inst = {
         'instruction': 'infer',
         'expression': self.defaultInferProgram(params)
     }
     o = self.execute_instruction(inst)
     value = o["value"]
     return value if type else u.strip_types(value)
Exemplo n.º 4
0
 def report(self, label_or_did, type=False):
     (tp, val) = _interp_label_or_did(label_or_did)
     if tp == 'did':
         i = {'instruction': 'report', 'directive_id': val}
     else:
         i = {'instruction': 'labeled_report', 'label': val}
     value = self.execute_instruction(i)['value']
     return value if type else u.strip_types(value)
Exemplo n.º 5
0
 def predict(self, expression, label=None, type=False):
     if label is None:
         i = {'instruction':'predict', 'expression':expression}
     else:
         label = _symbolize(label)
         i = {'instruction':'labeled_predict', 'expression':expression,
              'label':label}
     value = self.execute_instruction(i)['value']
     return value if type else u.strip_types(value)
Exemplo n.º 6
0
    def assume(self, 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.

        '''
        name = _symbolize(name)
        if label is None:
            label = name
        else:
            label = _symbolize(label)
        i = {'instruction':'labeled_assume',
             'symbol':name, 'expression':expression, 'label':label}
        value = self.execute_instruction(i)['value']
        return value if type else u.strip_types(value)
Exemplo n.º 7
0
 def sample_all(self, expression, type=False):
     i = {'instruction': 'sample_all', 'expression': expression}
     value = self.execute_instruction(i)['value']
     return value if type else u.strip_types(value)
Exemplo n.º 8
0
 def define(self, name, expression, type=False):
     name = _symbolize(name)
     i = {'instruction': 'define', 'symbol': name, 'expression': expression}
     value = self.execute_instruction(i)['value']
     return value if type else u.strip_types(value)
Exemplo n.º 9
0
 def execute_program(self, program_string, type=True):
     res = self.execute_parsed_program(self.parse_program(program_string))
     if not type:
         return u.strip_types([r["value"] for r in res])
     else:
         return res