예제 #1
0
                    mode = m_waiting_tm_var
            elif mode == m_waiting_tm_var:
                if line.startswith('tm var'):
                    tm_var_line = line
                    mode = m_waiting_braces
            elif mode == m_waiting_braces:
                if line.startswith('{'):
                    mode = m_reading_model
                    model_definition = ""
                elif line.startswith('}'):
                    mode = m_waiting_mode
            elif mode == m_reading_model:
                if line.startswith('}'):
                    # taylor model finished
                    model_definition = remove_intervals_from_tm(model_definition)
                    rv.append(TaylorModel(mode_name, tm_var_line, model_definition))

                    mode = m_waiting_braces
                else:
                    model_definition += line + "\n"
    return rv               
 
if __name__ == "__main__":
    tool_main(FlowstarTool())






예제 #2
0
파일: tool_hylaa.py 프로젝트: carptj/hyst
            if "not yet supported" in str(e):
                rv = RunCode.SKIP
            else:
                rv = RunCode.ERROR

        return rv

    def _make_image(self):
        '''make an image. For Hylaa, the image will already be made during computation.'''

        return True

    def parse_output(self, dummy_directory, lines, dummy_hypy_out):
        '''returns the parsed output object

        For hylaa, this is the hylaa engine object of the most recent run.
        '''
        rv = {'safe': None}

        for line in reversed(lines):
            if 'Result: Error modes are NOT reachable.' in line:
                rv['safe'] = True
            elif 'Result: Error modes are reachable.' in line:
                rv['safe'] = False

        return rv


if __name__ == "__main__":
    tool_main(HylaaTool())
        '''returns the parsed output object

        For pysim, this returns a dictionary created by run_tool():
        { 'simulations': <the result of running simulate()>,
          'variables': <list of state variable names>,
          'interval_bounds': interval bounds [x_min, x_max] of the state variables, as np.array with shape (n, 2)
        }
        Further entries may be added in the future.
        '''
        # NOTE: This function is not called on the same tool object as _run_tool and _make_image because these are run in a subprocess,
        # whereas parse_output is run in the main python process that called hypy.Engine.run().
        # Additionally, the temporary directory gets deleted before parse_output is called.
        # Therefore, the data must be passed via stdout.

        prefix = "PYSIM_RESULT_FILE="
        for line in lines:
            if line.startswith(prefix):
                # import data printed from _run_tool()
                path = line[len(prefix):]
                with open(path, 'rb') as f:
                    self._result = pickle.load(f)
                os.remove(path)

        assert self._result is not None, "could not find {} in output".format(
            prefix)
        return self._result


if __name__ == "__main__":
    tool_main(PySimTool())
예제 #4
0
def _main():
    '''main func for running SpaceEx'''

    extra_args = [('-cfg', 'cfg file')]
    tool_main(SpaceExTool(), extra_args)
예제 #5
0
                    mode = m_waiting_tm_var
            elif mode == m_waiting_tm_var:
                if line.startswith('tm var'):
                    tm_var_line = line
                    mode = m_waiting_braces
            elif mode == m_waiting_braces:
                if line.startswith('{'):
                    mode = m_reading_model
                    model_definition = ""
                elif line.startswith('}'):
                    mode = m_waiting_mode
            elif mode == m_reading_model:
                if line.startswith('}'):
                    # taylor model finished
                    model_definition = remove_intervals_from_tm(model_definition)
                    rv.append(TaylorModel(mode_name, tm_var_line, model_definition))

                    mode = m_waiting_braces
                else:
                    model_definition += line + "\n"
    return rv               
 
if __name__ == "__main__":
    tool_main(FlowstarTool())






예제 #6
0
                print "Error Running HyCreate (java return code was " + str(
                    proc.returncode) + ")"

                if proc.returncode == 1:
                    print "Did you assign HYCREATE_BIN?"

                rv = RunCode.ERROR
        except OSError as e:
            print "Exception while trying to run HyCreate2: " + str(e)
            rv = RunCode.ERROR

        return rv

    def _make_image(self):
        '''makes the image after the tool runs, returns True on success'''
        rv = True

        from_path = "result/reachability.png"
        to_path = self.image_path

        try:
            shutil.copyfile(from_path, to_path)
        except IOError:
            rv = False

        return rv


if __name__ == "__main__":
    tool_main(HyCreateTool())
예제 #7
0
        '''make an image'''

        if self._pysim_model == None:
            raise RuntimeError('pysim_model unassigned; pysim needs _run_tool() to be called before _make_image()')

        plot = getattr(self._pysim_model, 'plot')
        plot(self._result, self._init_states, self.image_path)

        return True

    def parse_output(self, dummy_directory, dummy_lines, dummy_hypy_out):
        '''returns the parsed output object

        For pysim, this is the result of running simulate()
        '''

        return self._result
                
if __name__ == "__main__":
    tool_main(PySimTool())










예제 #8
0
                rv = RunCode.ERROR
        except OSError as e:
            print "Exception while trying to run Hylaa: " + str(e)
            rv = RunCode.ERROR

        return rv

    def _make_image(self):
        '''make an image. For Hylaa, the image will already be made during computation.'''

        return True

    def parse_output(self, dummy_directory, lines, dummy_hypy_out):
        '''returns the parsed output object

        For hylaa, this is the hylaa engine object of the most recent run.
        '''
        rv = {'safe': None}

        for line in reversed(lines):
            if 'Result: Error modes are NOT reachable.' in line:
                rv['safe'] = True
            elif 'Result: Error modes are reachable.' in line:
                rv['safe'] = False

        return rv


if __name__ == "__main__":
    tool_main(Hylaa2Tool())
예제 #9
0
            if proc.returncode != 0:
                print "Error Running HyCreate (java return code was " + str(proc.returncode) + ")"
                
                if proc.returncode == 1:
                    print "Did you assign HYCREATE_BIN?"
                    
                rv = RunCode.ERROR
        except OSError as e:
            print "Exception while trying to run HyCreate2: " + str(e)
            rv = RunCode.ERROR

        return rv

    def _make_image(self):
        '''makes the image after the tool runs, returns True on success'''
        rv = True

        from_path = "result/reachability.png"
        to_path = self.image_path

        try:
            shutil.copyfile(from_path, to_path)
        except IOError:
            rv = False

        return rv

if __name__ == "__main__":
    tool_main(HyCreateTool())
예제 #10
0
        params = [
            self.tool_path, "-k", "0", self.model_path, "--verbose",
            "--visualize"
        ]

        print "Calling dreach with params:", params

        if not run_check_stderr(params):
            rv = RunCode.ERROR

        return rv

    def _copy_model(self, temp_folder):
        '''copy the model to the temp folder and sets self.model_path
        overriden to ensure .drh extension
        '''
        model_name = os.path.basename(self.original_model_path)

        if not model_name.endswith(".drh"):
            model_name += ".drh"

        self.model_path = os.path.join(temp_folder, model_name)
        shutil.copyfile(self.original_model_path, self.model_path)


if __name__ == "__main__":
    print "Starting dReach. If you kill the tool early, be sure to kill any spawned " \
      "subprocesses ('killall dReal')."

    tool_main(DReachTool())