diff --git a/src/miv_simulator/interface/connections.py b/src/miv_simulator/interface/connections.py index 17eb47f..a2c4e43 100644 --- a/src/miv_simulator/interface/connections.py +++ b/src/miv_simulator/interface/connections.py @@ -30,7 +30,7 @@ class Config(BaseModel): value_chunk_size: int = 1000 cache_size: int = 1 write_size: int = 1 - ranks_: int = 8 + ranks: int = 8 def config_from_file(self, filename: str) -> Dict: return from_yaml(filename) diff --git a/src/miv_simulator/interface/distances.py b/src/miv_simulator/interface/distances.py index 9e491fe..5824c2e 100644 --- a/src/miv_simulator/interface/distances.py +++ b/src/miv_simulator/interface/distances.py @@ -29,7 +29,7 @@ class Config(BaseModel): chunk_size: int = 1000 value_chunk_size: int = 1000 cache_size: int = 50 - ranks_: int = 8 + ranks: int = 8 def __call__(self): logging.basicConfig(level=logging.INFO) diff --git a/src/miv_simulator/interface/network_architecture.py b/src/miv_simulator/interface/network_architecture.py index 5394fc1..bb92f56 100644 --- a/src/miv_simulator/interface/network_architecture.py +++ b/src/miv_simulator/interface/network_architecture.py @@ -1,16 +1,28 @@ -from typing import Optional, Tuple, Dict +from typing import Optional, Tuple, Dict, Union import os import logging from machinable import Component from machinable.element import normversion -from machinable.types import VersionType from miv_simulator import config, simulator from miv_simulator.utils import io as io_utils, from_yaml from mpi4py import MPI from pydantic import BaseModel, Field, ConfigDict +def _join(*args): + uses = [] + for arg in args: + if arg is None: + continue + elif isinstance(arg, (list, tuple)): + uses.extend(arg) + else: + uses.append(arg) + + return uses + + class NetworkArchitecture(Component): """Creates the network architecture by generating the soma coordinates within specified layer geometry.""" @@ -34,7 +46,7 @@ class Config(BaseModel): io_size: int = -1 chunk_size: int = 1000 value_chunk_size: int = 1000 - ranks_: int = 1 + ranks: int = 8 def config_from_file(self, filename: str) -> Dict: return from_yaml(filename) @@ -64,7 +76,7 @@ def __call__(self) -> None: value_chunk_size=self.config.value_chunk_size, ) - def measure_distances(self, version: VersionType = None): + def measure_distances(self, version=None, uses=None): return self.derive( "miv_simulator.interface.distances", [ @@ -83,12 +95,10 @@ def measure_distances(self, version: VersionType = None): } ] + normversion(version), - uses=self, + uses=_join(self, uses), ) - def generate_synapse_forest( - self, version: VersionType = None - ) -> "Component": + def generate_synapse_forest(self, version=None, uses=None) -> "Component": return self.derive( "miv_simulator.interface.synapse_forest", [ @@ -97,17 +107,17 @@ def generate_synapse_forest( } ] + normversion(version), - uses=self, + uses=_join(self, uses), ) - def distribute_synapses(self, version: VersionType = None): + def distribute_synapses(self, version=None, uses=None): return self.derive( "miv_simulator.interface.synapses", [] + normversion(version), - uses=self, + uses=_join(self, uses), ) - def generate_connections(self, version: VersionType = None): + def generate_connections(self, version=None, uses=None): return self.derive( "miv_simulator.interface.connections", [ @@ -118,5 +128,5 @@ def generate_connections(self, version: VersionType = None): } ] + normversion(version), - uses=self, + uses=_join(self, uses), ) diff --git a/src/miv_simulator/interface/synapse_forest.py b/src/miv_simulator/interface/synapse_forest.py index 623f810..4436fb3 100644 --- a/src/miv_simulator/interface/synapse_forest.py +++ b/src/miv_simulator/interface/synapse_forest.py @@ -27,3 +27,4 @@ def __call__(self) -> None: population=self.config.population, morphology=self.config.morphology, ) + print("generate_synapse_forest() completed") diff --git a/src/miv_simulator/interface/synapses.py b/src/miv_simulator/interface/synapses.py index c11c7fa..6ba0812 100644 --- a/src/miv_simulator/interface/synapses.py +++ b/src/miv_simulator/interface/synapses.py @@ -23,8 +23,7 @@ class Config(BaseModel): write_size: int = 1 chunk_size: int = 1000 value_chunk_size: int = 1000 - ranks_: int = 8 - nodes_: int = 1 + ranks: int = 8 def config_from_file(self, filename: str) -> Dict: return from_yaml(filename) diff --git a/src/miv_simulator/simulator/generate_synapse_forest.py b/src/miv_simulator/simulator/generate_synapse_forest.py index e7418f5..38d3a36 100644 --- a/src/miv_simulator/simulator/generate_synapse_forest.py +++ b/src/miv_simulator/simulator/generate_synapse_forest.py @@ -11,6 +11,22 @@ def _bin_check(bin: str) -> None: raise FileNotFoundError(f"{bin} not found. Did you add it to the PATH?") +def _run(cmd): + try: + subprocess.check_output( + cmd, + stderr=subprocess.STDOUT, + ) + except subprocess.CalledProcessError as e: + error_message = e.output.decode() + print(f"{os.getcwd()}$:") + print(" ".join(cmd)) + print("Error:", error_message) + raise subprocess.CalledProcessError( + e.returncode, e.cmd, output=error_message + ) + + def generate_synapse_forest( filepath: str, tree_output_filepath: str, @@ -21,33 +37,28 @@ def generate_synapse_forest( # create tree if not os.path.isfile(tree_output_filepath): _bin_check("neurotrees_import") - assert ( - subprocess.run( - [ - "neurotrees_import", - population, - tree_output_filepath, - morphology, - ] - ).returncode - == 0 + _run( + [ + "neurotrees_import", + population, + tree_output_filepath, + morphology, + ] ) - assert ( - subprocess.run( - [ - "h5copy", - "-p", - "-s", - "/H5Types", - "-d", - "/H5Types", - "-i", - filepath, - "-o", - tree_output_filepath, - ] - ).returncode - == 0 + + _run( + [ + "h5copy", + "-p", + "-s", + "/H5Types", + "-d", + "/H5Types", + "-i", + filepath, + "-o", + tree_output_filepath, + ] ) if not os.path.isfile(output_filepath): @@ -61,17 +72,14 @@ def generate_synapse_forest( offset = f["H5Types"]["Populations"][idx][0] _bin_check("neurotrees_copy") - assert ( - subprocess.run( - [ - "neurotrees_copy", - "--fill", - "--output", - output_filepath, - tree_output_filepath, - population, - str(offset), - ] - ).returncode - == 0 + _run( + [ + "neurotrees_copy", + "--fill", + "--output", + output_filepath, + tree_output_filepath, + population, + str(offset), + ] )