Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry-pick various fixes from optimization branch #74

Merged
merged 2 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/miv_simulator/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,19 +215,20 @@ class Synapse(BaseModel):
layers: conlist(LayersDefOrStr)
proportions: conlist(float)
mechanisms: Dict[SynapseMechanismsLiteral, Mechanism]
contacts: int = 1


def _origin_value_to_callable(value: Union[str, float]) -> Callable:
if isinstance(value, (float, int)):
if isinstance(value, float):
return lambda _: value

return getattr(np, value)


class Origin(BaseModel):
U: Union[str, float, int]
V: Union[str, float, int]
L: Union[str, float, int]
U: Union[str, float]
V: Union[str, float]
L: Union[str, float]

def as_spec(self):
return {
Expand All @@ -245,7 +246,6 @@ class ParametricSurface(BaseModel):

class CellType(BaseModel):
template: str
mechanism: Union[str, Dict, None]
synapses: Dict[
Literal["density"],
Dict[
Expand Down
2 changes: 1 addition & 1 deletion src/miv_simulator/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ def generate_uv_distance_connections(
projection_config[source_population].layers,
projection_config[source_population].sections,
projection_config[source_population].proportions,
projection_config[source_population].get("contacts", 1),
projection_config[source_population].contacts,
)
for source_population in source_populations
}
Expand Down
2 changes: 1 addition & 1 deletion src/miv_simulator/geometry/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ def distance_interpolant(

vol_dist = get_volume_distances(
ip_volume,
origin_spec=config.Origin(**origin).as_spec(),
origin_spec=origin,
nsample=n_sample,
comm=comm,
alpha_radius=alpha_radius,
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 @@ -42,7 +42,7 @@ def __call__(self):
cell_distributions=self.config.cell_distributions,
layer_extents=self.config.layer_extents,
rotation=self.config.rotation,
origin=self.config.origin,
origin=config.Origin(**self.config.origin).as_spec(),
n_sample=self.config.n_sample,
alpha_radius=self.config.alpha_radius,
io_size=self.config.io_size,
Expand Down
2 changes: 1 addition & 1 deletion src/miv_simulator/opto/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def init_mechanisms(self):
rho_dict = self.pop_rho_dict[pop_name]
mech = getattr(h, self.mechanisms[self.model.nStates])

expProb = self.rho_params["expProb"]
expProb = self.rho_params.get("expProb", 1.0)

for gid in gid_set:
if not self.pc.gid_exists(gid):
Expand Down
3 changes: 0 additions & 3 deletions src/miv_simulator/simulator/generate_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ def generate_distance_connections(
synapses=env.connection_config,
axon_extents=env.connection_extents,
use_coreneuron=env.use_coreneuron,
dt=env.dt,
tstop=env.tstop,
celsius=env.celsius,
output_filepath=connectivity_path,
connectivity_namespace=connectivity_namespace,
coordinates_namespace=coords_namespace,
Expand Down
31 changes: 2 additions & 29 deletions src/miv_simulator/simulator/generate_network_architecture.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import random
import sys
from collections import defaultdict
import importlib

import h5py
import numpy as np
Expand Down Expand Up @@ -171,7 +170,7 @@ def generate_soma_coordinates(
layer_extents=env.geometry["Parametric Surface"]["Layer Extents"],
rotation=env.geometry["Parametric Surface"]["Rotation"],
cell_distributions=env.geometry["Cell Distribution"],
cell_constraints=env.geometry["Cell Constraints"],
cell_constraints=env.geometry.get("Cell Constraints", None),
output_namespace=output_namespace,
geometry_filepath=geometry_path,
populations=populations,
Expand All @@ -191,7 +190,7 @@ def generate_network_architecture(
cell_distributions: config.CellDistributions,
layer_extents: config.LayerExtents,
rotation: config.Rotation,
cell_constraints: config.CellConstraints,
cell_constraints: Optional[config.CellConstraints],
output_namespace: str,
geometry_filepath: Optional[str],
populations: Optional[Tuple[str, ...]],
Expand Down Expand Up @@ -342,26 +341,6 @@ def generate_network_architecture(
if count <= 0:
continue

if layer.startswith("@"):
# generate via callback
module_path, _, obj_name = layer[1:].rpartition(".")
if module_path == "__main__" or module_path == "":
module = sys.modules["__main__"]
else:
module = importlib.import_module(module_path)
callback = getattr(module, obj_name)

nodes = callback(count, layer_extents[layer])

if not len(nodes) == count:
logger.error(
f"Generator {layer} produced mismatch between actual count {len(nodes)} and configured count {count}"
)

xyz_coords_lst.append(nodes.reshape(-1, 3))

continue

alpha = layer_alpha_shapes[layer]

vert = alpha.points
Expand Down Expand Up @@ -604,12 +583,6 @@ def generate_network_architecture(
for i in range(delta):
for layer, count in pop_layers.items():
if count > 0:
if layer.startswith("@"):
logger.warning(
f"Generator {layer} did not return the specified number of coordinates"
)
continue

min_extent = layer_extents[layer][0]
max_extent = layer_extents[layer][1]
coord_u = np.random.uniform(
Expand Down
10 changes: 7 additions & 3 deletions src/miv_simulator/simulator/measure_distances.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def measure_distances_(
populations,
resolution,
nsample,
alpha_radius,
io_size,
chunk_size,
value_chunk_size,
Expand All @@ -52,15 +53,18 @@ def measure_distances_(
utils.config_logging(verbose)
env = Env(comm=MPI.COMM_WORLD, config=config, config_prefix=config_prefix)

parametric_surface = env.geometry["Parametric Surface"]
return measure_distances(
filepath=coords_path,
geometry_filepath=geometry_path,
coordinate_namespace=coords_namespace,
populations=populations,
cell_distributions=env.geometry["Cell Distribution"],
layer_extents=env.geometry["Layer Extents"],
rotation=env.geometry["Rotation"],
origin=env.geometry["Origin"],
layer_extents=parametric_surface["Layer Extents"],
rotation=parametric_surface["Rotation"],
origin=parametric_surface["Origin"],
resolution=resolution,
alpha_radius=alpha_radius,
n_sample=nsample,
io_size=io_size,
chunk_size=chunk_size,
Expand Down
3 changes: 3 additions & 0 deletions src/scripts/measure_distances.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
@click.option("--populations", "-i", required=True, multiple=True, type=str)
@click.option("--resolution", type=(int, int, int), default=(30, 30, 10))
@click.option("--nsample", type=int, default=1000)
@click.option("--alpha-radius", type=float, default=100)
@click.option("--io-size", type=int, default=-1)
@click.option("--chunk-size", type=int, default=1000)
@click.option("--value-chunk-size", type=int, default=1000)
Expand All @@ -50,6 +51,7 @@ def main(
populations,
resolution,
nsample,
alpha_radius,
io_size,
chunk_size,
value_chunk_size,
Expand All @@ -64,6 +66,7 @@ def main(
populations,
resolution,
nsample,
alpha_radius,
io_size,
chunk_size,
value_chunk_size,
Expand Down
Loading