Пример #1
0
    def save(self, saving_method='dict', fn=None):

        # log saving method
        awelogger.logger.info('Saving trial ' + self.__name + ' using ' +
                              saving_method)

        # set savefile name to trial name if unspecified
        if not fn:
            fn = self.__name

        # choose correct function for saving method
        if saving_method == 'awe':
            self.save_to_awe(fn)
        elif saving_method == 'dict':
            self.save_to_dict(fn)
        else:
            awelogger.logger.error(
                saving_method + ' is not a supported saving method. Trial ' +
                self.__name + ' could not be saved!')

        # log that save is complete
        awelogger.logger.info('Trial (%s) saved.', self.__name)
        awelogger.logger.info('')
        awelogger.logger.info(print_op.hline('&'))
        awelogger.logger.info(print_op.hline('&'))
        awelogger.logger.info('')
        awelogger.logger.info('')
Пример #2
0
    def solve_homotopy(self, nlp, model, options, final_homotopy_step,
                       visualization):

        logging.info('solve with homotopy procedure...')
        logging.info('')

        # do not consider homotopy steps after specified final_homotopy_step
        final_index = self.__schedule['homotopy'].index(final_homotopy_step)
        homotopy_schedule = self.__schedule['homotopy'][:final_index + 1]

        self.__solve_succeeded = True

        # iterate over homotopy schedule
        for step_name in homotopy_schedule:

            if self.__solve_succeeded:

                timer = time.time()
                self.solve_specific_homotopy_step(step_name, nlp, model,
                                                  options, visualization)
                self.update_runtime_info(timer, step_name)

        logging.info(print_op.hline('#'))

        return None
Пример #3
0
    def solve_with_vortex_linearization_setup(self, nlp, model, options, final_homotopy_step, visualization):

        awelogger.logger.info('solve set-up problem with vortex linearization...')
        awelogger.logger.info('')

        self.__solve_succeeded = True

        # solve set-up problem with homotopy (omitting the induction steps)
        self.solve_homotopy(nlp, model, options, final_homotopy_step, visualization)

        awelogger.logger.info(print_op.hline('#'))

        return None
Пример #4
0
def check_display(check_condition, check_name, label_pass, label_warning):

    logging.debug('')
    logging.debug(print_op.hline('*'))

    if check_condition:
        logging.debug('{0:>15}:'.format(check_name + ' PASSED') + ' ' +
                      label_pass)
    else:
        logging.debug('{0:>15}:'.format(check_name + ' WARNING') + ' ' +
                      label_warning)

    return None
Пример #5
0
    def solve_general_homotopy_step(self, step_name, counter, options, nlp,
                                    model, solver, visualization):

        if self.__solve_succeeded:

            logging.info(print_op.hline("#"))
            logging.info(self.__schedule['labels'][step_name][counter])
            logging.info('')

            [self.__cost_update_counter, self.__p_fix_num
             ] = scheduling.update_cost(self.__schedule, step_name, counter,
                                        self.__cost_update_counter,
                                        self.__p_fix_num)

            [self.__bound_update_counter, self.__V_bounds
             ] = scheduling.update_bounds(self.__schedule, step_name, counter,
                                          self.__bound_update_counter,
                                          self.__V_bounds, model, nlp)

            # hand over the parameters to the solver
            self.__arg['p'] = self.__p_fix_num

            # bounds on x
            self.__arg['ubx'] = self.__V_bounds['ub']
            self.__arg['lbx'] = self.__V_bounds['lb']

            # solve
            self.__solution = solver(**self.__arg)
            self.__stats = solver.stats()

            # add up iterations of multi-step homotopies
            if step_name not in list(self.__iterations.keys()):
                self.__iterations[step_name] = 0.
            self.__iterations[step_name] += self.__stats['iter_count']

            self.generate_outputs(nlp, self.__solution)

            self.allow_next_homotopy_step()

            diagnostics.print_runtime_values(self.__stats)
            diagnostics.print_homotopy_values(nlp, self.__solution,
                                              self.__p_fix_num)
            diagnostics.health_check(nlp, self.__solution, self.__arg, options,
                                     self.__solve_succeeded)

            if step_name in self.__debug_locations or self.__debug_locations == 'all':
                V_plot = nlp.V(self.__solution['x'])
                self.__make_debug_plot(V_plot, nlp, visualization, step_name)

        return None
Пример #6
0
    def solve_with_vortex_linearization_iterative(self, nlp, formulation, model, options, vortex_linearization_file, final_homotopy_step, visualization):

        awelogger.logger.info('solve iterative problem with vortex linearization...')
        awelogger.logger.info('')

        self.__solve_succeeded = True

        warmstart_solution_dict = save_op.extract_solution_dict_from_file(vortex_linearization_file)
        self.modify_args_for_warmstart(nlp, formulation, model, options, visualization, warmstart_solution_dict=warmstart_solution_dict)
        self.modify_schedule_for_vortex_linearization_iterative(final_homotopy_step, nlp, model)

        # solve homotopy with warmstart
        self.solve_homotopy(nlp, model, options, final_homotopy_step, visualization)

        awelogger.logger.info(print_op.hline('#'))

        return None
Пример #7
0
    def solve_from_warmstart(self, nlp, formulation, model, options, warmstart_file, final_homotopy_step, visualization):

        awelogger.logger.info('solve from warmstart...')
        awelogger.logger.info('')

        self.__solve_succeeded = True

        warmstart_solution_dict = save_op.extract_solution_dict_from_file(warmstart_file)
        self.modify_args_for_warmstart(nlp, formulation, model, options, visualization, warmstart_solution_dict = warmstart_solution_dict)
        self.modify_schedule_for_warmstart(final_homotopy_step, warmstart_solution_dict, nlp, model)

        # solve homotopy with warmstart
        self.solve_homotopy(nlp, model, options, final_homotopy_step, visualization)

        awelogger.logger.info(print_op.hline('#'))

        return None
Пример #8
0
    def solve_from_warmstart(self, nlp, model, options, warmstart_file,
                             final_homotopy_step, visualization):

        logging.info('solve from warmstart...')
        logging.info('')

        self.__solve_succeeded = True

        warmstart_trial = self.extract_warmstart_trial(warmstart_file)
        self.set_warmstart_args(warmstart_trial, nlp)
        self.define_warmstart_schedule(final_homotopy_step, warmstart_trial,
                                       nlp, model)

        # solve homotopy with warmstart
        self.solve_homotopy(nlp, model, options, final_homotopy_step,
                            visualization)

        logging.info(print_op.hline('#'))

        return None