def generate_jtlv_ltl(spec): """Return LTL specification for JTLV. @type spec: L{GRSpec} """ a, g = translation.translate(spec, 'jtlv') if not a: a = 'TRUE' if not g: g = 'TRUE' ltl = ltl_template.format(a=a, g=g) logger.debug('JTLV input formula:\n' + ltl) return ltl
def synthesize(formula, env_vars=None, sys_vars=None): """Return Moore transducer if C{formula} is realizable. Variable C{dict}s have variable names as keys and their type as value. The types should be 'boolean'. These parameters are only used if formula is of type C{str}. Else, the variable dictionaries associated with the L{LTL} or L{GRSpec} object are used. @param formula: linear temporal logic formula @type formula: C{str}, L{LTL}, or L{GRSpec} @param env_vars: uncontrolled variables (inputs); used only if C{formula} is of type C{str} @type env_vars: C{dict} or None @param sys_vars: controlled variables (outputs); used only if C{formula} is of type C{str} @type sys_vars: C{dict} or None @return: symbolic Moore transducer (guards are conjunctions, not sets) @rtype: L{MooreMachine} """ if isinstance(formula, GRSpec): env_vars = formula.env_vars sys_vars = formula.sys_vars elif isinstance(formula, LTL): env_vars = formula.input_variables sys_vars = formula.output_variables all_vars = dict(env_vars) all_vars.update(sys_vars) if not all(v == 'boolean' for v in all_vars.itervalues()): raise TypeError( 'all variables should be Boolean:\n{v}'.format(v=all_vars)) if isinstance(formula, GRSpec): f = translate(formula, 'wring') else: T = parse(str(formula)) f = translate_ast(T, 'wring').flatten(env_vars=env_vars, sys_vars=sys_vars) # dump partition file s = '.inputs {inp}\n.outputs {out}'.format( inp=' '.join(env_vars), out=' '.join(sys_vars) ) with open(IO_PARTITION_FILE, 'w') as fid: fid.write(s) # call lily try: p = subprocess.Popen([LILY, '-f', f, '-syn', IO_PARTITION_FILE], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) out = p.stdout.read() except OSError as e: if e.errno == os.errno.ENOENT: raise Exception( 'lily.pl not found in path.\n' 'See the Lily docs for setting PERL5LIB and PATH.') else: raise dotf = open(DOTFILE, 'r') fail_msg = 'Formula is not realizable' if dotf.read(len(fail_msg)) == fail_msg: return None dotf.seek(0) g = nx.read_dot(dotf) dotf.close() moore = lily_strategy2moore(g, env_vars, sys_vars) return moore
def check_translate_unrecognized_types(spc): ts.translate(spc, 'gr1c')
def test_translate_unrecognized_types(spc): ts.translate(spc, 'gr1c')