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

Refactored core #70

Merged
merged 73 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from 56 commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
7c90cfb
refactoring
MangaBoba Sep 7, 2023
dc45428
refactored postprocessing
MangaBoba Sep 15, 2023
6032236
add polygon level crossover
MangaBoba Sep 15, 2023
c2f9cb0
fix parallel execution, fix modules compatibility
MangaBoba Sep 15, 2023
ef74200
add: joblib backend, postprocessing-safe mutations, basic logger,
MangaBoba Oct 2, 2023
eb85f98
add config models, golem tuners interface
MangaBoba Oct 4, 2023
31f50a5
add sound_wave + tuner case, minor fixes, requirements fix new core
MangaBoba Oct 5, 2023
df48091
fix compatibility, add extra in config
MangaBoba Oct 5, 2023
6e739e2
fix np.log10 zero division warning
MangaBoba Oct 5, 2023
2ff48ac
fix docstring
MangaBoba Oct 6, 2023
1957f36
fix tuning: search variance, invalid sturcts after tuning
MangaBoba Oct 6, 2023
8f15b58
add better pop logging
MangaBoba Oct 7, 2023
29d6c1f
add configurable logs paths
MangaBoba Oct 7, 2023
091c12d
patch iOpt infinite loop with np.inf fitness
MangaBoba Oct 9, 2023
72eb949
fix serialization, add parser
MangaBoba Oct 10, 2023
86ac5f6
patch golem verbose arg
MangaBoba Oct 10, 2023
3c735d6
fix parsing
MangaBoba Oct 10, 2023
da4d7bc
add normal distrib search space
MangaBoba Oct 11, 2023
b70f785
minor fix sound simulator
MangaBoba Oct 11, 2023
34c60e7
fix tuner timeout
MangaBoba Oct 12, 2023
cd749d3
simple surrogate case
MangaBoba Oct 13, 2023
9d5868a
add surrogate optimizer, fix operations for GOLEM compatibility
MangaBoba Oct 18, 2023
348aa58
Changed SoundFieldFitness in main. Shafle options in optimizer in Bas…
SoloWayG Oct 5, 2023
64e08b2
add poly_from_point.py and bottom_square.txt
SoloWayG Oct 9, 2023
56e5c97
add swan_interface.py and microphone_points.py
SoloWayG Oct 18, 2023
6e384f0
fix standard sampler
MangaBoba Oct 18, 2023
fc38f66
fix standard sampler
MangaBoba Oct 18, 2023
b63a870
sync
MangaBoba Oct 18, 2023
3d7aa0a
sync
MangaBoba Oct 18, 2023
3eae7c9
Refactoring ci (#67)
MangaBoba Oct 31, 2023
fedfded
Refactoring postroc (#68)
MangaBoba Oct 31, 2023
3d2bbe8
domain tests
MangaBoba Nov 3, 2023
4c64b57
add updated test_geometry2D.py
SoloWayG Nov 3, 2023
d55beb2
Merge remote-tracking branch 'origin/refactoring' into refactoring
SoloWayG Nov 3, 2023
af939bd
add mutation and structure crossover tests
SoloWayG Nov 7, 2023
e662113
update mutation tests
SoloWayG Nov 7, 2023
96037c4
Fix for BaseGA and crossovers.py
SoloWayG Nov 7, 2023
7125f08
fix codestyle, modules structure, convex mutations bugs, add py cfg e…
MangaBoba Nov 8, 2023
a3bea29
Merge branch 'refactoring' into refactoring_geometry
MangaBoba Nov 8, 2023
5dd89fa
Merge branch 'refactoring_geometry' into refactoring
MangaBoba Nov 8, 2023
59c5314
minor fix
MangaBoba Nov 8, 2023
9d41d61
upt flake8 cfg
MangaBoba Nov 8, 2023
b5679c3
fix flake8 action
MangaBoba Nov 8, 2023
25b64c6
add docstrings, fix codestyle
MangaBoba Nov 8, 2023
7fe4619
minor test fix
MangaBoba Nov 8, 2023
95727b6
upd py version for package & git actions
MangaBoba Nov 9, 2023
71189f4
minor git action syntax fix
MangaBoba Nov 9, 2023
8d7ecbc
update docs, add synthetic cases, add simple experimets runner, fix t…
MangaBoba Nov 10, 2023
e63aa41
add comsol and sound cases
MangaBoba Nov 11, 2023
7d638bd
add tuners tutorial
MangaBoba Nov 11, 2023
a59db48
add optimizers tutorial
MangaBoba Nov 12, 2023
216a220
add PRE test
SoloWayG Nov 8, 2023
083833d
add validation test
SoloWayG Nov 13, 2023
fbef4b5
add conves-safe util test
MangaBoba Nov 13, 2023
ce73b1a
Merge branch 'refactoring' of https://github.com/aimclub/GEFEST into …
MangaBoba Nov 13, 2023
7386f47
add tests for out_of_bounds and selfintersection checks
MangaBoba Nov 13, 2023
2a737eb
rm debug samples
MangaBoba Nov 13, 2023
0db6252
Add Arctice config and ob2_upd with SWAN.exe to breakwaters case
SoloWayG Nov 14, 2023
bfdc506
Merge remote-tracking branch 'origin/refactoring' into refactoring
SoloWayG Nov 14, 2023
3d34220
Fix flake8 errors
SoloWayG Nov 14, 2023
d9c367c
add multiobj selectors spea2 & moead, init pop can be set manually, m…
MangaBoba Nov 15, 2023
a0ec2d9
Merge branch 'refactoring' of https://github.com/aimclub/GEFEST into …
MangaBoba Nov 15, 2023
23f364a
fix convex-save-area and polygon crossover bugs
MangaBoba Nov 16, 2023
83bf964
upd tutorials
MangaBoba Nov 16, 2023
dd78c48
fix gefest_ga pipeline bugs, add parallel estimation feature, minor f…
MangaBoba Nov 17, 2023
cfdc7b0
add some tests, draft sound parallel cfg, minor bugfixes
MangaBoba Nov 19, 2023
8f9d73b
fix example import
MangaBoba Nov 20, 2023
24d53fa
Add Sampler - noise_sampler.py to reverse generate synthetic geometry…
SoloWayG Nov 21, 2023
7bf80fc
tuner fix, parallel sound, minor fixes
MangaBoba Nov 23, 2023
17fc0a1
add ensure seq, jit sound estimator optimisation, minor fixes
MangaBoba Nov 24, 2023
0af93fd
fix test filepath
MangaBoba Nov 24, 2023
0f759e9
Create a geojson parser definition from arctic_config.py file.
SoloWayG Nov 24, 2023
6f1dcba
upd docs build py version, fix build action
MangaBoba Nov 24, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/workflows/unit-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: unit tests

on:
push:
branches: [ main ]
branches: [ main, refactoring ]
MangaBoba marked this conversation as resolved.
Show resolved Hide resolved
pull_request:
branches: [ main ]
branches: [ main, refactoring ]

jobs:
build:
Expand All @@ -13,7 +13,7 @@ jobs:
timeout-minutes: 5
strategy:
matrix:
python-version: [ 3.8, 3.9]
python-version: [ "3.9", "3.10" ]

steps:
- uses: actions/checkout@v2
Expand All @@ -27,6 +27,9 @@ jobs:
pip install pytest
pip install -r requirements.txt
pip install pytest-cov
- name: Run flake8 checks
run: |
flake8 gefest test --count --statistics
- name: Test with pytest
run: |
pytest --cov=GEFEST -s test/
201 changes: 201 additions & 0 deletions cases/breakwaters/main_arctic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
import pickle
from functools import partial
from gefest.core.algs.postproc.resolve_errors import Rules, apply_postprocess
import numpy as np
from hyperopt import hp
from gefest.core.opt.operators.selections import tournament_selection,roulette_selection
from gefest.core.algs.postproc.resolve_errors import Rules, postprocess
from gefest.core.configs.optimization_params import OptimizationParams
from gefest.core.configs.tuner_params import TunerParams
from gefest.core.geometry import Structure
from gefest.core.geometry.domain import Domain
from gefest.core.geometry.geometry_2d import Geometry2D
from gefest.core.geometry.utils import get_random_structure
from gefest.core.opt.adapters.structure import StructureAdapter
from gefest.core.opt.operators.crossovers import (
panmixis,
polygon_level_crossover,
structure_level_crossover,
)
from gefest.core.opt.operators.mutations import (
add_point,
add_poly,
drop_point,
drop_poly,
pos_change_point_mutation,
resize_poly,
rotate_poly,
)
import json
from gefest.core.opt.tuning.tuner import GolemTuner
from gefest.core.structure.prohibited import create_prohibited
from gefest.core.viz.struct_vizualizer import GIFMaker
from gefest.tools.estimators.simulators.sound_wave.sound_interface import (
SoundSimulator,
generate_map,
)
from gefest.tools.fitness import Fitness
from gefest.tools.optimizers.GA.base_GA import BaseGA
from pathlib import Path
from gefest.tools.estimators.simulators.swan.swan_interface import Swan
from shapely.geometry import shape
# pre domain params
root_path = Path(__file__).parent.parent.parent
with open(f'{root_path}/cases/breakwaters/newdata/result_PwiOsA2HE2igZUel.geojson', 'r') as file:
res_list = json.load(file)
with open(f'{root_path}/cases/breakwaters/newdata/border_PwiOsA2HE2igZUel.geojson', 'r') as file:
border_dict = json.load(file)
border = shape(border_dict['features'][0]['geometry'])
water = [i for i in res_list['features'] if i['properties']['type'] =='water']
water_coord =[p['geometry']['coordinates'] for p in water]
cargo_piers = [i for i in res_list['features'] if i['properties']['type'] =='cargo_pier']
passenger_pier = [i for i in res_list['features'] if i['properties']['type'] =='passenger_pier']
piers = [i for i in res_list['features'] if (i['properties']['type']=='passenger_pier') or (i['properties']['type'] =='cargo_pier')]
piers_coords = [x[0] for x in [i['geometry']['coordinates'] for i in piers]]
piers_line = [max(p,key=lambda i: i[1]) for p in piers_coords]
unique_types = np.unique([i['properties']['type'] for i in res_list['features']])
allow_water = [i for i in water_coord[0][0] if (i[0]>74.8) and (i[1]<67.942) and (i[1]>67.915)]
###########
allow_area = [[74.80,67.92],[74.80,67.94]]+allow_water +[[74.80,67.92]]
grid_resolution_x = 17 # Number of points on x-axis
grid_resolution_y = 31 # Number of points on y-axis
coord_Y = np.linspace(min([p[1] for p in allow_area])*500, max([p[1] for p in allow_area])*500, grid_resolution_y + 1) # X coordinate for spatial grid
coord_X = np.linspace(min([p[0] for p in allow_area])*500, max([p[0] for p in allow_area])*500, grid_resolution_x + 1)
grid = [grid_resolution_x, grid_resolution_y] # points grid
fixed_area = None
targets = [[14,10],[16,10],[18,10]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут напрашивается заварачивание в какую-то функцию, парсящую geojson

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут напрашивается заварачивание в какую-то функцию, парсящую geojson

Завернул в функцию. Теперь этот main находится в cases/breakwaters/arctic_config/acrtic_config.py.
А функция находится cases/breakwaters/utils.



def load_file_from_path(path: str):
with open(path, 'rb') as f:
file = pickle.load(f)
f.close()
return file
nicl-nno marked this conversation as resolved.
Show resolved Hide resolved


if __name__ == '__main__':
# class SoundSimulator_(SoundSimulator):
# def __init__(self, domain, obstacle_map=None):
# super().__init__(domain, obstacle_map=None)
# self.duration = 200
# self.pressure_hist = np.zeros((self.duration, self.size_y, self.size_x))
# if (
# obstacle_map is not None
# and (obstacle_map.shape[0], obstacle_map.shape[1]) == self.map_size
# ):
# print("** Map Accepted **")
# self.obstacle_map = obstacle_map
# elif obstacle_map is not None and obstacle_map.shape != self.map_size:
# print("** Map size denied **")
# self.obstacle_map = np.zeros((self.size_y, self.size_x))
# else:
# self.obstacle_map = np.zeros((self.size_y, self.size_x))

# in the future all model can be loaded from configs

# domain configuration
geometry = Geometry2D(is_closed=False, is_convex=True)
prohibited = create_prohibited(1, [], [], fixed_area=fixed_area)
domain = Domain(
allowed_area=[
(min(coord_X), min(coord_Y)),
(min(coord_X), max(coord_Y)),
(max(coord_X), max(coord_Y)),
(max(coord_X), min(coord_Y)),
(min(coord_X), min(coord_Y)),
],
geometry=geometry,
max_poly_num=1,
min_poly_num=1,
max_points_num=10,
min_points_num=4,
prohibited_area=prohibited,
)

# tuner config
tp = TunerParams(
tuner_type='sequential',
n_steps_tune=25,
sampling_variance=1,
hyperopt_dist=hp.uniform,
)
path_=f"{root_path}/cases/breakwaters/ob2/"
#Estimator
swan_estimator = Swan(
targets=targets,
domain=domain,
grid=grid,
path=path_,
hs_file_path='results/HSig_ob_example.dat'
)
# fitness function
class SoundFieldFitness(Fitness):
def __init__(self, domain, estimator):
super().__init__(domain)
self.estimator=estimator
def fitness(self, ind: Structure):
fitness = self.estimator(ind)
return fitness

# fitness estimator
estimator = SoundFieldFitness(
domain,
swan_estimator
)

# optimization params config
opt_params = OptimizationParams(
crossovers=[
polygon_level_crossover,
structure_level_crossover,
],
crossover_prob=0.3,
crossover_each_prob=[0.0, 1.0],
mutations=[
rotate_poly,
resize_poly,
add_point,
drop_point,
add_poly,
drop_poly,
pos_change_point_mutation,
],
mutation_each_prob=[0.125, 0.125, 0.25, 0.25, 0.00, 0.00, 0.25],
pair_selector=panmixis,
postprocess_attempts=10,
domain=domain,
postprocessor=apply_postprocess,
estimator=estimator,
postprocess_rules=[
Rules.not_out_of_bounds.value,
Rules.not_closed_polygon.value,
Rules.not_self_intersects.value,
Rules.not_too_close_polygons.value,
# Rules.not_overlaps_prohibited.value,
Rules.not_too_close_points.value,
],
extra=2,
n_jobs=0,
golem_adapter=StructureAdapter,
tuner_cfg=tp,
n_steps=5,
pop_size=6,
selector=roulette_selection
)

optimizer = BaseGA(opt_params)
optimized_pop = optimizer.optimize()

# make mp4 of optimized pop here if need

# tuner = GolemTuner(opt_params)
# n_best_for_tune = 1
# tuned_individuals = tuner.tune(optimized_pop[0:n_best_for_tune])

# make mp4 of tuned pop here if need

# code to create mp4
###
# gm = GIFMaker(domain=domain) # mp4 maker actually
# gm.create_frame(_structure_, {'Optimized': _structure_.fitness}) # make frames for each stucture you want
# gm.make_gif('tuning', 500, ) # save file
54 changes: 54 additions & 0 deletions cases/breakwaters/ob2/INPUT
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
$***********MODEL INPUT*********************************
SET NAUTical
MODE NONSTationary TWODimensional
COORDinates spherical

CGRID REGular xpc=74.70350703505787 ypc=67.88206697110601 alpc=0. &
xlenc=0.128969 ylenc=0.086128 mxc=17 myc=31 &
CIRCLE mdc=36 flow=0.05 fhigh=1. msc=25

INPgrid BOTtom REGular xpinp=74.70350703505787 ypinp=67.88206697110601 &
alpinp=0. mxinp=17 myinp=31 &
dxinp=0.0071370458 dyinp=0.0026897599 EXCeption -9
READinp BOTtom fac=1 'data\bathy.bot' idla=1 0 FREE

INPgrid WIND REGular xpinp=74.70350703505787 ypinp=67.88206697110601 &
alpinp=0. mxinp=17 myinp=31 &
dxinp=0.0071370458 dyinp=0.0026897599 &
NONSTATIONARY 20180101.000000 6 HR 20180103.230000
READinp WIND fac=1.21 SERIES 'data\wind_inventory.txt' 1 0 1 0 FREE

BOUnd SHAPespec JONswap 3.3 PEAK DSPR DEGRees



OBSTACLE TRANSM 0. REFL 0. LINE 74.810470, 67.930902, 74.806538, 67.930025, 74.803719, 67.928509, 74.809836, 67.923163, 74.810798, 67.922973, 74.811649, 67.926213, 74.811374, 67.929569
$optline


GEN3 ST6 6.5E-6 8.5E-5 4.0 4.0 UP HWANG VECTAU U10PROXY 35.0 AGROW
BREAKING
FRiction JONswap CONstant 0.067
TRIAD
DIFFRACtion
PROP BSBT
QUANTity Per short='Tm-1,0' power=0.



OUTPUT OPTIONS '%' TABLE 16 BLOCK 6 18

BLOCK 'COMPGRID' NOHEAD 'results\HSig_ob_example.dat' LAYOUT 1 HSig OUT 20180102.000000 1. HR
BLOCK 'COMPGRID' NOHEAD 'results\PDIR_ob_example.dat' LAYOUT 1 PDIR OUT 20180102.000000 1. HR
BLOCK 'COMPGRID' NOHEAD 'results\RTP_ob_example.dat' LAYOUT 1 RTP OUT 20180102.000000 1. HR








COMPUTE NONSTat 20180101.000000 10 MIN 20180103.230000

STOP
18 changes: 0 additions & 18 deletions cases/main_conf.py

This file was deleted.

Loading
Loading