def automaton_from_gff(gff: str, complement: bool = False) -> Automaton: gff = strip_unused_symbols(gff) input_file_name = get_tmp_file_name() output_file_name = get_tmp_file_name() output_file_name2 = get_tmp_file_name() with open(input_file_name, "w") as f: f.write(gff) complement_stmnt = "" if not complement else "\n$res = complement $res;" goal_script = """ $res = load "{input_file_name}"; {complement_stmnt} $res = simplify -m fair -dse -ds -rse -rs -ru -rd $res; $res = determinization -m bk09 $res; acc -min $res; save $res {output_file_name}; acc -max $res; save $res {output_file_name2}; """.format( complement_stmnt=complement_stmnt, input_file_name=input_file_name, output_file_name=output_file_name, output_file_name2=output_file_name2, ) execute_goal_script(goal_script) gff = readfile(output_file_name) gff2 = readfile(output_file_name2) init_state2, states2, edges2, acc_states2 = gff_2_automaton_params(gff2) nacc_trap_states2 = get_nacc_trap_states(states2, acc_states2, edges2) if set(nacc_trap_states2).union(acc_states2) == set(states2): # safety automaton automaton = Automaton(states2, init_state2, acc_states2, nacc_trap_states2, True, tuple(edges2.items())) else: # contains both dead states, and accepting states init_state, states, edges, acc_states = gff_2_automaton_params(gff) nacc_trap_states = get_nacc_trap_states(states, acc_states, edges) automaton = Automaton(states, init_state, acc_states, nacc_trap_states, False, tuple(edges.items())) logger.info("after all manipulations: %s", ["liveness", "safety"][automaton.is_safety]) remove(input_file_name) remove(output_file_name) remove(output_file_name2) return automaton
def automaton_from_gff(gff: str, complement: bool=False) -> Automaton: gff = strip_unused_symbols(gff) input_file_name = get_tmp_file_name() output_file_name = get_tmp_file_name() output_file_name2 = get_tmp_file_name() with open(input_file_name, 'w') as f: f.write(gff) complement_stmnt = '' if not complement else '\n$res = complement $res;' goal_script = """ $res = load "{input_file_name}"; {complement_stmnt} $res = simplify -m fair -dse -ds -rse -rs -ru -rd $res; $res = determinization -m bk09 $res; acc -min $res; save $res {output_file_name}; acc -max $res; save $res {output_file_name2}; """.format(complement_stmnt=complement_stmnt, input_file_name=input_file_name, output_file_name=output_file_name, output_file_name2=output_file_name2) execute_goal_script(goal_script) gff = readfile(output_file_name) gff2 = readfile(output_file_name2) init_state2, states2, edges2, acc_states2 = gff_2_automaton_params(gff2) nacc_trap_states2 = get_nacc_trap_states(states2, acc_states2, edges2) if set(nacc_trap_states2).union(acc_states2) == set(states2): # safety automaton automaton = Automaton(states2, init_state2, acc_states2, nacc_trap_states2, True, tuple(edges2.items())) else: # contains both dead states, and accepting states init_state, states, edges, acc_states = gff_2_automaton_params(gff) nacc_trap_states = get_nacc_trap_states(states, acc_states, edges) automaton = Automaton(states, init_state, acc_states, nacc_trap_states, False, tuple(edges.items())) logger.info('after all manipulations: %s', ['liveness', 'safety'][automaton.is_safety]) remove(input_file_name) remove(output_file_name) remove(output_file_name2) return automaton
def is_realizable(test): spec_status = stripped_non_empty(readfile(test).splitlines())[-1] if re.fullmatch('-- *realizable', spec_status): return True if re.fullmatch('-- *unrealizable', spec_status): return False assert 0, 'spec status is unknown'
def execute_translation(what: str, formula: str, options: str="") -> str: output_file_name = get_tmp_file_name("goal_trans_") if "\"" in formula: raise SyntaxError("Quotation marks are not allowed as parts of formulae.") template = "translate {what} {option} -o {output} \"{formula}\";" script = template.format(what=what, option=options, formula=formula, output=output_file_name) execute_goal_script(script) result = readfile(output_file_name) remove(output_file_name) return result
def main(smv_spec_file_name, verbose_level): logger = logging.getLogger(__name__) scripts_dir = os.path.dirname(os.path.abspath(__file__)) spec_2_smv_path = scripts_dir + '/spec_2_smv.py' verbosity = '-{}'.format('v' * verbose_level) if verbose_level else '' latches_2_output_path = scripts_dir + '/latches_2_output.py' logger.debug('calling to %s' % spec_2_smv_path) # i could not fix the problem with unicode encodings when using execute_shell (with separate checks of exit statuses), # so use piping here instead aig = str(subprocess.check_output( '{spec_2_smv} {verbosity} {spec_file} | smvflatten | smvtoaig | aigtoaig -a | {latches_2_output}' .format(spec_2_smv=spec_2_smv_path, verbosity=verbosity, spec_file=smv_spec_file_name, latches_2_output=latches_2_output_path), shell=True), encoding=sys.getdefaultencoding()) outputs = get_controllable(readfile(smv_spec_file_name).splitlines()) assert outputs, 'there are no controllable signals, abort' lines = aig.splitlines() symbol_table_starts = find(lambda l: l.startswith('i'), lines) result = lines[:symbol_table_starts] i = symbol_table_starts while True: l = lines[i] if not l.startswith('i'): break result.append(rename(l, outputs)) i += 1 result += lines[i:] print('\n'.join(result)) return 0
def main(smv_spec_file_name, verbose_level): logger = logging.getLogger(__name__) scripts_dir = os.path.dirname(os.path.abspath(__file__)) spec_2_smv_path = scripts_dir + '/spec_2_smv.py' verbosity = '-{}'.format('v'*verbose_level) if verbose_level else '' latches_2_output_path = scripts_dir + '/latches_2_output.py' logger.debug('calling to %s' % spec_2_smv_path) # i could not fix the problem with unicode encodings when using execute_shell (with separate checks of exit statuses), # so use piping here instead aig = str(subprocess.check_output('{spec_2_smv} {verbosity} {spec_file} | smvflatten | smvtoaig | aigtoaig -a | {latches_2_output}' .format(spec_2_smv=spec_2_smv_path, verbosity=verbosity, spec_file=smv_spec_file_name, latches_2_output=latches_2_output_path), shell=True), encoding=sys.getdefaultencoding()) outputs = get_controllable(readfile(smv_spec_file_name).splitlines()) assert outputs, 'there are no controllable signals, abort' lines = aig.splitlines() symbol_table_starts = find(lambda l: l.startswith('i'), lines) result = lines[:symbol_table_starts] i = symbol_table_starts while True: l = lines[i] if not l.startswith('i'): break result.append(rename(l, outputs)) i += 1 result += lines[i:] print('\n'.join(result)) return 0