Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parallelization with MOEAD #683

Closed
Kookaburra13 opened this issue Jan 30, 2025 · 2 comments
Closed

Parallelization with MOEAD #683

Kookaburra13 opened this issue Jan 30, 2025 · 2 comments
Assignees
Labels

Comments

@Kookaburra13
Copy link

Hi ! Thanks for the package, it is really helpful and easy to use.

I have a problem with 19 variables and 3 objectives, NSGA3 works perfectly, and I wanted to compare with MOEAD. However, the parallelization doesn't work when replacing the algorithm by MOEAD (and adding some arguments such as n_neighbors and prob_neighbor_mating). Is it specific to MOEAD ?

Here is the code for NSGA3. I tried MOEAD and ParallelMOEAD instead of NSGA3, but parallelization doesn't work for both.

class MyProblem(Problem):
    def __init__(self, **kwargs):
        super().__init__(n_var=19, n_obj=3, elementwise_evaluation=True,
                         xl=np.array([0.16, 0.0006, 500, 0.0144, 9, 0.50, 0.5, 0.065, 0.94, 0.008,
                                      0.72, 0, 1.26, 0.04, 20, 0.0, 0.3, 0.0, 0.0]),
                         xu=np.array([0.5, 0.002, 3500, 0.0216, 18, 0.57, 0.9, 0.075, 0.99, 0.02,
                                      0.95, 5, 1.54, 0.135, 50, 1, 0.5, 1.0, 1.0]))
        self.Variete = 'Skyscraper'
        self.names = ['alfa', 'Xn', 'Do_Leun', 'SpLAI', 'm_Leun', 'A_brunt', 'a', 'B_brunt',
                      'epsilon_leaf', 'b_Leun', 'sigma_NIR', 'PenPar2', 'NNI_crit',
                      'K_sat_1', 'ShldResC', 'delta_Leun', 'k_net', 'SOrgPhotEff', 'StemPhotEff']
        # Getting measurements
        self.MeasWSOrg, self.MeasNEE, self.MeasLE, self.ObsDate = funcs.measured_data(self.Variete)

    def _evaluate(self, x, out):
        with ThreadPool(23) as pool:
            # Getting model ouputs when there are measurements and rRMSE computation
            def run_with_id(idx, param_values):
                return funcs.running_daisy(param_names=self.names, ObsDate=self.ObsDate,
                                           Variete=self.Variete, MeasWSOrg=self.MeasWSOrg,
                                           MeasNEE=self.MeasNEE, MeasLE=self.MeasLE,
                                           x=param_values[0], thread_id=idx)
            params = [[x[k]] for k in range(len(x))]
            inputs_with_ids = [(idx, param) for idx, param in enumerate(params)]
            outputs = pool.starmap(run_with_id, inputs_with_ids)
            out["F"] = np.array(outputs)
if __name__ == "__main__":
    problem = MyProblem()
    initial_X = np.array(pd.read_csv('pop.csv').iloc[:, 1:])

    ref_dirs = get_reference_directions("energy", 3, 200, seed=1)
    algorithm = NSGA3(ref_dirs=ref_dirs, elminate_duplicates=True, sampling=initial_X,
                      crossover=SBX(prob=0.8, eta=30), mutation=PM(eta=20))

    res = minimize(problem, algorithm, termination=('n_gen', 1000), seed=1,
                   verbose=True)
    print('Processes:', res.exec_time)

Thanks !

@blankjul blankjul self-assigned this Feb 1, 2025
@blankjul blankjul added the bug label Feb 1, 2025
@blankjul
Copy link
Collaborator

blankjul commented Feb 1, 2025

Can you please post some source code to reproduce your error?
(please use a test problem and avoid any imports that are not from standard libraries)

@Kookaburra13
Copy link
Author

Actually there is no error, the code runs but without parallelization. Using MOEAD requires 30 hours for 100 generations while NSGA3 requires around 3 hours (also for 100 generations).

Regarding the standard libraries, if you refer to funcs, this is just another part of my code.

I'll keep searching, try a test problem and get back to you if necessary, thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants