def __init__(self, generation_tree=None): # Store the logic generation tree if it is provided. self.gen_tree = generation_tree self.spec_lists = chunks_from_gentree(self.gen_tree) if self.gen_tree else None self.user_history = [] self.system_history = []
def set_gen_tree(self, gen_tree): """Set the generation tree.""" self._gen_tree = gen_tree self._spec_lists = chunks_from_gentree( self._gen_tree) if self._gen_tree else None
def __init__(self, *args, **kwds): # begin wxGlade: MopsyFrame.__init__ kwds["style"] = wx.DEFAULT_FRAME_STYLE wx.Frame.__init__(self, *args, **kwds) self.mopsy_frame_statusbar = self.CreateStatusBar(1, 0) self.window_1 = wx.SplitterWindow(self, wx.ID_ANY, style=wx.SP_3D | wx.SP_BORDER) self.window_1_pane_1 = wx.Panel(self.window_1, wx.ID_ANY) self.history_grid = wx.grid.Grid(self.window_1_pane_1, wx.ID_ANY, size=(1, 1)) self.window_1_pane_2 = wx.Panel(self.window_1, wx.ID_ANY) self.panel_1 = wx.Panel(self.window_1_pane_2, wx.ID_ANY, style=wx.SUNKEN_BORDER | wx.TAB_TRAVERSAL) self.label_1 = wx.StaticText(self.window_1_pane_2, wx.ID_ANY, "Your goal:") self.label_goal = wx.StaticText(self.window_1_pane_2, wx.ID_ANY, "Wait patiently for Mopsy to load") self.label_5 = wx.StaticText(self.window_1_pane_2, wx.ID_ANY, "Current environment state:") self.label_6 = wx.StaticText(self.window_1_pane_2, wx.ID_ANY, "Please choose your response:") self.label_movingto = wx.StaticText(self.window_1_pane_2, wx.ID_ANY, "Moving to XXX ...") self.label_8 = wx.StaticText(self.window_1_pane_2, wx.ID_ANY, "Actuator states:") self.label_9 = wx.StaticText(self.window_1_pane_2, wx.ID_ANY, "Internal propositions:") self.label_violation = wx.StaticText(self.window_1_pane_2, wx.ID_ANY, "", style=wx.ST_NO_AUTORESIZE) self.button_next = wx.Button(self.window_1_pane_2, wx.ID_ANY, "Execute Move >>") self.__set_properties() self.__do_layout() self.Bind(wx.EVT_BUTTON, self.onButtonNext, self.button_next) # end wxGlade self.coreCalculationLock = threading.Lock() self.dest_region = None self.current_region = None self.regionsToHide = [] self.actuatorStates = {} self.sensorStates = {} self.panel_1.SetBackgroundStyle(wx.BG_STYLE_CUSTOM) self.mapBitmap = None # Load in the project and map self.mopsy_frame_statusbar.SetStatusText("Loading project...", 0) self.compiler = SpecCompiler(sys.argv[1]) self.proj = copy.deepcopy(self.compiler.proj) self.proj.rfi = self.proj.loadRegionFile(decomposed=True) self.Bind(wx.EVT_SIZE, self.onResize, self) self.panel_1.Bind(wx.EVT_PAINT, self.onPaint) self.panel_1.Bind(wx.EVT_ERASE_BACKGROUND, self.onEraseBG) self.panel_1.Bind(wx.EVT_LEFT_DOWN, self.onMapClick) self.onResize() self.proj.determineEnabledPropositions() # Parse specification so we can give feedback self.mopsy_frame_statusbar.SetStatusText("Parsing specification...", 0) self.compiler._decompose() self.spec, self.tracebackTree, response = self.compiler._writeLTLFile() self.compiler._writeSMVFile() # to update propList if self.proj.compile_options["parser"] == "slurp": # Add SLURP to path for import p = os.path.dirname(os.path.abspath(__file__)) sys.path.append(os.path.join(p, "..", "etc", "SLURP")) global chunks_from_gentree, line_to_chunks from ltlbroom.specgeneration import chunks_from_gentree, line_to_chunks self.tracebackChunks = chunks_from_gentree(self.tracebackTree) # Load in counter-strategy automaton self.envDummySensorHandler = EnvDummySensorHandler(self) self.envDummyActuatorHandler = EnvDummyActuatorHandler(self) self.dummyMotionHandler = DummyMotionHandler() self.proj.sensor_handler, self.proj.actuator_handler, self.proj.h_instance = [ None ] * 3 self.mopsy_frame_statusbar.SetStatusText( "Loading environment counter-strategy...", 0) self.num_bits = int(numpy.ceil(numpy.log2(len(self.proj.rfi.regions))) ) # Number of bits necessary to encode all regions region_props = ["bit" + str(n) for n in xrange(self.num_bits)] self.env_aut = fsa.Automaton(self.proj) self.env_aut.sensor_handler = self.envDummySensorHandler self.env_aut.actuator_handler = self.envDummyActuatorHandler self.env_aut.motion_handler = self.dummyMotionHandler # We are being a little tricky here by just reversing the sensor and actuator propositions # to create a sort of dual of the usual automaton self.env_aut.loadFile( self.proj.getFilenamePrefix() + ".aut", self.proj.enabled_actuators + self.proj.all_customs + self.compiler.proj.internal_props + region_props, self.proj.enabled_sensors, []) self.env_aut.current_region = None # Find first state in counterstrategy that seeks to falsify the given liveness if len(sys.argv) > 2: desired_jx = int(sys.argv[2]) for s in self.env_aut.states: if s.transitions: rank_str = s.transitions[0].rank m = re.search(r"\(\d+,(-?\d+)\)", rank_str) if m is None: print "ERROR: Error parsing jx in automaton. Are you sure the spec is unrealizable?" return jx = int(m.group(1)) if jx == desired_jx: self.env_aut.current_state = s break if self.env_aut.current_state is None: print "ERROR: could not find state in counterstrategy to falsify sys goal #{}".format( desired_jx) return else: self.env_aut.current_state = self.env_aut.states[0] # Internal aut housekeeping (ripped from chooseInitialState; hacky) self.env_aut.last_next_states = [] self.env_aut.next_state = None self.env_aut.next_region = None #self.env_aut.dumpStates([self.env_aut.current_state]) # Set initial sensor values self.env_aut.updateOutputs() # Figure out what actuator/custom-prop settings the system should start with for k, v in self.env_aut.current_state.inputs.iteritems(): # Skip any "bitX" region encodings if re.match('^bit\d+$', k): continue self.actuatorStates[k] = int(v) # Figure out what region the system should start from self.current_region = self.regionFromEnvState( self.env_aut.current_state) self.dest_region = self.current_region # Create all the sensor/actuator buttons self.env_buttons = [] # This will later hold our buttons self.act_buttons = [] # This will later hold our buttons self.cust_buttons = [] # This will later hold our buttons actprops = dict((k, v) for k, v in self.actuatorStates.iteritems() if k in self.proj.enabled_actuators) custprops = dict( (k, v) for k, v in self.actuatorStates.iteritems() if k in self.proj.all_customs + self.compiler.proj.internal_props) self.populateToggleButtons(self.sizer_env, self.env_buttons, self.sensorStates) self.populateToggleButtons(self.sizer_act, self.act_buttons, actprops) self.populateToggleButtons(self.sizer_prop, self.cust_buttons, custprops) # Make the env buttons not clickable (TODO: maybe replace with non-buttons) #for b in self.env_buttons: # b.Enable(False) # Set up the logging grid self.history_grid.SetDefaultCellFont( wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, "")) self.history_grid.SetLabelFont( wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, "")) colheaders = self.proj.enabled_sensors + [ "Region" ] + self.proj.enabled_actuators + self.proj.all_customs + self.compiler.proj.internal_props self.history_grid.CreateGrid(0, len(colheaders)) for i, n in enumerate(colheaders): self.history_grid.SetColLabelValue(i, " " + n + " ") self.history_grid.SetColSize(i, -1) # Auto-size self.history_grid.EnableEditing(False) # Decide whether to enable core-finding self.coreFindingEnabled = self.compiler._getPicosatCommand( ) is not None # Put initial condition into log self.appendToHistory() # Start initial environment move # All transitionable states have the same env move, so just use the first if (len(self.env_aut.current_state.transitions) >= 1): self.env_aut.updateOutputs( self.env_aut.current_state.transitions[0]) self.label_movingto.SetLabel( "Stay in region " + self.env_aut.getAnnotatedRegionName(self.current_region)) self.showCurrentGoal() self.applySafetyConstraints()
def __init__(self, *args, **kwds): # begin wxGlade: MopsyFrame.__init__ kwds["style"] = wx.DEFAULT_FRAME_STYLE wx.Frame.__init__(self, *args, **kwds) self.mopsy_frame_statusbar = self.CreateStatusBar(1, 0) self.window_1 = wx.SplitterWindow(self, wx.ID_ANY, style=wx.SP_3D | wx.SP_BORDER) self.window_1_pane_1 = wx.Panel(self.window_1, wx.ID_ANY) self.history_grid = wx.grid.Grid(self.window_1_pane_1, wx.ID_ANY, size=(1, 1)) self.window_1_pane_2 = wx.Panel(self.window_1, wx.ID_ANY) self.panel_1 = wx.Panel(self.window_1_pane_2, wx.ID_ANY, style=wx.SUNKEN_BORDER | wx.TAB_TRAVERSAL) self.label_1 = wx.StaticText(self.window_1_pane_2, wx.ID_ANY, "Your goal:") self.label_goal = wx.StaticText(self.window_1_pane_2, wx.ID_ANY, "Wait patiently for Mopsy to load") self.label_5 = wx.StaticText(self.window_1_pane_2, wx.ID_ANY, "Current environment state:") self.label_6 = wx.StaticText(self.window_1_pane_2, wx.ID_ANY, "Please choose your response:") self.label_movingto = wx.StaticText(self.window_1_pane_2, wx.ID_ANY, "Moving to XXX ...") self.label_8 = wx.StaticText(self.window_1_pane_2, wx.ID_ANY, "Actuator states:") self.label_9 = wx.StaticText(self.window_1_pane_2, wx.ID_ANY, "Internal propositions:") self.label_violation = wx.StaticText(self.window_1_pane_2, wx.ID_ANY, "", style=wx.ST_NO_AUTORESIZE) self.button_next = wx.Button(self.window_1_pane_2, wx.ID_ANY, "Execute Move >>") self.__set_properties() self.__do_layout() self.Bind(wx.EVT_BUTTON, self.onButtonNext, self.button_next) # end wxGlade self.coreCalculationLock = threading.Lock() self.dest_region = None self.current_region = None self.regionsToHide = [] self.actuatorStates = {} self.sensorStates = {} self.panel_1.SetBackgroundStyle(wx.BG_STYLE_CUSTOM) self.mapBitmap = None # Load in the project and map self.mopsy_frame_statusbar.SetStatusText("Loading project...", 0) self.compiler = SpecCompiler(sys.argv[1]) self.proj = copy.deepcopy(self.compiler.proj) self.proj.rfi = self.proj.loadRegionFile(decomposed=True) self.Bind(wx.EVT_SIZE, self.onResize, self) self.panel_1.Bind(wx.EVT_PAINT, self.onPaint) self.panel_1.Bind(wx.EVT_ERASE_BACKGROUND, self.onEraseBG) self.panel_1.Bind(wx.EVT_LEFT_DOWN, self.onMapClick) self.onResize() self.proj.determineEnabledPropositions() # Parse specification so we can give feedback self.mopsy_frame_statusbar.SetStatusText("Parsing specification...", 0) self.compiler._decompose() self.spec, self.tracebackTree, response = self.compiler._writeLTLFile() self.compiler._writeSMVFile() # to update propList if self.proj.compile_options["parser"] == "slurp": # Add SLURP to path for import p = os.path.dirname(os.path.abspath(__file__)) sys.path.append(os.path.join(p, "..", "etc", "SLURP")) global chunks_from_gentree, line_to_chunks from ltlbroom.specgeneration import chunks_from_gentree, line_to_chunks self.tracebackChunks = chunks_from_gentree(self.tracebackTree) # Load in counter-strategy automaton self.envDummySensorHandler = EnvDummySensorHandler(self) self.envDummyActuatorHandler = EnvDummyActuatorHandler(self) self.dummyMotionHandler = DummyMotionHandler() self.proj.sensor_handler, self.proj.actuator_handler, self.proj.h_instance = [None]*3 self.mopsy_frame_statusbar.SetStatusText("Loading environment counter-strategy...", 0) self.num_bits = int(numpy.ceil(numpy.log2(len(self.proj.rfi.regions)))) # Number of bits necessary to encode all regions region_props = ["bit" + str(n) for n in xrange(self.num_bits)] self.env_aut = fsa.Automaton(self.proj) self.env_aut.sensor_handler = self.envDummySensorHandler self.env_aut.actuator_handler = self.envDummyActuatorHandler self.env_aut.motion_handler = self.dummyMotionHandler # We are being a little tricky here by just reversing the sensor and actuator propositions # to create a sort of dual of the usual automaton self.env_aut.loadFile(self.proj.getFilenamePrefix() + ".aut", self.proj.enabled_actuators + self.proj.all_customs + self.compiler.proj.internal_props + region_props, self.proj.enabled_sensors, []) self.env_aut.current_region = None # Find first state in counterstrategy that seeks to falsify the given liveness if len(sys.argv) > 2: desired_jx = int(sys.argv[2]) for s in self.env_aut.states: if s.transitions: rank_str = s.transitions[0].rank m = re.search(r"\(\d+,(-?\d+)\)", rank_str) if m is None: print "ERROR: Error parsing jx in automaton. Are you sure the spec is unrealizable?" return jx = int(m.group(1)) if jx == desired_jx: self.env_aut.current_state = s break if self.env_aut.current_state is None: print "ERROR: could not find state in counterstrategy to falsify sys goal #{}".format(desired_jx) return else: self.env_aut.current_state = self.env_aut.states[0] # Internal aut housekeeping (ripped from chooseInitialState; hacky) self.env_aut.last_next_states = [] self.env_aut.next_state = None self.env_aut.next_region = None #self.env_aut.dumpStates([self.env_aut.current_state]) # Set initial sensor values self.env_aut.updateOutputs() # Figure out what actuator/custom-prop settings the system should start with for k,v in self.env_aut.current_state.inputs.iteritems(): # Skip any "bitX" region encodings if re.match('^bit\d+$', k): continue self.actuatorStates[k] = int(v) # Figure out what region the system should start from self.current_region = self.regionFromEnvState(self.env_aut.current_state) self.dest_region = self.current_region # Create all the sensor/actuator buttons self.env_buttons = [] # This will later hold our buttons self.act_buttons = [] # This will later hold our buttons self.cust_buttons = [] # This will later hold our buttons actprops = dict((k,v) for k,v in self.actuatorStates.iteritems() if k in self.proj.enabled_actuators) custprops = dict((k,v) for k,v in self.actuatorStates.iteritems() if k in self.proj.all_customs + self.compiler.proj.internal_props) self.populateToggleButtons(self.sizer_env, self.env_buttons, self.sensorStates) self.populateToggleButtons(self.sizer_act, self.act_buttons, actprops) self.populateToggleButtons(self.sizer_prop, self.cust_buttons, custprops) # Make the env buttons not clickable (TODO: maybe replace with non-buttons) #for b in self.env_buttons: # b.Enable(False) # Set up the logging grid self.history_grid.SetDefaultCellFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, "")) self.history_grid.SetLabelFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, "")) colheaders = self.proj.enabled_sensors + ["Region"] + self.proj.enabled_actuators + self.proj.all_customs + self.compiler.proj.internal_props self.history_grid.CreateGrid(0,len(colheaders)) for i,n in enumerate(colheaders): self.history_grid.SetColLabelValue(i, " " + n + " ") self.history_grid.SetColSize(i,-1) # Auto-size self.history_grid.EnableEditing(False) # Decide whether to enable core-finding self.coreFindingEnabled = self.compiler._getPicosatCommand() is not None # Put initial condition into log self.appendToHistory() # Start initial environment move # All transitionable states have the same env move, so just use the first if (len(self.env_aut.current_state.transitions) >=1 ): self.env_aut.updateOutputs(self.env_aut.current_state.transitions[0]) self.label_movingto.SetLabel("Stay in region " + self.env_aut.getAnnotatedRegionName(self.current_region)) self.showCurrentGoal() self.applySafetyConstraints()
def set_gen_tree(self, gen_tree): """Set the generation tree.""" self._gen_tree = gen_tree self._spec_lists = chunks_from_gentree(self._gen_tree) if self._gen_tree else None