From 58a1aa62ca28c646d9993b227b08a9cfca306543 Mon Sep 17 00:00:00 2001 From: Johannes Hjorth Date: Mon, 18 Mar 2024 11:09:57 +0100 Subject: [PATCH 1/5] Updated error message --- snudda/input/input.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/snudda/input/input.py b/snudda/input/input.py index a1b3224f5..39d678d27 100644 --- a/snudda/input/input.py +++ b/snudda/input/input.py @@ -902,6 +902,12 @@ 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. " + f"Are you trying to use meta.json input, but spelled name wrong, " + f"or did you miss to specify conductance for the input?\n{input_inf =}") + cond = input_inf["conductance"] if "num_inputs" in input_inf: From 4a6220ffc2ddb43a10a87e66c64efc78d9d9abb2 Mon Sep 17 00:00:00 2001 From: Johannes Hjorth Date: Mon, 18 Mar 2024 11:13:44 +0100 Subject: [PATCH 2/5] Mer info --- snudda/input/input.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/snudda/input/input.py b/snudda/input/input.py index 39d678d27..fe2cfd770 100644 --- a/snudda/input/input.py +++ b/snudda/input/input.py @@ -904,9 +904,11 @@ def make_neuron_input_parallel(self): # 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. " + raise ValueError(f"No conductance specified for input {input_type}. " f"Are you trying to use meta.json input, but spelled name wrong, " - f"or did you miss to specify conductance for the input?\n{input_inf =}") + 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 = }") cond = input_inf["conductance"] From 4717bfee41bdfb19204462edc09904fe2c168fb7 Mon Sep 17 00:00:00 2001 From: Johannes Hjorth Date: Mon, 18 Mar 2024 11:14:56 +0100 Subject: [PATCH 3/5] Mer info --- snudda/input/input.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snudda/input/input.py b/snudda/input/input.py index fe2cfd770..e068bf5ca 100644 --- a/snudda/input/input.py +++ b/snudda/input/input.py @@ -904,7 +904,7 @@ def make_neuron_input_parallel(self): # 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 {input_type}. " + raise ValueError(f"No conductance specified for {input_type = }. " 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 = }" From 90830276aa310730e870a6d4cec9c453924e1f5f Mon Sep 17 00:00:00 2001 From: Johannes Hjorth Date: Mon, 18 Mar 2024 11:16:31 +0100 Subject: [PATCH 4/5] Mer info --- snudda/input/input.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/snudda/input/input.py b/snudda/input/input.py index e068bf5ca..a8a0ac685 100644 --- a/snudda/input/input.py +++ b/snudda/input/input.py @@ -904,11 +904,12 @@ def make_neuron_input_parallel(self): # 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 = }. " + 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"\n{input_inf = }" + f"\nSee examples: https://github.com/Hjorthmedh/Snudda/tree/master/examples/notebooks") cond = input_inf["conductance"] From d075f09a9c1e2d17b03337a4220f2a2902563cbd Mon Sep 17 00:00:00 2001 From: Johannes Hjorth Date: Mon, 18 Mar 2024 15:24:10 +0100 Subject: [PATCH 5/5] Updated place --- snudda/init/init_config.py | 11 +++++++++-- snudda/place/place.py | 10 ++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/snudda/init/init_config.py b/snudda/init/init_config.py index 47646a6d1..3efbccaf5 100644 --- a/snudda/init/init_config.py +++ b/snudda/init/init_config.py @@ -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")): @@ -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 diff --git a/snudda/place/place.py b/snudda/place/place.py index a730d4c32..0dc0fd1a9 100644 --- a/snudda/place/place.py +++ b/snudda/place/place.py @@ -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): @@ -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"), @@ -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") @@ -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