def test_map_setitem(self): map = LabelsMap() map[Label({'a': True})] = True assert map[Label({'a': True})] == True # map[Label({'a':True})] = False # assert map[Label({'a':True})] == False assert Label({'a': True, 'c': True}) in map assert Label({}) not in map
def _restrict_trans(self, impl, permissible_states): #: :type: FuncDescription trans_func_desc = impl.taus_descs[0] assertions = StrAwareList() for curr_state in permissible_states: free_input_vars = self._get_free_vars(Label(), impl) value_by_arg = self._get_proc_tau_args(curr_state, Label(), 0, impl) next_state = self._underlying_solver.call_func(trans_func_desc, value_by_arg) assertions += self._underlying_solver.assert_( self._underlying_solver.forall_bool(free_input_vars, self._get_permissible_states_clause(next_state, permissible_states))) return assertions
def _create_automaton(self, node_names, init_node_name, transitions_dict): name_to_node = {} for name in node_names: name_to_node[name] = Node(name) for trans_desc, is_rejecting in transitions_dict.items(): src_node, dst_node = list(map(lambda name: name_to_node[name], trans_desc.split('->'))) src_node.add_transition(Label({}), {(dst_node,is_rejecting)}) return Automaton([{name_to_node[init_node_name]}], set(), set(name_to_node.values()))
def _label_states_with_outvalues(lts:LTS, filter='all'): dot_lines = StrAwareList() for state in lts.states: signal_vals_pairs = [(var, vals) for (var, vals) in lts.model_by_name.items() if var in filter or filter == 'all'] outvals = dict([(var, vals[Label({'state': state})]) # TODO: hack for (var, vals) in signal_vals_pairs]) outvals_str = _convert_to_dot(outvals) if outvals_str != '': dot_lines += '"{state}"[label="{out}\\n({state})"]'.format(state=state, out=outvals_str) return dot_lines
def test_map_getitem(self): label_map = LabelsMap() label_map[Label({'a': False, 'b': False})] = True assert Label({'a': False, 'b': False}) in label_map assert label_map[Label({'a': False, 'b': False})] == True assert Label({'a': False, 'b': False, 'c': False}) in label_map assert label_map[Label({'a': False, 'b': False, 'c': False})] == True assert Label({'a': True, 'b': False}) not in label_map assert Label({'a': True}) not in label_map
def _build_func_model_from_smt(self, func_smt_lines, func_desc:FuncDescription) -> dict: """ Return transition(output) graph {label:output} """ func_model = {} for l in func_smt_lines: # (get-value ((tau t0 true true))) l = l.replace('get-value', '').replace('(', '').replace(')', '') tokens = l.split() if tokens[0] != func_desc.name: continue values = self._parse_values(tokens[1:]) # the very first - func_name args = Label(func_desc.get_args_dict(values[:-1])) func_model[args] = values[-1] return func_model
def _get_tok_rings_safety_props( self) -> StrAwareList: # TODO: should be able to specify states! """ Return (in SMT form, constraints on non-wrapped tau function): G(tok & !sends -> Xtok(tau(!prev))) G(sends -> tok) G(sends -> X!tok(!prev)) G(Xtok(prev)) G(!tok -> !Xtok(!prev)) """ smt_lines = StrAwareList() tau_desc = self.taus_descs[0] tau_signals = self.orig_inputs[0] tok_func_desc = self.outvar_desc_by_process[0][self._has_tok_signal] sends_func_desc = self.outvar_desc_by_process[0][self._sends_signal] prev_is_false_label = Label({self._sends_prev_signal: False}) prev_is_true_label = Label({self._sends_prev_signal: True}) states = self.states_by_process[0] for state in states: state_arg = {self.state_arg_name: state} has_tok_expr = call_func(tok_func_desc, state_arg) sends_tok_expr = call_func(sends_func_desc, state_arg) _, free_vars = build_signals_values(tau_signals, prev_is_false_label) nprev_arg, _ = build_signals_values(tau_signals, prev_is_false_label) nprev_state_arg = add_dicts(nprev_arg, state_arg) prev_arg, _ = build_signals_values(tau_signals, prev_is_true_label) prev_state_arg = add_dicts(prev_arg, state_arg) tau_nprev_expr = call_func(tau_desc, nprev_state_arg) tok_of_tau_nprev_expr = call_func( tok_func_desc, {self.state_arg_name: tau_nprev_expr}) tau_prev_expr = call_func(tau_desc, prev_state_arg) tok_of_tau_prev_expr = call_func( tok_func_desc, {self.state_arg_name: tau_prev_expr}) # tok_dont_disappear = forall_bool( free_vars, op_implies(op_and([has_tok_expr, op_not(sends_tok_expr)]), tok_of_tau_nprev_expr)) sends_with_token_only = forall_bool( free_vars, op_implies(sends_tok_expr, has_tok_expr)) sends_means_release = forall_bool( free_vars, op_implies(sends_tok_expr, op_not(tok_of_tau_nprev_expr))) sends_prev_means_acquire = forall_bool(free_vars, tok_of_tau_prev_expr) no_sends_prev_no_tok_means_no_next_tok = forall_bool( free_vars, op_implies(op_not(has_tok_expr), op_not(tok_of_tau_nprev_expr))) smt_lines += [ tok_dont_disappear, sends_with_token_only, sends_means_release, sends_prev_means_acquire, no_sends_prev_no_tok_means_no_next_tok ] return smt_lines