Skip to content

Commit

Permalink
Add network interface
Browse files Browse the repository at this point in the history
  • Loading branch information
frthjf committed Mar 19, 2024
1 parent 612e635 commit ac4e576
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/miv_simulator/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ class ParametricSurface(BaseModel):

class CellType(BaseModel):
template: str
mechanism: Optional[Dict]
synapses: Dict[
Literal["density"],
Dict[
Expand All @@ -260,6 +259,7 @@ class CellType(BaseModel):
],
],
]
mechanism: Optional[Dict] = None


CellTypes = Dict[PopulationsLiteral, CellType]
Expand Down
104 changes: 104 additions & 0 deletions src/miv_simulator/interface/network.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import os

from pydantic import BaseModel, Field, ConfigDict
from machinable import Interface, get
from miv_simulator.config import Config


class Network(Interface):
class Config(BaseModel):
model_config = ConfigDict(extra="forbid")

config_filepath: str = Field("???")
mechanisms_path: str = ("./mechanisms",)
template_path: str = ("./templates",)
morphology_path: str = "./morphology"

def launch(self):
config = Config.from_yaml(self.config.config_filepath)

self.h5_types = get(
"miv_simulator.interface.h5_types",
[
{
"projections": config.projections,
"cell_distributions": config.cell_distributions,
},
],
).launch()

self.network = get(
"miv_simulator.interface.network_architecture",
[
{
"filepath": self.h5_types.output_filepath,
"cell_distributions": self.h5_types.config.cell_distributions,
"layer_extents": config.layer_extents,
},
],
uses=self.h5_types,
).launch()

self.distances = self.network.measure_distances().launch()

self.synapse_forest = {
population: self.network.generate_synapse_forest(
{
"population": population,
"morphology": os.path.join(
self.config.morphology_path, f"{population}.swc"
),
},
uses=self.distances,
).launch()
for population in config.synapses
}

self.synapses = {
population: self.network.distribute_synapses(
{
"forest_filepath": self.synapse_forest[
population
].output_filepath,
"cell_types": config.cell_types,
"population": population,
"distribution": "poisson",
"mechanisms_path": self.config.mechanisms_path,
"template_path": self.config.template_path,
"io_size": 1,
"write_size": 0,
},
uses=list(self.synapse_forest.values()),
).launch()
for population in config.synapses
}

self.connections = {
population: self.network.generate_connections(
{
"synapses": config.synapses,
"forest_filepath": self.synapses[
population
].output_filepath,
"axon_extents": config.axon_extents,
"io_size": 1,
"cache_size": 20,
"write_size": 100,
},
uses=list(self.synapses.values()),
).launch()
for population in config.synapses
}

self.neural_h5 = get(
"miv_simulator.interface.neuroh5_graph",
uses=[
self.network,
self.distances,
*self.synapse_forest.values(),
*self.synapses.values(),
*self.connections.values(),
],
).launch()

return self

0 comments on commit ac4e576

Please sign in to comment.