def loadSpecObjectFromFile(self, spec_file = ""): """ spec_file: path to specification """ if not spec_file: spec_file = os.path.join(self.proj.project_root, self.proj.getFilenamePrefix() + ".spec") compiler = specCompiler.SpecCompiler(spec_file) compiler._decompose() spec, tracebackTree, response = compiler._writeLTLFile() # replace EnvTrans check to make sure it's not empty spec['EnvTrans'] = '&\n '.join(filter(None, [spec['EnvTrans'], spec["EnvTopo"]])) # replace EnvInit and SysInit to just init topology for centralized synthesis spec['EnvInit'] = spec['InitEnvRegionSanityCheck'] spec['SysInit'] = spec['InitRegionSanityCheck'] # replace SysTrans spec['SysTrans'] = '&\n '.join(filter(None, [spec['SysTrans'], spec["Topo"]])) # replace EnvGoals spec['EnvGoals'] = '&\n '.join(filter(None, [spec['EnvGoals'], spec["SysImplyEnv"]])) return spec
def runTest(self): title_str = "#### Testing project '{0}' ####".format(self.spec_filename) print if sys.platform not in ['win32', 'cygwin']: print "\033[41m" # red background color print "#"*len(title_str) print title_str print "#"*len(title_str), if sys.platform not in ['win32', 'cygwin']: print "\033[0m" # end coloring print c = specCompiler.SpecCompiler(self.spec_filename) c_out = c.compile() self.assertIsNotNone(c_out, msg="Compilation failed due to parser error") realizable, realizableFS, output = c_out print output expectedToBeUnrealizable = ("unsynth" in self.spec_filename) or \ ("unreal" in self.spec_filename) or \ ("unsat" in self.spec_filename) if expectedToBeUnrealizable: self.assertFalse(realizable, msg="Specification was realizable but we did not expect this") else: self.assertTrue(realizable, msg="Specification was unrealizable")
def resynthesizeFromNewSpecification(self, spec_text): self.pause() self.postEvent("INFO", "Starting resynthesis...") # Copy the current project new_proj = self._duplicateProject(self.proj) # Overwrite the specification text new_proj.specText = spec_text # Save the file new_proj.writeSpecFile() # Get a SpecCompiler ready c = specCompiler.SpecCompiler() c.proj = new_proj # Make sure rfi is non-decomposed here c.proj.loadRegionFile(decomposed=False) if c.proj.compile_options["decompose"]: c._decompose() # Call the parser c._writeLTLFile() c._writeSMVFile() # Constrain the initial conditions to our current state self._setSpecificationInitialConditionsToCurrent(new_proj) # Synthesize a strategy (realizable, realizableFS, output) = c._synthesize() logging.debug(output) if not (realizable or realizableFS): logging.error("Specification for resynthesis was unsynthesizable!") self.pause() return False logging.info("New automaton has been created.") # Load in the new strategy self.proj = new_proj logging.info("Reinitializing execution...") spec_file = self.proj.getFilenamePrefix() + ".spec" aut_file = self.proj.getFilenamePrefix() + ".aut" self.initialize(spec_file, aut_file, firstRun=False) self.resume() return True
def loadSpecFile(spec_file): """ spec_file: path to specification """ compiler = specCompiler.SpecCompiler(spec_file) compiler._decompose() spec, tracebackTree, response = compiler._writeLTLFile() # replace EnvTrans check to make sure it's not empty spec['EnvTrans'] = '&\n '.join(filter(None, [spec['EnvTrans'], spec["EnvTopo"]])) # replace EnvInit and SysInit to just init topology for centralized synthesis spec['EnvInit'] = spec['InitEnvRegionSanityCheck'] spec['SysInit'] = spec['InitRegionSanityCheck'] # replace SysTrans spec['SysTrans'] = '&\n '.join(filter(None, [spec['SysTrans'], spec["Topo"]])) # replace EnvGoals spec['EnvGoals'] = '&\n '.join(filter(None, [spec['EnvGoals'], spec["SysImplyEnv"]])) return spec
def compileSpec(): """compiles the project via the spec file, returns log""" createSession() saveToSession('regions') saveToSession('spec') sc = specCompiler.SpecCompiler() sc.loadSpec(session['specFilePath']) realizable, realizableFS, logString = sc.compile() # create zip of all files in the project with zipfile.ZipFile(joinToSessionDir(session['username'] + '.zip'), 'w') as myzip: myzip.write(session['regionsFilePath'], os.path.basename(session['regionsFilePath'])) myzip.write(session['specFilePath'], os.path.basename(session['specFilePath'])) fileName, fileExtension = os.path.splitext(session['specFilePath']) myzip.write(fileName + '.ltl', os.path.basename(fileName + '.ltl')) myzip.write(fileName + '.smv', os.path.basename(fileName + '.smv')) myzip.write(fileName + '.aut', os.path.basename(fileName + '.aut')) myzip.write(fileName + '_decomposed.regions', os.path.basename(fileName + '_decomposed.regions')) return jsonify({'compilerLog': logString})
def compileCentralizedSpec(self): """ Compile centralized spec. """ # synthesize our new centralized controller again self.compiler = specCompiler.SpecCompiler() self.compiler.proj.compile_options[ 'synthesizer'] = 'slugs' # use slugs self.compiler.proj.project_root = os.path.dirname( os.path.realpath(__file__)) #set directory to save slugsin self.compiler.proj.project_basename = self.filePath createSMVfile(self.filePath, self.smvEnvPropList, self.smvSysPropList) # create a new SMV file # create a new LTL file LTLspec_envList = [] LTLspec_sysList = [] # append new sys and env init currentEnvInitState = '(' + self.currentState.getLTLRepresentation( mark_players=True, use_next=False, include_inputs=True, include_outputs=False) + ')' currentSysInitState = '(' + self.currentState.getLTLRepresentation( mark_players=True, use_next=False, include_inputs=False, include_outputs=True) + ')' ## construct specification for specType in self.spec.keys(): if specType in ['EnvInit', 'SysInit']: if specType == 'EnvInit': # append init state LTLspec_envList.append(currentEnvInitState) else: LTLspec_sysList.append(currentSysInitState) for robot in self.coordinatingRobots: # here we will skip the goals and join them together below if specType in ['SysGoals']: continue elif specType in ['SysInit', 'SysTrans']: LTLspec_sysList.append(self.spec[specType][robot]) else: LTLspec_envList.append(self.spec[specType][robot]) # join the goals of the robots so that the goals are pursued at the same time specSysGoals = " &\n ".join( filter(None, [ x.strip().lstrip('[]<>') for x in self.spec['SysGoals'].values() ])) LTLspec_sysList.append("[]<>(" + specSysGoals + ")" if specSysGoals else specSysGoals) # set up violation check object specSysGoalsOld = " &\n ".join( filter( None, [x.strip().lstrip('[]<>') for x in self.sysGoalsOld.values()])) logging.debug("specSysGoalsOld:" + str(specSysGoalsOld)) if specSysGoalsOld: self.sysGoalsCheck = LTLParser.LTLcheck.LTL_Check( None, {}, {'sysGoals': specSysGoalsOld}, 'sysGoals') createLTLfile(self.filePath, " &\n".join(filter(None, LTLspec_envList)), " &\n".join(filter(None, LTLspec_sysList))) startTime = time.time() #HACK: Make it to recovery mode to try it out #self.compiler.proj.compile_options['recovery']=True # interactive strategy auto synthesizes with recovery option self.compiler.cooperativeGR1Strategy = True self.compiler.onlyRealizability = True realizable, realizableFS, output = self.compiler._synthesize() endTime = time.time() logging.info(output) """ If realizable, load AUT and return status to each robot. The execution of each robot resumes. """ if realizable: logging.info('Strategy synthesized in ' + str(endTime - startTime) + ' s.') # load strategy and initial state #self.strategy = strategy.createStrategyFromFile(self.filePath + '.aut', self.smvEnvPropList, self.smvSysPropList) self.strategy = strategy.createStrategyFromFile( self.filePath + '.slugsin', self.smvEnvPropList, self.smvSysPropList) # TODO: need to be finished self.strategy.current_state = self.strategy.searchForOneState( self.currentAssignment) logging.info('Starting at State ' + str(self.strategy.current_state.state_id)) else: logging.error('cannot synthesize a centralized patch') pass
def analyzeSpec(): """analyzes the stored spec and sends back the output""" sc = specCompiler.SpecCompiler() sc.loadSpec(session['specFilePath']) realizable, unsat, nonTrivial, to_highlight, output = sc._analyze() return jsonify({'analyzeLog': output})