Skip to content

Commit

Permalink
factoring out click interface for optimize_network
Browse files Browse the repository at this point in the history
  • Loading branch information
iraikov committed Nov 3, 2023
1 parent f5827e2 commit 09f9f0e
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 66 deletions.
45 changes: 44 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down
67 changes: 2 additions & 65 deletions src/miv_simulator/optimize_network.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
) :
]
)
100 changes: 100 additions & 0 deletions src/scripts/optimization/optimize_network.py
Original file line number Diff line number Diff line change
@@ -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,
)

0 comments on commit 09f9f0e

Please sign in to comment.