def restore(self):
        #load state
        data = State.get_data(self.version, self.StateID)

        for inputsize in data:
            try:
                algdata = inputsize["Methodology"]
            except:
                inputsize = {
                    "Input": self.newinput,
                    "BenchmarkInput": self.benchmark_input,
                    "Methodology": {},
                }
                State.checkpoint(self.version, self.StateID, data)
                continue

            if not (algdata in [None, {}, []]):
                self.benchmark_input = inputsize["BenchmarkInput"]
                self.benchmark_solutions = None
                for sol in self.profiling_solutions:
                    if sol["Input"] == self.benchmark_input:
                        self.benchmark_solutions = sol["Configurations"]

                if not self.benchmark_solutions:
                    #the benchmark input from the save file doesn't have any solution explored
                    self.benchmark_input = self.profiling_solutions[-1][
                        "Input"]
                    self.benchmark_solutions = self.profiling_solutions[-1][
                        "Configurations"]

                self.strategy.update_state(algdata)
                #if profiling with the input size was finished go to the next one
                if not self.strategy.stop_condition():
                    break
        return data
    def restore(self):
        print "Restoring Profile."
        data = State.get_data(self.version, self.StateID)
        q = False
        for inputsize in data:
            try:
                algdata = inputsize["Algorithm"]
            except:

                inputsize = {
                    "ResourceVariables": self.variables,
                    "InputParameters": self.parameters,
                    "Algorithm": {}
                }
                State.checkpoint(self.version, self.StateID, data)
                break
            if algdata != None and algdata != []:

                if inputsize["InputParameters"] == self.parameters:
                    q = True
                    self.strategy.update_state(algdata)
                    #if profiling with the input size was finished go to the next one
                    if not self.strategy.stop_condition():
                        break
        if not q:
            return []
        return data
示例#3
0
    def recieve(self):
        buff = b''
        while True:
            if len(buff) < 3:
                buff += self.connection.recv(3)

            # Package metadata: type and length
            package_type, package_len = struct.unpack('<BH', buff[0:3])
            buff = buff[3:]

            # recieve until the package is complete.
            while len(buff) < package_len:
                buff += self.connection.recv(package_len)

            try:
                if package_type == PACKAGE_TYPE_STATUS:
                    self.main.update_state(State(bytes(buff)))
                elif package_type == PACKAGE_TYPE_RESPONSE:
                    self.response_holder.set(bytes(buff))
                    self.recv_event.set()
                else:
                    self.main.ui.print(
                        'Wrong package recieved: 0x{:02x}'.format(
                            package_type))
            except Exception as e:
                self.main.ui.print(repr(e))

            # remove full packages from buffer:
            buff = buff[package_len:]
 def restore(self):
     if self.Data == {}:
         #load state
         for v in self.versions:
             version = ".".join(map(lambda s: str(s), v))
             data = State.get_data(version, self.StateID)
             if data in [None, {}, []]:
                 continue
             self.Data[version] = data[0]
    def save_state(self):
        print "Save state to file."
        data = State.get_data(self.version, self.StateID)
        algdata = self.strategy.get_state()
        info = {
            "Input": self.newinput,
            "BenchmarkInput": self.benchmark_input,
            "Methodology": algdata
        }
        q = False
        for inputsize in data:
            if inputsize["Input"] == self.newinput:
                inputsize.update(info)
                q = True
        if not q:
            data.append(info)

        State.checkpoint(self.version, self.StateID, data)
    def save_state(self):
        print "Save state to file."
        data = State.get_data(self.version, self.StateID)
        algdata = self.strategy.get_state()
        info = {
            "ResourceVariables": self.variables,
            "InputParameters": self.parameters,
            "Algorithm": algdata
        }

        q = False
        for inputsize in data:
            if inputsize["InputParameters"] == self.parameters:
                inputsize.update(info)
                q = True
        if not q:
            data.append(info)

        State.checkpoint(self.version, self.StateID, data)
    def get_explored_solutions(self):
        data = State.get_data(self.version, self.StateID)

        if data in [None, []]:
            return self.variables, None

        solutions = []

        for info in data:
            solutions.append({
                "Input": info["InputParameters"],
                "Configurations": info["Algorithm"]["solutions"]
            })

        return self.variables, solutions
示例#8
0
    def query_initial_status(self, connection):
        """ Sends an initial status update to retrieve the current state. """
        command_bytes = self.command_manager.get_command(
            'adc update state').get_command_bytes('')
        connection.send(command_bytes)

        # Metadata: type and length
        package_descriptor = connection.recv(3)
        package_type, package_len = struct.unpack('<BH', package_descriptor)

        # Get content of the package.
        buff = b''
        while len(buff) < package_len:
            buff += connection.recv(package_len - len(buff))

        if package_type == PACKAGE_TYPE_RESPONSE:
            status, = struct.unpack('<B', buff[0:1])
            if status != 0:
                self.ui.print("Couldn't get a first status update")
            else:
                self.update_state(State(buff[1:]))
        else:
            self.ui.print("Couldn't get a first status update")
    def model_version(v):
        version = ".".join(map(lambda s: str(s), v))
        #LOOK FOR PROFILE DATA
        profile_dir = os.path.abspath(
            os.path.join(os.path.dirname(__file__), "../profiles"))
        data_file = "%s/%s-%s.pf" % (profile_dir, Controller.application.Name,
                                     version)

        State.load(version, data_file)

        current_state = State.get_current_state(version)

        if current_state == 0:
            print "Profiling state."
            #profiling with static input phase
            #get the first small input size to profile with
            parameters = VariableMapper(
                Controller.application.getParameterVariableMap(
                )).lower_bound_values()
            #start profiler to create a model
            Profiler.StateID = current_state
            profiler = Profiler(Controller.application,
                                version,
                                parameters=parameters)
            try:
                profiler.run()
            except:
                traceback.print_exc()
                print 'Profiler interrupted. Exiting'
                return False, None
            State.change_state(version)
            current_state = State.get_current_state(version)
            State.checkpoint(version, current_state)

        #get the input size from the SLO for which to make prediction
        input_size = Controller.application.getExecutionParameters(
            Controller.slo.ExecutionArguments)
        modeller = None
        if current_state >= 1:
            print "Modelling state."
            #profiling variable input
            #modelling state - use function to predict
            Extrapolator.StateID = current_state
            variables, solutions_identified_in_profiling = Profiler(
                Controller.application, version).get_explored_solutions()

            print len(solutions_identified_in_profiling)

            modeller = Extrapolator(Controller.application, version, variables,
                                    solutions_identified_in_profiling,
                                    input_size)
            try:
                modeller.run()
            except:
                traceback.print_exc()
                print 'Modeller interrupted. Exiting'
                return False, None
            State.change_state(version)
            current_state = State.get_current_state(version)

        print "Current state", current_state
        State.save(version)
        #retrieve the model - tuple (function,constraints)
        model = modeller.get_model()
        return True, model