diff --git a/poetry.lock b/poetry.lock index bedff12..4e126ed 100644 --- a/poetry.lock +++ b/poetry.lock @@ -660,6 +660,24 @@ files = [ [package.extras] graph = ["objgraph (>=1.7.2)"] +[[package]] +name = "distgfs" +version = "1.1.0" +description = "Distributed global function search via dlib" +optional = true +python-versions = ">=3.8,<4.0" +files = [ + {file = "distgfs-1.1.0-py3-none-any.whl", hash = "sha256:3a872c8d0b9052ef70b040aafdafa8b7a7f94add19e73ad58ee592552ae514eb"}, + {file = "distgfs-1.1.0.tar.gz", hash = "sha256:0771308c2c3b2f8bd06b2d09e6a945b5db9e0b72e02777a2a215d3c483799afc"}, +] + +[package.dependencies] +distwq = ">=1.1.0" +dlib = ">=19.24.0,<20.0.0" +h5py = ">=3.7.0,<4.0.0" +mpi4py = ">=3.1.3,<4.0.0" +numpy = ">=1.23.3,<2.0.0" + [[package]] name = "distlib" version = "0.3.7" @@ -671,6 +689,31 @@ files = [ {file = "distlib-0.3.7.tar.gz", hash = "sha256:9dafe54b34a028eafd95039d5e5d4851a13734540f1331060d31c9916e7147a8"}, ] +[[package]] +name = "distwq" +version = "1.1.0" +description = "Distributed queue operations with mpi4py" +optional = true +python-versions = ">=3.8,<4.0" +files = [ + {file = "distwq-1.1.0-py3-none-any.whl", hash = "sha256:ca9297d2f512059b4035add868f2e6e3ebdf3f86cd0ea387567cb6b556e4d65b"}, + {file = "distwq-1.1.0.tar.gz", hash = "sha256:ffe10d76da8ba87667e534d7b836026960487dec04fa0749670fb1172f0170b7"}, +] + +[package.dependencies] +mpi4py = ">=3.1.3,<4.0.0" +numpy = ">=1.23.1,<2.0.0" + +[[package]] +name = "dlib" +version = "19.24.2" +description = "A toolkit for making real world machine learning and data analysis applications" +optional = true +python-versions = "*" +files = [ + {file = "dlib-19.24.2.tar.gz", hash = "sha256:2d4f618073bc6b297aa01ce05595a2d32b5b37e69cafd99f796e77346f6dcfb5"}, +] + [[package]] name = "docutils" version = "0.19" @@ -3604,4 +3647,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = ">=3.9,<3.12" -content-hash = "9523763e99913a68051401e39d1ac1555b0763eb78faea92a78dfb92bd6524d4" +content-hash = "f07b0f840718a5b39f547fd4a7002f64caa0de9dd79e98948722d8e2fb073475" diff --git a/pyproject.toml b/pyproject.toml index fb08c1f..8e85b33 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,6 +28,7 @@ matplotlib = "^3.6.0" quantities = "^0.13.0" pydantic = "^2.3.0" neuron = "^8.2.3" +distgfs = {version = "^1.1.0", optional = true} [tool.poetry.dev-dependencies] @@ -88,6 +89,7 @@ check-config = "scripts.tools.check_config:main" cut-slice = "scripts.tools.cut_slice:main" sample-cells = "scripts.tools.sample_cells:main" reposition-trees = "scripts.tools.reposition_trees:main" +optimize-network = "scripts.optimization.optimize_network:main_cli" [build-system] diff --git a/src/miv_simulator/optimize_network.py b/src/miv_simulator/optimize_network.py index 0367e27..0efbac5 100644 --- a/src/miv_simulator/optimize_network.py +++ b/src/miv_simulator/optimize_network.py @@ -1,6 +1,6 @@ #!/usr/bin/env python """ -Dentate Gyrus model optimization script for optimization with dmosopt +Network model optimization script for optimization with dmosopt """ import os, sys, logging, datetime, gc @@ -133,56 +133,7 @@ def init_controller(subworld_size, use_coreneuron): h.pc.psolve(0.05) -@click.command( - context_settings=dict( - ignore_unknown_options=True, - allow_extra_args=True, - ) -) -@click.option( - "--config-path", - required=True, - type=str, - help="optimization configuration file name", -) -@click.option( - "--target-features-path", - required=False, - type=click.Path(), - help="path to neuroh5 file containing target rate maps used for rate optimization", -) -@click.option( - "--target-features-namespace", - type=str, - required=False, - default="Input Spikes", - help="namespace containing target rate maps used for rate optimization", -) -@click.option( - "--optimize-file-dir", - type=click.Path(exists=True, file_okay=False, dir_okay=True), - default="results", -) -@click.option( - "--optimize-file-name", - type=click.Path(exists=False, file_okay=True, dir_okay=False), -) -@click.option("--nprocs-per-worker", type=int, default=1) -@click.option("--n-epochs", type=int, default=1) -@click.option("--n-initial", type=int, default=30) -@click.option("--initial-maxiter", type=int, default=50) -@click.option("--initial-method", type=str, default="glp") -@click.option("--optimizer-method", type=str, default="nsga2") -@click.option("--population-size", type=int, default=100) -@click.option("--num-generations", type=int, default=200) -@click.option("--resample-fraction", type=float) -@click.option("--mutation-rate", type=float) -@click.option("--collective-mode", type=str, default="gather") -@click.option("--spawn-startup-wait", type=int, default=3) -@click.option("--spawn-workers", is_flag=True) -@click.option("--get-best", is_flag=True) -@click.option("--verbose", "-v", is_flag=True) -def main( +def optimize_network( config_path, target_features_path, target_features_namespace, @@ -541,17 +492,3 @@ def compute_objectives(local_features, operational_config, opt_targets): ) return {0: result} - - -if __name__ == "__main__": - main( - args=sys.argv[ - ( - list_find( - lambda x: os.path.basename(x) == os.path.basename(__file__), - sys.argv, - ) - + 1 - ) : - ] - ) diff --git a/src/scripts/optimization/optimize_network.py b/src/scripts/optimization/optimize_network.py new file mode 100644 index 0000000..5792f8c --- /dev/null +++ b/src/scripts/optimization/optimize_network.py @@ -0,0 +1,100 @@ +import os +import sys +import click +from miv_simulator import utils +from miv_simulator.optimize_network import optimize_network + + +@click.command( + context_settings=dict( + ignore_unknown_options=True, + allow_extra_args=True, + ) +) +@click.option( + "--config-path", + required=True, + type=str, + help="optimization configuration file name", +) +@click.option( + "--target-features-path", + required=False, + type=click.Path(), + help="path to neuroh5 file containing target rate maps used for rate optimization", +) +@click.option( + "--target-features-namespace", + type=str, + required=False, + default="Input Spikes", + help="namespace containing target rate maps used for rate optimization", +) +@click.option( + "--optimize-file-dir", + type=click.Path(exists=True, file_okay=False, dir_okay=True), + default="results", +) +@click.option( + "--optimize-file-name", + type=click.Path(exists=False, file_okay=True, dir_okay=False), +) +@click.option("--nprocs-per-worker", type=int, default=1) +@click.option("--n-epochs", type=int, default=1) +@click.option("--n-initial", type=int, default=30) +@click.option("--initial-maxiter", type=int, default=50) +@click.option("--initial-method", type=str, default="glp") +@click.option("--optimizer-method", type=str, default="nsga2") +@click.option("--population-size", type=int, default=100) +@click.option("--num-generations", type=int, default=200) +@click.option("--resample-fraction", type=float) +@click.option("--mutation-rate", type=float) +@click.option("--collective-mode", type=str, default="gather") +@click.option("--spawn-startup-wait", type=int, default=3) +@click.option("--spawn-workers", is_flag=True) +@click.option("--get-best", is_flag=True) +@click.option("--verbose", "-v", is_flag=True) +def main_cli( + config_path, + target_features_path, + target_features_namespace, + optimize_file_dir, + optimize_file_name, + nprocs_per_worker, + n_epochs, + n_initial, + initial_maxiter, + initial_method, + optimizer_method, + population_size, + num_generations, + resample_fraction, + mutation_rate, + collective_mode, + spawn_startup_wait, + spawn_workers, + get_best, + verbose, +): + optimize_network( + config_path, + target_features_path, + target_features_namespace, + optimize_file_dir, + optimize_file_name, + nprocs_per_worker, + n_epochs, + n_initial, + initial_maxiter, + initial_method, + optimizer_method, + population_size, + num_generations, + resample_fraction, + mutation_rate, + collective_mode, + spawn_startup_wait, + spawn_workers, + get_best, + verbose, + )