Example #1
0
    def parse(self):

        # Do nothing if we're already parsed
        if self.parsed:
            return

        Session.write("Parsing System...\n")
        self.parse_errors = []

        Session.write("  Parsing Variables...")
        self.parse_errors += self.parse_local_variables()
        self.parse_errors += self.parse_output_variables()
        self.parse_errors += self.parse_input_variables()
        Session.write("  Variables Parsed.\n")

        for automaton in self.automata:
            self.parse_errors += automaton.parse()

        Session.write("  Validating Current Property...\n")
        Property.validate_cur_prop()
        Session.write("  Current Property Valid.\n")

        if len(self.parse_errors) == 0:
            self.parsed = True
            Session.write("No Parse Errors.\n")
        else:
            self.parsed = False
            self.print_parse_errors()

        Session.write("Parsing Complete.\n")
        return
    def _reload_xml(self, event=None):

        if not Session.file_path:
            print('No session filepath\n')
            return
        Session.write("Reloading xml...")

        file_path = Session.file_path
        file = FileHandler.open_file(file_path)
        if (HYXML_FILE in file_path):
            Session.write("  hyxml file reloaded.\n")
            Session.file_type = HYXML_FILE
        elif (MDL_FILE in file_path):
            Session.write("  mdl file opened\n")
            Session.file_type = MDL_FILE

        if file == None:
            print("File reload failed: No file\n")
            return

        # Obtain parsed results
        Session.hybrid = file['hybrid']
        Session.prop_list = file['prop_list']
        if (len(Session.prop_list) == 0):
            Session.prop_list.append(Property())
        Session.file_opened = True

        self.open_xml()

        return
Example #3
0
    def _callback_new(self):
        # Create new property
        Session.cur_prop = Property()
        Session.hybrid.properties.append(Session.cur_prop)

        # Display property in view and list
        self.sel_iid = self._add_property(Session.cur_prop)
        self.list_view.selection_set(self.sel_iid)
        self._display_property(Session.cur_prop)
Example #4
0
    def _callback_us(self, unsafe_set):
        """ Parse unsafe set an display errors, if any, above text box """

        (valid, error) = Property.validate_unsafe_set(unsafe_set)

        self.us_err.set(error)
        self.us_vl.set_state(valid)
        self.unsafe_set_disable = (not valid)
        if self.check_sim_ver_disable():
            self._disable_enable_button(1)
        else:
            self._disable_enable_button(0)

        return
Example #5
0
    def _callback_is(self, initial_set):
        """ Parse initial set an display errors, if any, above text box """

        (valid, error) = Property.validate_initial_set(initial_set)

        self.is_err.set(error)
        self.is_vl.set_state(valid)
        self.initial_set_disable = (not valid)
        if self.check_sim_ver_disable():
            self._disable_enable_button(1)
        else:
            self._disable_enable_button(0)

        return
Example #6
0
    def create_template():

        hybrid = HyIR()
        automaton = Automaton()
        property_ = Property()

        # LMB I'm guessing every model will use time
        automaton.add_var(Variable(name="t"))

        m1 = Mode("Mode A", 0)
        m2 = Mode("Mode B", 1)
        automaton.add_mode(m1)
        automaton.add_mode(m2)

        automaton.add_transition(Transition(Guard(), [], 0, m1.id, m2.id))
        automaton.add_transition(Transition(Guard(), [], 1, m2.id, m1.id))

        hybrid.add_automaton(automaton)
        hybrid.add_property(property_)

        return hybrid
Example #7
0
    def _callback_rmv(self):
        # Find next property to select
        idx = self.list_view.index(self.sel_iid)
        plen = len(Session.hybrid.properties) - 1
        if plen == 0:
            Session.cur_prop = Property()
            Session.hybrid.properties.append(Session.cur_prop)
            up_iid = self._add_property(Session.cur_prop)
        elif idx == plen:
            Session.cur_prop = Session.hybrid.properties[idx - 1]
            up_iid = self.list_view.prev(self.sel_iid)
        else:
            Session.cur_prop = Session.hybrid.properties[idx + 1]
            up_iid = self.list_view.next(self.sel_iid)

        # Remove the selected property
        self.list_view.delete(self.sel_iid)
        del Session.hybrid.properties[idx]

        # Display property in view and list
        self.sel_iid = up_iid
        self.list_view.selection_set(self.sel_iid)
        self._display_property(Session.cur_prop)
Example #8
0
    def open_hyxml_properties(root):
        """ 
        Load properties from hyxml
        
        Args:
            root: XML root

        Returns:
            List of Proerty() objects
        """

        Session.write("  Loading hyxml properties...")

        prop_list = []
        for prop in root.iterfind('property'):

            p = Property()
            p.name = prop.get('name')

            p.type = SAFETY
            p.initial_set_str = FileHandler.clean_eq(prop.get('initialSet'))
            p.unsafe_set_str = FileHandler.clean_eq(prop.get('unsafeSet'))

            # Handle properties parameters
            param = prop.find('parameters')
            if param is not None:
                time_step = param.get('timestep')
                if time_step is None:
                    p.time_step = 0.0
                else:
                    p.time_step = float(time_step)

                time_horizon = param.get('timehorizon')
                if time_horizon is None:
                    p.time_horizon = 0.0
                else:
                    p.time_horizon = float(time_horizon)

                k_value = param.get('kvalue')
                if k_value is None:
                    p.k_value = 0.0
                else:
                    p.k_value = float(k_value)

            prop_list.append(p)

        Session.write("  Done.\n")
        return prop_list
Example #9
0
            print("ERROR: File required")
            sys.exit()
        FileHandler.open_file(args['-f'])
        
        # Select Simulator (Session defaults to ODEINT_FIX)
        if ('-s' in args) and (args['-s'] == "odeintadp"):
            Session.simulator = ODEINT_ADP

        # Select Refinement Strategy (Session defualts to DEF_STRAT)
        if ('-r' in args) and (args['-r'] == "user"):
            Session.refine_strat = USR_STRAT
        
        HyIR.compose_all(Session.hybrid)
        # We only concern ourselves with the first listed property - for now
        Session.prop_list = [Session.cur_prop]
        Property.validate_cur_prop()

        # Simulate/Verify (Simulate is default)
        if ('-a' in args) and (args['-a'] == "verify"):
            result = verify()
            print("\nVerification Results")
        else:
            result = simulate()
            print("\nSimulation Results")

        print("-----------------------")
        print("Property: ", Session.cur_prop.name)
        print("Stauts:   ", Session.cur_prop.status)
        print("Result:   ", Session.cur_prop.result)

    else: