From 1e0ae97cfdd26a29ee9b66619e8d83bb4c6b51fc Mon Sep 17 00:00:00 2001 From: Winni <winnus@posteo.de> Date: Tue, 4 Jul 2023 16:32:49 +0200 Subject: [PATCH] Added Diagramm, Changed folder structure Classes are now splittet into core and components, where core is internal and components are user defined --- diagramms/User_interface.drawio | 160 +++++++++++++++++++++ src/PyGMA.py | 5 +- src/{ => components}/evolutionary_phase.py | 5 +- src/{ => components}/experiment.py | 9 +- src/{ => components}/genetic_operators.py | 0 src/config.py | 10 +- src/{ => core}/controller.py | 6 +- src/{ => core}/individual.py | 0 src/{ => core}/mpi_tags.py | 0 src/{ => core}/mpi_worker.py | 15 +- src/{ => core}/population.py | 4 +- src/{ => core}/population_old.py | 0 src/{ => testing}/Evo.ipynb | 0 src/{ => testing}/PyGMA.ipynb | 0 src/{ => testing}/mpi_test.py | 0 src/{ => testing}/testing_notebook.ipynb | 0 16 files changed, 188 insertions(+), 26 deletions(-) create mode 100755 diagramms/User_interface.drawio mode change 100644 => 100755 src/PyGMA.py rename src/{ => components}/evolutionary_phase.py (93%) rename src/{ => components}/experiment.py (92%) rename src/{ => components}/genetic_operators.py (100%) rename src/{ => core}/controller.py (99%) rename src/{ => core}/individual.py (100%) rename src/{ => core}/mpi_tags.py (100%) mode change 100644 => 100755 rename src/{ => core}/mpi_worker.py (77%) mode change 100644 => 100755 rename src/{ => core}/population.py (97%) rename src/{ => core}/population_old.py (100%) rename src/{ => testing}/Evo.ipynb (100%) rename src/{ => testing}/PyGMA.ipynb (100%) rename src/{ => testing}/mpi_test.py (100%) mode change 100644 => 100755 rename src/{ => testing}/testing_notebook.ipynb (100%) diff --git a/diagramms/User_interface.drawio b/diagramms/User_interface.drawio new file mode 100755 index 0000000..728ca68 --- /dev/null +++ b/diagramms/User_interface.drawio @@ -0,0 +1,160 @@ +<mxfile host="Electron" modified="2023-07-04T14:30:41.800Z" agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/21.2.8 Chrome/112.0.5615.165 Electron/24.2.0 Safari/537.36" etag="A4Cifa2M0oYHXV9wZ0hg" version="21.2.8" type="device"> + <diagram name="Page-1" id="d9ukyp2v95sI_arlxVt0"> + <mxGraphModel dx="2537" dy="995" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0"> + <root> + <mxCell id="0" /> + <mxCell id="1" parent="0" /> + <mxCell id="ehnrpR-e_t0s3ppQeY-d-56" value="" style="rounded=1;whiteSpace=wrap;html=1;fillColor=none;strokeColor=#2F5B7C;strokeWidth=3;" vertex="1" parent="1"> + <mxGeometry x="-720" y="105" width="410" height="435" as="geometry" /> + </mxCell> + <mxCell id="ehnrpR-e_t0s3ppQeY-d-1" value="<b>Controller</b>" style="rounded=1;whiteSpace=wrap;html=1;strokeColor=none;fillColor=#2F5B7C;fontColor=#ffffff;" vertex="1" parent="1"> + <mxGeometry x="10" y="290" width="120" height="60" as="geometry" /> + </mxCell> + <mxCell id="ehnrpR-e_t0s3ppQeY-d-2" value="<b>config</b>" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#008a00;fontColor=#ffffff;strokeColor=#005700;" vertex="1" parent="1"> + <mxGeometry x="280" y="290" width="120" height="60" as="geometry" /> + </mxCell> + <mxCell id="ehnrpR-e_t0s3ppQeY-d-3" value="<b>evolutionary_phase</b>" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#008a00;fontColor=#ffffff;strokeColor=#005700;" vertex="1" parent="1"> + <mxGeometry x="510" y="160" width="120" height="60" as="geometry" /> + </mxCell> + <mxCell id="ehnrpR-e_t0s3ppQeY-d-4" value="<b>experiment</b>" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#008a00;fontColor=#ffffff;strokeColor=#005700;" vertex="1" parent="1"> + <mxGeometry x="510" y="290" width="120" height="60" as="geometry" /> + </mxCell> + <mxCell id="ehnrpR-e_t0s3ppQeY-d-5" value="<b>genetic_operators</b>" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#008a00;fontColor=#ffffff;strokeColor=#005700;" vertex="1" parent="1"> + <mxGeometry x="510" y="420" width="120" height="60" as="geometry" /> + </mxCell> + <mxCell id="ehnrpR-e_t0s3ppQeY-d-6" value="<b>individual</b>" style="rounded=1;whiteSpace=wrap;html=1;strokeColor=none;fillColor=#2F5B7C;fontColor=#ffffff;" vertex="1" parent="1"> + <mxGeometry x="-300" y="206" width="120" height="60" as="geometry" /> + </mxCell> + <mxCell id="ehnrpR-e_t0s3ppQeY-d-7" value="<b>population</b>" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#2F5B7C;fontColor=#ffffff;strokeColor=none;" vertex="1" parent="1"> + <mxGeometry x="-300" y="105" width="120" height="60" as="geometry" /> + </mxCell> + <mxCell id="ehnrpR-e_t0s3ppQeY-d-10" value="" style="edgeStyle=none;rounded=0;jumpStyle=none;html=1;shadow=0;labelBackgroundColor=none;startArrow=none;startFill=0;endArrow=classic;endFill=1;jettySize=auto;orthogonalLoop=1;strokeColor=#2F5B7C;strokeWidth=3;fontFamily=Helvetica;fontSize=16;fontColor=#23445D;spacing=5;exitX=0;exitY=0;exitDx=0;exitDy=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="ehnrpR-e_t0s3ppQeY-d-1" target="ehnrpR-e_t0s3ppQeY-d-6"> + <mxGeometry relative="1" as="geometry"> + <mxPoint x="-24" y="319.40999999999997" as="sourcePoint" /> + <mxPoint x="-150" y="319.40999999999997" as="targetPoint" /> + </mxGeometry> + </mxCell> + <mxCell id="ehnrpR-e_t0s3ppQeY-d-12" value="" style="edgeStyle=none;rounded=0;jumpStyle=none;html=1;shadow=0;labelBackgroundColor=none;startArrow=none;startFill=0;endArrow=classic;endFill=1;jettySize=auto;orthogonalLoop=1;strokeColor=#2F5B7C;strokeWidth=3;fontFamily=Helvetica;fontSize=16;fontColor=#23445D;spacing=5;exitX=0.25;exitY=0;exitDx=0;exitDy=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="ehnrpR-e_t0s3ppQeY-d-1" target="ehnrpR-e_t0s3ppQeY-d-7"> + <mxGeometry relative="1" as="geometry"> + <mxPoint x="-24" y="179.41" as="sourcePoint" /> + <mxPoint x="-150" y="179" as="targetPoint" /> + </mxGeometry> + </mxCell> + <mxCell id="ehnrpR-e_t0s3ppQeY-d-15" value="" style="edgeStyle=none;rounded=1;jumpStyle=none;html=1;shadow=0;labelBackgroundColor=none;startArrow=none;startFill=0;jettySize=auto;orthogonalLoop=1;strokeColor=#005700;strokeWidth=3;fontFamily=Helvetica;fontSize=14;fontColor=#FFFFFF;spacing=5;fontStyle=1;fillColor=#008a00;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=0.75;entryY=1;entryDx=0;entryDy=0;" edge="1" parent="1" source="ehnrpR-e_t0s3ppQeY-d-5" target="ehnrpR-e_t0s3ppQeY-d-2"> + <mxGeometry relative="1" as="geometry"> + <mxPoint x="390" y="412.5" as="sourcePoint" /> + <mxPoint x="480" y="470" as="targetPoint" /> + </mxGeometry> + </mxCell> + <mxCell id="ehnrpR-e_t0s3ppQeY-d-16" value="" style="edgeStyle=none;rounded=1;jumpStyle=none;html=1;shadow=0;labelBackgroundColor=none;startArrow=none;startFill=0;jettySize=auto;orthogonalLoop=1;strokeColor=#005700;strokeWidth=3;fontFamily=Helvetica;fontSize=14;fontColor=#FFFFFF;spacing=5;fontStyle=1;fillColor=#008a00;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="ehnrpR-e_t0s3ppQeY-d-4" target="ehnrpR-e_t0s3ppQeY-d-2"> + <mxGeometry relative="1" as="geometry"> + <mxPoint x="898" y="448" as="sourcePoint" /> + <mxPoint x="500" y="240" as="targetPoint" /> + </mxGeometry> + </mxCell> + <mxCell id="ehnrpR-e_t0s3ppQeY-d-17" value="" style="edgeStyle=none;rounded=1;jumpStyle=none;html=1;shadow=0;labelBackgroundColor=none;startArrow=none;startFill=0;jettySize=auto;orthogonalLoop=1;strokeColor=#005700;strokeWidth=3;fontFamily=Helvetica;fontSize=14;fontColor=#FFFFFF;spacing=5;fontStyle=1;fillColor=#008a00;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=0.75;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="ehnrpR-e_t0s3ppQeY-d-3" target="ehnrpR-e_t0s3ppQeY-d-2"> + <mxGeometry relative="1" as="geometry"> + <mxPoint x="908" y="458" as="sourcePoint" /> + <mxPoint x="320" y="200" as="targetPoint" /> + </mxGeometry> + </mxCell> + <mxCell id="ehnrpR-e_t0s3ppQeY-d-18" value="<b>MPI_tags</b>" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#2F5B7C;fontColor=#ffffff;strokeColor=none;" vertex="1" parent="1"> + <mxGeometry x="-300" y="480" width="120" height="60" as="geometry" /> + </mxCell> + <mxCell id="ehnrpR-e_t0s3ppQeY-d-19" value="" style="edgeStyle=none;rounded=0;jumpStyle=none;html=1;shadow=0;labelBackgroundColor=none;startArrow=none;startFill=0;endArrow=classic;endFill=1;jettySize=auto;orthogonalLoop=1;strokeColor=#2F5B7C;strokeWidth=3;fontFamily=Helvetica;fontSize=16;fontColor=#23445D;spacing=5;exitX=0.25;exitY=1;exitDx=0;exitDy=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="ehnrpR-e_t0s3ppQeY-d-1" target="ehnrpR-e_t0s3ppQeY-d-18"> + <mxGeometry relative="1" as="geometry"> + <mxPoint x="20" y="330" as="sourcePoint" /> + <mxPoint x="-170" y="320" as="targetPoint" /> + </mxGeometry> + </mxCell> + <mxCell id="ehnrpR-e_t0s3ppQeY-d-20" value="" style="edgeStyle=none;rounded=1;jumpStyle=none;html=1;shadow=0;labelBackgroundColor=none;startArrow=none;startFill=0;jettySize=auto;orthogonalLoop=1;strokeColor=#005700;strokeWidth=3;fontFamily=Helvetica;fontSize=14;fontColor=#FFFFFF;spacing=5;fontStyle=1;fillColor=#008a00;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;enumerate=0;" edge="1" parent="1" source="ehnrpR-e_t0s3ppQeY-d-2" target="ehnrpR-e_t0s3ppQeY-d-1"> + <mxGeometry relative="1" as="geometry"> + <mxPoint x="300" y="470" as="sourcePoint" /> + <mxPoint x="160" y="370" as="targetPoint" /> + </mxGeometry> + </mxCell> + <mxCell id="ehnrpR-e_t0s3ppQeY-d-27" value="" style="image;aspect=fixed;html=1;points=[];align=center;fontSize=12;image=img/lib/azure2/identity/Users.svg;" vertex="1" parent="1"> + <mxGeometry x="317.14" y="459" width="45.71" height="50" as="geometry" /> + </mxCell> + <mxCell id="ehnrpR-e_t0s3ppQeY-d-40" value="Configuration<br>Objects" style="text;html=1;align=left;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="1"> + <mxGeometry x="170" y="281" width="90" height="40" as="geometry" /> + </mxCell> + <mxCell id="ehnrpR-e_t0s3ppQeY-d-41" value="Apply_operator_stacks" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;rotation=45;" vertex="1" parent="1"> + <mxGeometry x="-690" y="272" width="150" height="30" as="geometry" /> + </mxCell> + <mxCell id="ehnrpR-e_t0s3ppQeY-d-42" value="Conduct phase specific experiment" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="1"> + <mxGeometry x="-685" y="331" width="210" height="30" as="geometry" /> + </mxCell> + <mxCell id="ehnrpR-e_t0s3ppQeY-d-43" value="Stagnation check" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;rotation=15;" vertex="1" parent="1"> + <mxGeometry x="-655" y="371" width="120" height="30" as="geometry" /> + </mxCell> + <mxCell id="ehnrpR-e_t0s3ppQeY-d-44" value="Create new populations (Island Fusion)" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;rotation=-15;" vertex="1" parent="1"> + <mxGeometry x="-575" y="341" width="230" height="30" as="geometry" /> + </mxCell> + <mxCell id="ehnrpR-e_t0s3ppQeY-d-45" value="Start new phase" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;rotation=-90;" vertex="1" parent="1"> + <mxGeometry x="-535" y="272" width="110" height="30" as="geometry" /> + </mxCell> + <mxCell id="ehnrpR-e_t0s3ppQeY-d-46" value="Check if phase is finished" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="1"> + <mxGeometry x="-630" y="421" width="160" height="30" as="geometry" /> + </mxCell> + <mxCell id="ehnrpR-e_t0s3ppQeY-d-47" value="Sort individuals based on their fitness" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;rotation=-45;" vertex="1" parent="1"> + <mxGeometry x="-500" y="241" width="220" height="30" as="geometry" /> + </mxCell> + <mxCell id="ehnrpR-e_t0s3ppQeY-d-48" value="Determine&nbsp; if to use MPI. MPI Futures, Python Futures, none at all" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;rotation=-15;" vertex="1" parent="1"> + <mxGeometry x="-675" y="451" width="370" height="30" as="geometry" /> + </mxCell> + <mxCell id="ehnrpR-e_t0s3ppQeY-d-49" value="Pass work to MPI workers" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;rotation=45;" vertex="1" parent="1"> + <mxGeometry x="-730" y="411" width="160" height="30" as="geometry" /> + </mxCell> + <mxCell id="ehnrpR-e_t0s3ppQeY-d-50" value="Apply phase start operators" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;rotation=-30;" vertex="1" parent="1"> + <mxGeometry x="-475" y="371" width="170" height="30" as="geometry" /> + </mxCell> + <mxCell id="ehnrpR-e_t0s3ppQeY-d-51" value="Initialize populations" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;rotation=-15;" vertex="1" parent="1"> + <mxGeometry x="-580" y="131" width="130" height="30" as="geometry" /> + </mxCell> + <mxCell id="ehnrpR-e_t0s3ppQeY-d-52" value="Instantiate individuals" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;rotation=30;" vertex="1" parent="1"> + <mxGeometry x="-460" y="131" width="140" height="30" as="geometry" /> + </mxCell> + <mxCell id="ehnrpR-e_t0s3ppQeY-d-53" value="Return the fittest n individuals" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;rotation=-10;" vertex="1" parent="1"> + <mxGeometry x="-570" y="161" width="180" height="30" as="geometry" /> + </mxCell> + <mxCell id="ehnrpR-e_t0s3ppQeY-d-54" value="Population mean/max fitness values" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;rotation=15;" vertex="1" parent="1"> + <mxGeometry x="-705" y="221" width="220" height="30" as="geometry" /> + </mxCell> + <mxCell id="ehnrpR-e_t0s3ppQeY-d-58" value="" style="edgeStyle=none;rounded=0;jumpStyle=none;html=1;shadow=0;labelBackgroundColor=none;startArrow=none;startFill=0;endArrow=classic;endFill=1;jettySize=auto;orthogonalLoop=1;strokeColor=#2F5B7C;strokeWidth=3;fontFamily=Helvetica;fontSize=16;fontColor=#23445D;spacing=5;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="ehnrpR-e_t0s3ppQeY-d-1" target="ehnrpR-e_t0s3ppQeY-d-56"> + <mxGeometry relative="1" as="geometry"> + <mxPoint x="-60" y="370" as="sourcePoint" /> + <mxPoint x="-310" y="325" as="targetPoint" /> + </mxGeometry> + </mxCell> + <mxCell id="ehnrpR-e_t0s3ppQeY-d-59" value="<b>MPI_worker</b>" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#2F5B7C;fontColor=#ffffff;strokeColor=none;" vertex="1" parent="1"> + <mxGeometry x="-300" y="371" width="120" height="60" as="geometry" /> + </mxCell> + <mxCell id="ehnrpR-e_t0s3ppQeY-d-60" value="" style="edgeStyle=none;rounded=0;jumpStyle=none;html=1;shadow=0;labelBackgroundColor=none;startArrow=none;startFill=0;endArrow=classic;endFill=1;jettySize=auto;orthogonalLoop=1;strokeColor=#2F5B7C;strokeWidth=3;fontFamily=Helvetica;fontSize=16;fontColor=#23445D;spacing=5;exitX=0;exitY=1;exitDx=0;exitDy=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="ehnrpR-e_t0s3ppQeY-d-1" target="ehnrpR-e_t0s3ppQeY-d-59"> + <mxGeometry relative="1" as="geometry"> + <mxPoint x="50" y="360" as="sourcePoint" /> + <mxPoint x="-170" y="490" as="targetPoint" /> + </mxGeometry> + </mxCell> + <mxCell id="ehnrpR-e_t0s3ppQeY-d-61" value="" style="endArrow=none;html=1;rounded=0;strokeWidth=3;strokeColor=#2F5B7C;" edge="1" parent="1"> + <mxGeometry width="50" height="50" relative="1" as="geometry"> + <mxPoint x="-720" y="559" as="sourcePoint" /> + <mxPoint x="130" y="559" as="targetPoint" /> + </mxGeometry> + </mxCell> + <mxCell id="ehnrpR-e_t0s3ppQeY-d-62" value="" style="endArrow=none;html=1;rounded=0;strokeWidth=3;fillColor=#008a00;strokeColor=#005700;" edge="1" parent="1"> + <mxGeometry width="50" height="50" relative="1" as="geometry"> + <mxPoint x="280" y="559" as="sourcePoint" /> + <mxPoint x="640" y="559" as="targetPoint" /> + </mxGeometry> + </mxCell> + <mxCell id="ehnrpR-e_t0s3ppQeY-d-63" value="Components" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;fillColor=none;fontStyle=1;fontSize=18;" vertex="1" parent="1"> + <mxGeometry x="280" y="509" width="130" height="40" as="geometry" /> + </mxCell> + <mxCell id="ehnrpR-e_t0s3ppQeY-d-64" value="Core" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;fillColor=none;fontStyle=1;fontSize=18;" vertex="1" parent="1"> + <mxGeometry x="70" y="509" width="60" height="40" as="geometry" /> + </mxCell> + </root> + </mxGraphModel> + </diagram> +</mxfile> diff --git a/src/PyGMA.py b/src/PyGMA.py old mode 100644 new mode 100755 index 4d9e544..fd621ee --- a/src/PyGMA.py +++ b/src/PyGMA.py @@ -1,6 +1,6 @@ import numpy as np from config import CONFIG, check_config -from controller import Controller +from core.controller import Controller # remove here @@ -14,14 +14,13 @@ def bool2int(x): def mpi_worker(config): # instantiate the worker - from mpi_worker import MPI_worker + from core.mpi_worker import MPI_worker worker = MPI_worker(config=config, sleep_time=0) worker.start() return 0 - def controller(): """ Main controller logic for the algorithm diff --git a/src/evolutionary_phase.py b/src/components/evolutionary_phase.py similarity index 93% rename from src/evolutionary_phase.py rename to src/components/evolutionary_phase.py index 5500c12..3ce12af 100755 --- a/src/evolutionary_phase.py +++ b/src/components/evolutionary_phase.py @@ -1,6 +1,5 @@ -from genetic_operators import Genetic_operator -from experiment import Experiment -from population import Population +from components.genetic_operators import Genetic_operator +from components.experiment import Experiment # -------------- # Interface idea diff --git a/src/experiment.py b/src/components/experiment.py similarity index 92% rename from src/experiment.py rename to src/components/experiment.py index df7d48a..3d19f46 100755 --- a/src/experiment.py +++ b/src/components/experiment.py @@ -74,19 +74,18 @@ class Function_optimisation_experiment(Experiment): y = bool2int(numbers[1]) z = bool2int(numbers[2]) - # define the objective output + # define the objective output for our function output = 424242 - # calculate the outpup + # calculate the output r = self.f(x, y, z) # calc error and fitness error = abs(r-output) # if error is small fitness is high - if error == 0: - error = 0.000000000000000000000000000000000000000000001 - fitness = 1/error + # make sure that if error can not be 0 :) + fitness = 1.0/(error + 0.00000000000000001) # print(f'error: {error} fitness {fitness}') return fitness diff --git a/src/genetic_operators.py b/src/components/genetic_operators.py similarity index 100% rename from src/genetic_operators.py rename to src/components/genetic_operators.py diff --git a/src/config.py b/src/config.py index 02770b2..66bbe70 100755 --- a/src/config.py +++ b/src/config.py @@ -1,6 +1,6 @@ -from genetic_operators import Mutation_operator, Single_point_crossover_operator, Removal_operator -from evolutionary_phase import Simple_evolutionary_phase -from experiment import Function_optimisation_experiment +from components.genetic_operators import Mutation_operator, Single_point_crossover_operator, Removal_operator +from components.evolutionary_phase import Simple_evolutionary_phase +from components.experiment import Function_optimisation_experiment # ----------------------------- @@ -47,7 +47,7 @@ CONFIG = { # use mpi parallelization # If use_mpi4py_futures=False start with: # mpiexec -n 3 python PyGMA.py - 'use_mpi': True, + 'use_mpi': False, # use mpi4py.futures # this will dynamically spawn workers. @@ -60,6 +60,8 @@ CONFIG = { # solves the experiment. Spawning takes time (memcopys etc) # if the experiment is very simple having only one process # handling everyting might be faster. + # start programm with: + # python PyGMA.py 'num_local_processes': 1, diff --git a/src/controller.py b/src/core/controller.py similarity index 99% rename from src/controller.py rename to src/core/controller.py index 5106a24..eb4b74e 100755 --- a/src/controller.py +++ b/src/core/controller.py @@ -1,4 +1,4 @@ -from population import Population +from core.population import Population from concurrent.futures import ProcessPoolExecutor import numpy as np # FIXME: @@ -124,7 +124,7 @@ class Controller: else: # will use the cached module and as such the global intercomm from mpi4py import MPI - from mpi_tags import mpi_tags + from core.mpi_tags import mpi_tags comm = MPI.COMM_WORLD world_size = comm.Get_size() @@ -365,7 +365,7 @@ class Controller: if self.config['use_mpi'] and not self.config['use_mpi4py_futures']: # send stop to all wokers from mpi4py import MPI - from mpi_tags import mpi_tags + from core.mpi_tags import mpi_tags comm = MPI.COMM_WORLD world_size = comm.Get_size() print('stopping mpi workers') diff --git a/src/individual.py b/src/core/individual.py similarity index 100% rename from src/individual.py rename to src/core/individual.py diff --git a/src/mpi_tags.py b/src/core/mpi_tags.py old mode 100644 new mode 100755 similarity index 100% rename from src/mpi_tags.py rename to src/core/mpi_tags.py diff --git a/src/mpi_worker.py b/src/core/mpi_worker.py old mode 100644 new mode 100755 similarity index 77% rename from src/mpi_worker.py rename to src/core/mpi_worker.py index cf7034f..ba3b5a2 --- a/src/mpi_worker.py +++ b/src/core/mpi_worker.py @@ -1,10 +1,10 @@ import time from mpi4py import MPI -from mpi_tags import mpi_tags +from core.mpi_tags import mpi_tags class MPI_worker(): - def __init__(self, config, sleep_time=0.01): + def __init__(self, config, sleep_time=0): self.config = config self.comm = MPI.COMM_WORLD self.rank = self.comm.Get_rank() @@ -20,10 +20,13 @@ class MPI_worker(): # we receive a bool if we shall to continue to process # to not eat all CPU ressources we sleep a little if no transmission - while not self.comm.iprobe(source=0, tag=mpi_tags.CONTINUE_PROCESSING): - # sleep - # print(f'worker {self.rank} is sleeping') - time.sleep(self.sleep_time) + # but this will slow down tremendously, + # don't sleep when you are supposed to be present + if self.sleep_time > 0: + while not self.comm.iprobe(source=0, tag=mpi_tags.CONTINUE_PROCESSING): + # sleep + # print(f'worker {self.rank} is sleeping') + time.sleep(self.sleep_time) continue_processing = self.comm.recv( source=0, tag=mpi_tags.CONTINUE_PROCESSING) diff --git a/src/population.py b/src/core/population.py similarity index 97% rename from src/population.py rename to src/core/population.py index 286f94e..e0d20f4 100755 --- a/src/population.py +++ b/src/core/population.py @@ -1,5 +1,5 @@ -from individual import Individual -from genetic_operators import Genetic_operator +from core.individual import Individual +from components.genetic_operators import Genetic_operator import numpy as np diff --git a/src/population_old.py b/src/core/population_old.py similarity index 100% rename from src/population_old.py rename to src/core/population_old.py diff --git a/src/Evo.ipynb b/src/testing/Evo.ipynb similarity index 100% rename from src/Evo.ipynb rename to src/testing/Evo.ipynb diff --git a/src/PyGMA.ipynb b/src/testing/PyGMA.ipynb similarity index 100% rename from src/PyGMA.ipynb rename to src/testing/PyGMA.ipynb diff --git a/src/mpi_test.py b/src/testing/mpi_test.py old mode 100644 new mode 100755 similarity index 100% rename from src/mpi_test.py rename to src/testing/mpi_test.py diff --git a/src/testing_notebook.ipynb b/src/testing/testing_notebook.ipynb similarity index 100% rename from src/testing_notebook.ipynb rename to src/testing/testing_notebook.ipynb -- GitLab