Skip to content

Commit

Permalink
Record interface dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
frthjf committed Oct 26, 2023
1 parent 27a76a2 commit 9815199
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 56 deletions.
2 changes: 1 addition & 1 deletion src/miv_simulator/interface/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/miv_simulator/interface/distances.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
36 changes: 23 additions & 13 deletions src/miv_simulator/interface/network_architecture.py
Original file line number Diff line number Diff line change
@@ -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."""

Expand All @@ -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)
Expand Down Expand Up @@ -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",
[
Expand All @@ -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",
[
Expand All @@ -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",
[
Expand All @@ -118,5 +128,5 @@ def generate_connections(self, version: VersionType = None):
}
]
+ normversion(version),
uses=self,
uses=_join(self, uses),
)
1 change: 1 addition & 0 deletions src/miv_simulator/interface/synapse_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ def __call__(self) -> None:
population=self.config.population,
morphology=self.config.morphology,
)
print("generate_synapse_forest() completed")
3 changes: 1 addition & 2 deletions src/miv_simulator/interface/synapses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
86 changes: 47 additions & 39 deletions src/miv_simulator/simulator/generate_synapse_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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):
Expand All @@ -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),
]
)

0 comments on commit 9815199

Please sign in to comment.