Skip to content

Commit

Permalink
Merge pull request #413 from Hjorthmedh/init_redux2
Browse files Browse the repository at this point in the history
Fixed init bug
  • Loading branch information
Hjorthmedh authored Mar 18, 2024
2 parents 0492cd4 + d075f09 commit 53050f6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
11 changes: 9 additions & 2 deletions snudda/init/init_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ def replace_network_path(self, network_path):
print(f"Setting {network_path = }")
self.config_data["network_path"] = network_path

def skip_item(self, item):

return isinstance(item, str) and len(item) > 0 and item[0] == '!'

def substitute_json(self, putative_file, key=None, parent_file=None):

if not (isinstance(putative_file, str) and putative_file.endswith(".json")):
Expand Down Expand Up @@ -120,14 +124,17 @@ def parse_subtree(self, config_dict, parent_file=None):
updated_config[key] = self.parse_subtree(value, parent_file=parent_file)

elif isinstance(value, list):
updated_config[key] = [self.substitute_json(x, parent_file=parent_file) for x in value]
updated_config[key] = [self.substitute_json(x, parent_file=parent_file) for x in value if not self.skip_item(x)]

# If the first element is a dict, assume all are dict and merge them
if isinstance(updated_config[key][0], dict):
updated_config[key] = dict(ChainMap(*reversed(updated_config[key])))

else:
updated_config[key] = self.substitute_json(value, key, parent_file=parent_file)
if not self.skip_item(item=value):
updated_config[key] = self.substitute_json(value, key, parent_file=parent_file)
else:
del updated_config[key]

return updated_config

Expand Down
9 changes: 9 additions & 0 deletions snudda/input/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,15 @@ def make_neuron_input_parallel(self):

# If your code fails here, it might be that you are trying to override the background input
# frequency, but have the incorrect name of that input (check the meta.json file)

if "conductance" not in input_inf:
raise ValueError(f"No conductance specified for {input_type = }.\n"
f"Are you trying to use meta.json input, but spelled name wrong, "
f"or did you miss to specify conductance for the input?"
f"\n{neuron_id = }, {neuron_name = }, {neuron_type = }, {population_unit_id = }"
f"\n{input_inf = }"
f"\nSee examples: https://github.com/Hjorthmedh/Snudda/tree/master/examples/notebooks")

cond = input_inf["conductance"]

if "num_inputs" in input_inf:
Expand Down
10 changes: 8 additions & 2 deletions snudda/place/place.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,8 @@ def parse_config(self, config_file=None, resort_neurons=True):
else:
raise ValueError(f"You need to specify 'fraction' or 'num_neurons' for {neuron_type}")

# print(f"{neuron_type = }, {num_neurons = }")

n_types = len(neuron_data["neuron_path"])

if isinstance(num_neurons, int):
Expand All @@ -463,6 +465,8 @@ def parse_config(self, config_file=None, resort_neurons=True):
else:
n_neurons = num_neurons

# print(f"{n_neurons = }")

parameter_key_list = SnuddaPlace.replicate_str(neuron_data.get("parameter_key"),
n_neurons, f"{neuron_type} parameter_key")
morphology_key_list = SnuddaPlace.replicate_str(neuron_data.get("morphology_key"),
Expand All @@ -474,6 +478,8 @@ def parse_config(self, config_file=None, resort_neurons=True):
in zip(neuron_data["neuron_path"].items(), n_neurons,
parameter_key_list, morphology_key_list, modulation_key_list):

print(f"{neuron_name = }, {num = }, {neuron_path = }")

if neuron_name.split("_")[0] != neuron_type and neuron_name != neuron_type:
raise ValueError(f"The keys in neuron_path must be {neuron_name}_X where X is usually a number")

Expand Down Expand Up @@ -1438,11 +1444,11 @@ def replicate_str(string, n_replicas, variable_name=None):
# variable_name is just used to help with error message if incorrect input

if string is None or isinstance(string, str):
rep_str = [string for x in range(np.sum(n_replicas))]
rep_str = [string for x in range(len(n_replicas))]
elif len(string) == n_replicas:
rep_str = string
else:
raise ValueError(f"Expected a str or a list of str of length {n_replicas} for {variable_name}")
raise ValueError(f"Expected a str or a list of str of length {len(n_replicas)} for {variable_name}")

return rep_str

Expand Down

0 comments on commit 53050f6

Please sign in to comment.