From cb6ddbf8cb4006e5b0c3d7f3f99b041ce71ce893 Mon Sep 17 00:00:00 2001 From: Winnus <winnus@posteo.de> Date: Fri, 22 Sep 2023 16:40:13 +0200 Subject: [PATCH] More reasonable text output --- src/PyGMA.py | 12 ++++++++-- .../config_logical_gate_construction.py | 2 +- src/components/evolutionary_phase.py | 2 +- src/core/controller.py | 24 ++++++++++++++++--- src/core/mpi_worker.py | 2 +- 5 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/PyGMA.py b/src/PyGMA.py index bf0e970..e0cb943 100755 --- a/src/PyGMA.py +++ b/src/PyGMA.py @@ -27,7 +27,13 @@ def controller(): # evolution for all phases GAController.evolve() + + # ---------------------- + # Evolution has finished + # ---------------------- + print() print("Evolve finished (fitness or epoch criterion met)") + print('-------------------------------------------------') # todo find the population with the best gene @@ -35,10 +41,12 @@ def controller(): # this is started inside the controller in get_fittest_individuals() # use the below code there to implement the function... fit_per_pop = GAController.get_population_fitness(mean=False) - m = max(fit_per_pop) - i = np.where(fit_per_pop == m) + # m = max(fit_per_pop) + # i = np.where(fit_per_pop == m) print(f'Population fitness:{fit_per_pop}') + print() + print() # print(GAController.populations[0].individuals[0].fitness) diff --git a/src/components/config_logical_gate_construction.py b/src/components/config_logical_gate_construction.py index d0d46c4..3c6b84b 100755 --- a/src/components/config_logical_gate_construction.py +++ b/src/components/config_logical_gate_construction.py @@ -179,7 +179,7 @@ CONFIG_CIRCUIT_EVOLVE = { # -------------- # defining the phases that will be sequantially evolved 'evolutionary_phases': [ - PHASE0, PHASE0 + PHASE0 ] } diff --git a/src/components/evolutionary_phase.py b/src/components/evolutionary_phase.py index 020196f..3b28c13 100755 --- a/src/components/evolutionary_phase.py +++ b/src/components/evolutionary_phase.py @@ -62,7 +62,7 @@ class Simple_evolutionary_phase(Evolutionary_phase): if max_fitness > 90.9: return True - if epochs > 30000: + if epochs > 3: return True return False diff --git a/src/core/controller.py b/src/core/controller.py index 5b98dec..2291b2f 100755 --- a/src/core/controller.py +++ b/src/core/controller.py @@ -322,6 +322,9 @@ class Controller: # ---------- # phase epochs # ---------- + # save timings + ts_op_stack = [] + ts_evaluate = [] while not evolutionary_phase.completed(self.get_population_fitness(), self.epochs): # conduct a new epoch # ------------------- @@ -332,6 +335,7 @@ class Controller: t_op_stack = time.time() self.__apply_operator_stack() t_op_stack = time.time() - t_op_stack + ts_op_stack.append(t_op_stack) # instantiate individuals (get them a fitness value) # tell them the phase index becaus the worker processes @@ -340,11 +344,15 @@ class Controller: t_evaluate = time.time() self.__instantiate_individuals(phase_index=p_index) t_evaluate = time.time() - t_evaluate + ts_evaluate.append(t_evaluate) # check if algorithm stagnates - # IMP + # To be Implemented IMP - # fusion islands but what is the condition? + # fusion islands + # meaning that you take two or more islands and combine them + # into a new island + # but what is the condition? # whenever a new phase happens the phase can do # this on their own. @@ -366,6 +374,15 @@ class Controller: # ---------- print(f'Finished phase {evolutionary_phase}') print('--------------------------------') + print(f'phase epochs: {self.epochs}') + print(f'min Operator Stack time: {min(ts_op_stack)}') + print(f'max Operator Stack time: {max(ts_op_stack)}') + print(f'mean Operator Stack time: {np.mean(ts_op_stack)}') + print(f'min Fitness Evaluation time: {min(ts_evaluate)}') + print(f'max Fitness Evaluation time: {max(ts_evaluate)}') + print(f'mean Fitness Evaluation time: {np.mean(ts_evaluate)}') + print(f'Pop max fitness {self.get_population_fitness()}') + print() # print('--------------------------------') # Evoluting finised @@ -377,7 +394,8 @@ class Controller: from core.mpi_tags import mpi_tags comm = MPI.COMM_WORLD world_size = comm.Get_size() - print('stopping mpi workers') + print() + print('MPI was used, stopping mpi workers...') for w_index in range(1, world_size): comm.send(False, dest=w_index, tag=mpi_tags.CONTINUE_PROCESSING) diff --git a/src/core/mpi_worker.py b/src/core/mpi_worker.py index 3c453da..3c1ae82 100755 --- a/src/core/mpi_worker.py +++ b/src/core/mpi_worker.py @@ -15,7 +15,7 @@ class MPI_worker(): # worker # loop until stop is signalled while True: - print(f'worker {self.rank} loop') + # print(f'worker {self.rank} loop') # signaling that we are waiting for new work self.comm.isend(None, dest=0, tag=mpi_tags.IDLE) -- GitLab