From 02af90ba20bf339457dacc627c0e661da3f36328 Mon Sep 17 00:00:00 2001 From: Johanna Senk Date: Mon, 4 Dec 2023 15:51:27 +0100 Subject: [PATCH] Fix line lengths --- doc/extractor_userdocs.py | 46 +-- macOS/pythonlib/nestgpu.py | 212 ++++--------- python/Potjans_2014/eval_microcircuit_time.py | 4 +- python/Potjans_2014/helpers.py | 14 +- python/Potjans_2014/network.py | 52 +--- python/Potjans_2014/network_params.py | 4 +- python/Potjans_2014/run_microcircuit.py | 12 +- .../Potjans_2014_hc/eval_microcircuit_time.py | 4 +- python/Potjans_2014_hc/helpers.py | 14 +- python/Potjans_2014_hc/network.py | 52 +--- python/Potjans_2014_hc/network_params.py | 4 +- python/Potjans_2014_hc/run_microcircuit.py | 12 +- .../Potjans_2014_s/eval_microcircuit_time.py | 4 +- python/Potjans_2014_s/helpers.py | 14 +- python/Potjans_2014_s/network.py | 52 +--- python/Potjans_2014_s/network_params.py | 4 +- python/Potjans_2014_s/run_microcircuit.py | 12 +- python/examples/brunel_array.py | 8 +- python/examples/temp_mpi.py | 18 +- python/hpc_benchmark/hpc_benchmark.py | 64 +--- python/test/test_brunel_array.py | 8 +- python/test/test_stdp/cases/case1.py | 4 +- python/test/test_stdp/cases/case10.py | 4 +- python/test/test_stdp/cases/case2.py | 4 +- python/test/test_stdp/cases/case3.py | 4 +- python/test/test_stdp/cases/case4.py | 4 +- python/test/test_stdp/cases/case5.py | 4 +- python/test/test_stdp/cases/case6.py | 4 +- python/test/test_stdp/cases/case7.py | 4 +- python/test/test_stdp/cases/case8.py | 4 +- python/test/test_stdp/cases/case9.py | 4 +- python/test/test_stdp/long_test/test_stdp.py | 4 +- pythonlib/nestgpu.py | 292 +++++------------- src/write_iaf_psc_exp_hc_params.py | 11 +- 34 files changed, 231 insertions(+), 730 deletions(-) diff --git a/doc/extractor_userdocs.py b/doc/extractor_userdocs.py index ddad28737..af675d416 100644 --- a/doc/extractor_userdocs.py +++ b/doc/extractor_userdocs.py @@ -89,9 +89,7 @@ def UserDocExtractor(filenames, basedir="..", replace_ext=".rst", outdir="userdo if not os.path.exists(outdir): log.info("creating output directory " + outdir) os.mkdir(outdir) - userdoc_re = re.compile( - r"BeginUserDocs:?\s*(?P([\w -]+(,\s*)?)*)\n+(?P(.|\n)*)EndUserDocs" - ) + userdoc_re = re.compile(r"BeginUserDocs:?\s*(?P([\w -]+(,\s*)?)*)\n+(?P(.|\n)*)EndUserDocs") tagdict = dict() # map tags to lists of documents nfiles_total = 0 with tqdm(unit="files", total=len(filenames)) as progress: @@ -160,14 +158,7 @@ def rewrite_short_description(doc, filename, short_description="Short descriptio secend = nexttitle.start() sdesc = doc[secstart:secend].strip().replace("\n", " ") fixed_title = "%s – %s" % (name, sdesc) - return ( - doc[: title.start()] - + fixed_title - + "\n" - + "=" * len(fixed_title) - + "\n\n" - + doc[secend:] - ) + return doc[: title.start()] + fixed_title + "\n" + "=" * len(fixed_title) + "\n\n" + doc[secend:] raise ValueError("No section '%s' found in %s!" % (short_description, filename)) @@ -237,14 +228,7 @@ def rightcase(text): return ( doc[:secstart] + "\n" - + ", ".join( - [ - ":doc:`{taglabel} `".format( - tag=tag, taglabel=rightcase(tag) - ) - for tag in tags - ] - ) + + ", ".join([":doc:`{taglabel} `".format(tag=tag, taglabel=rightcase(tag)) for tag in tags]) + "\n\n" + doc[secend:] ) @@ -282,9 +266,7 @@ def make_hierarchy(tags, *basetags): return tags # items having all given basetags - baseitems = set.intersection( - *[set(items) for tag, items in tags.items() if tag in basetags] - ) + baseitems = set.intersection(*[set(items) for tag, items in tags.items() if tag in basetags]) tree = dict() subtags = [t for t in tags.keys() if t not in basetags] for subtag in subtags: @@ -326,9 +308,7 @@ def mktitle(t, ul, link=None): text = t if t != t.upper(): text = t.title() # title-case any tag that is not an acronym - title = ":doc:`{text} <{filename}>`".format( - text=text, filename=link or "index_" + t - ) + title = ":doc:`{text} <{filename}>`".format(text=text, filename=link or "index_" + t) text = title + "\n" + ul * len(title) + "\n" return text @@ -352,9 +332,7 @@ def mkitem(t): title = tags else: title = " & ".join(tags) - if ( - title and not len(hierarchy) == 1 - ): # not print title if already selected by current_tags + if title and not len(hierarchy) == 1: # not print title if already selected by current_tags output.append(mktitle(title, underlines[0])) if isinstance(items, dict): output.append(rst_index(items, current_tags, underlines[1:], top=False)) @@ -405,18 +383,14 @@ def CreateTagIndices(tags, outdir="userdocs/"): """ taglist = list(tags.keys()) maxtaglen = max([len(t) for t in tags]) - for tag, count in sorted( - [(tag, len(lst)) for tag, lst in tags.items()], key=lambda x: x[1] - ): + for tag, count in sorted([(tag, len(lst)) for tag, lst in tags.items()], key=lambda x: x[1]): log.info(" %%%ds tag in %%d files" % maxtaglen, tag, count) if "" in taglist: taglist.remove("") indexfiles = list() depth = min(4, len(taglist)) # how many levels of indices to create at most nindices = sum([comb(len(taglist), L) for L in range(depth - 1)]) - log.info( - "indices down to level %d → %d possible keyword combinations", depth, nindices - ) + log.info("indices down to level %d → %d possible keyword combinations", depth, nindices) for current_tags in tqdm( chain(*[combinations(taglist, L) for L in range(depth - 1)]), unit="idx", @@ -479,9 +453,7 @@ def getTitles(text): elements are the section title re.match objects """ titlechar = r"\+" - title_re = re.compile( - r"^(?P.+)\n(?P<underline>" + titlechar + r"+)$", re.MULTILINE - ) + title_re = re.compile(r"^(?P<title>.+)\n(?P<underline>" + titlechar + r"+)$", re.MULTILINE) titles = [] # extract all titles for match in title_re.finditer(text): diff --git a/macOS/pythonlib/nestgpu.py b/macOS/pythonlib/nestgpu.py index e8ed2ee50..1df9f97b5 100644 --- a/macOS/pythonlib/nestgpu.py +++ b/macOS/pythonlib/nestgpu.py @@ -222,9 +222,7 @@ def Create(model_name, n_node=1, n_ports=1, status_dict=None): elif status_dict != None: raise ValueError("Wrong argument in Create") - c_model_name = ctypes.create_string_buffer( - to_byte_str(model_name), len(model_name) + 1 - ) + c_model_name = ctypes.create_string_buffer(to_byte_str(model_name), len(model_name) + 1) i_node = NESTGPU_Create(c_model_name, ctypes.c_int(n_node), ctypes.c_int(n_ports)) ret = NodeSeq(i_node, n_node) if GetErrorCode() != 0: @@ -260,16 +258,12 @@ def CreatePoissonGenerator(n_node, rate): def CreateRecord(file_name, var_name_list, i_node_list, i_port_list): "Create a record of neuron variables" n_node = len(i_node_list) - c_file_name = ctypes.create_string_buffer( - to_byte_str(file_name), len(file_name) + 1 - ) + c_file_name = ctypes.create_string_buffer(to_byte_str(file_name), len(file_name) + 1) array_int_type = ctypes.c_int * n_node array_char_pt_type = c_char_p * n_node c_var_name_list = [] for i in range(n_node): - c_var_name = ctypes.create_string_buffer( - to_byte_str(var_name_list[i]), len(var_name_list[i]) + 1 - ) + c_var_name = ctypes.create_string_buffer(to_byte_str(var_name_list[i]), len(var_name_list[i]) + 1) c_var_name_list.append(c_var_name) ret = NESTGPU_CreateRecord( @@ -346,12 +340,8 @@ def GetRecordData(i_record): def SetNeuronScalParam(i_node, n_node, param_name, val): "Set neuron scalar parameter value" - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) - ret = NESTGPU_SetNeuronScalParam( - ctypes.c_int(i_node), ctypes.c_int(n_node), c_param_name, ctypes.c_float(val) - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) + ret = NESTGPU_SetNeuronScalParam(ctypes.c_int(i_node), ctypes.c_int(n_node), c_param_name, ctypes.c_float(val)) if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) return ret @@ -370,9 +360,7 @@ def SetNeuronScalParam(i_node, n_node, param_name, val): def SetNeuronArrayParam(i_node, n_node, param_name, param_list): "Set neuron array parameter value" - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) array_size = len(param_list) array_float_type = ctypes.c_float * array_size ret = NESTGPU_SetNeuronArrayParam( @@ -400,14 +388,10 @@ def SetNeuronArrayParam(i_node, n_node, param_name, param_list): def SetNeuronPtScalParam(nodes, param_name, val): "Set neuron list scalar parameter value" n_node = len(nodes) - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) node_arr = (ctypes.c_int * len(nodes))(*nodes) node_pt = ctypes.cast(node_arr, ctypes.c_void_p) - ret = NESTGPU_SetNeuronPtScalParam( - node_pt, ctypes.c_int(n_node), c_param_name, ctypes.c_float(val) - ) + ret = NESTGPU_SetNeuronPtScalParam(node_pt, ctypes.c_int(n_node), c_param_name, ctypes.c_float(val)) if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) return ret @@ -427,9 +411,7 @@ def SetNeuronPtScalParam(nodes, param_name, val): def SetNeuronPtArrayParam(nodes, param_name, param_list): "Set neuron list array parameter value" n_node = len(nodes) - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) node_arr = (ctypes.c_int * len(nodes))(*nodes) node_pt = ctypes.cast(node_arr, ctypes.c_void_p) @@ -454,9 +436,7 @@ def SetNeuronPtArrayParam(nodes, param_name, param_list): def IsNeuronScalParam(i_node, param_name): "Check name of neuron scalar parameter" - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) ret = NESTGPU_IsNeuronScalParam(ctypes.c_int(i_node), c_param_name) != 0 if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) @@ -470,9 +450,7 @@ def IsNeuronScalParam(i_node, param_name): def IsNeuronPortParam(i_node, param_name): "Check name of neuron scalar parameter" - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) ret = NESTGPU_IsNeuronPortParam(ctypes.c_int(i_node), c_param_name) != 0 if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) @@ -486,9 +464,7 @@ def IsNeuronPortParam(i_node, param_name): def IsNeuronArrayParam(i_node, param_name): "Check name of neuron scalar parameter" - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) ret = NESTGPU_IsNeuronArrayParam(ctypes.c_int(i_node), c_param_name) != 0 if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) @@ -508,9 +484,7 @@ def IsNeuronArrayParam(i_node, param_name): def SetNeuronScalVar(i_node, n_node, var_name, val): "Set neuron scalar variable value" c_var_name = ctypes.create_string_buffer(to_byte_str(var_name), len(var_name) + 1) - ret = NESTGPU_SetNeuronScalVar( - ctypes.c_int(i_node), ctypes.c_int(n_node), c_var_name, ctypes.c_float(val) - ) + ret = NESTGPU_SetNeuronScalVar(ctypes.c_int(i_node), ctypes.c_int(n_node), c_var_name, ctypes.c_float(val)) if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) return ret @@ -561,9 +535,7 @@ def SetNeuronPtScalVar(nodes, var_name, val): node_arr = (ctypes.c_int * len(nodes))(*nodes) node_pt = ctypes.cast(node_arr, ctypes.c_void_p) - ret = NESTGPU_SetNeuronPtScalVar( - node_pt, ctypes.c_int(n_node), c_var_name, ctypes.c_float(val) - ) + ret = NESTGPU_SetNeuronPtScalVar(node_pt, ctypes.c_int(n_node), c_var_name, ctypes.c_float(val)) if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) return ret @@ -650,9 +622,7 @@ def IsNeuronArrayVar(i_node, var_name): def GetNeuronParamSize(i_node, param_name): "Get neuron parameter array size" - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) ret = NESTGPU_GetNeuronParamSize(ctypes.c_int(i_node), c_param_name) if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) @@ -666,12 +636,8 @@ def GetNeuronParamSize(i_node, param_name): def GetNeuronParam(i_node, n_node, param_name): "Get neuron parameter value" - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) - data_pt = NESTGPU_GetNeuronParam( - ctypes.c_int(i_node), ctypes.c_int(n_node), c_param_name - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) + data_pt = NESTGPU_GetNeuronParam(ctypes.c_int(i_node), ctypes.c_int(n_node), c_param_name) array_size = GetNeuronParamSize(i_node, param_name) data_list = [] @@ -696,9 +662,7 @@ def GetNeuronParam(i_node, n_node, param_name): def GetNeuronPtParam(nodes, param_name): "Get neuron list scalar parameter value" n_node = len(nodes) - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) node_arr = (ctypes.c_int * len(nodes))(*nodes) node_pt = ctypes.cast(node_arr, ctypes.c_void_p) data_pt = NESTGPU_GetNeuronPtParam(node_pt, ctypes.c_int(n_node), c_param_name) @@ -725,9 +689,7 @@ def GetNeuronPtParam(nodes, param_name): def GetArrayParam(i_node, n_node, param_name): "Get neuron array parameter" - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) data_list = [] for j_node in range(n_node): i_node1 = i_node + j_node @@ -747,9 +709,7 @@ def GetArrayParam(i_node, n_node, param_name): def GetNeuronListArrayParam(node_list, param_name): "Get neuron array parameter" - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) data_list = [] for i_node in node_list: row_list = [] @@ -789,9 +749,7 @@ def GetNeuronVarSize(i_node, var_name): def GetNeuronVar(i_node, n_node, var_name): "Get neuron variable value" c_var_name = ctypes.create_string_buffer(to_byte_str(var_name), len(var_name) + 1) - data_pt = NESTGPU_GetNeuronVar( - ctypes.c_int(i_node), ctypes.c_int(n_node), c_var_name - ) + data_pt = NESTGPU_GetNeuronVar(ctypes.c_int(i_node), ctypes.c_int(n_node), c_var_name) array_size = GetNeuronVarSize(i_node, var_name) @@ -887,9 +845,7 @@ def GetNeuronStatus(nodes, var_name): raise ValueError("Unknown node type") c_var_name = ctypes.create_string_buffer(to_byte_str(var_name), len(var_name) + 1) if type(nodes) == NodeSeq: - if IsNeuronScalParam(nodes.i0, var_name) | IsNeuronPortParam( - nodes.i0, var_name - ): + if IsNeuronScalParam(nodes.i0, var_name) | IsNeuronPortParam(nodes.i0, var_name): ret = GetNeuronParam(nodes.i0, nodes.n, var_name) elif IsNeuronArrayParam(nodes.i0, var_name): ret = GetArrayParam(nodes.i0, nodes.n, var_name) @@ -900,9 +856,7 @@ def GetNeuronStatus(nodes, var_name): else: raise ValueError("Unknown neuron variable or parameter") else: - if IsNeuronScalParam(nodes[0], var_name) | IsNeuronPortParam( - nodes[0], var_name - ): + if IsNeuronScalParam(nodes[0], var_name) | IsNeuronPortParam(nodes[0], var_name): ret = GetNeuronPtParam(nodes, var_name) elif IsNeuronArrayParam(nodes[0], var_name): ret = GetNeuronListArrayParam(nodes, var_name) @@ -936,9 +890,7 @@ def GetNScalVar(i_node): def GetScalVarNames(i_node): "Get list of scalar variable names" n_var = GetNScalVar(i_node) - var_name_pp = ctypes.cast( - NESTGPU_GetScalVarNames(ctypes.c_int(i_node)), ctypes.POINTER(c_char_p) - ) + var_name_pp = ctypes.cast(NESTGPU_GetScalVarNames(ctypes.c_int(i_node)), ctypes.POINTER(c_char_p)) var_name_list = [] for i in range(n_var): var_name_p = var_name_pp[i] @@ -970,9 +922,7 @@ def GetNPortVar(i_node): def GetPortVarNames(i_node): "Get list of scalar variable names" n_var = GetNPortVar(i_node) - var_name_pp = ctypes.cast( - NESTGPU_GetPortVarNames(ctypes.c_int(i_node)), ctypes.POINTER(c_char_p) - ) + var_name_pp = ctypes.cast(NESTGPU_GetPortVarNames(ctypes.c_int(i_node)), ctypes.POINTER(c_char_p)) var_name_list = [] for i in range(n_var): var_name_p = var_name_pp[i] @@ -1005,9 +955,7 @@ def GetNScalParam(i_node): def GetScalParamNames(i_node): "Get list of scalar parameter names" n_param = GetNScalParam(i_node) - param_name_pp = ctypes.cast( - NESTGPU_GetScalParamNames(ctypes.c_int(i_node)), ctypes.POINTER(c_char_p) - ) + param_name_pp = ctypes.cast(NESTGPU_GetScalParamNames(ctypes.c_int(i_node)), ctypes.POINTER(c_char_p)) param_name_list = [] for i in range(n_param): param_name_p = param_name_pp[i] @@ -1040,9 +988,7 @@ def GetNPortParam(i_node): def GetPortParamNames(i_node): "Get list of scalar parameter names" n_param = GetNPortParam(i_node) - param_name_pp = ctypes.cast( - NESTGPU_GetPortParamNames(ctypes.c_int(i_node)), ctypes.POINTER(c_char_p) - ) + param_name_pp = ctypes.cast(NESTGPU_GetPortParamNames(ctypes.c_int(i_node)), ctypes.POINTER(c_char_p)) param_name_list = [] for i in range(n_param): param_name_p = param_name_pp[i] @@ -1075,9 +1021,7 @@ def GetNArrayParam(i_node): def GetArrayParamNames(i_node): "Get list of scalar parameter names" n_param = GetNArrayParam(i_node) - param_name_pp = ctypes.cast( - NESTGPU_GetArrayParamNames(ctypes.c_int(i_node)), ctypes.POINTER(c_char_p) - ) + param_name_pp = ctypes.cast(NESTGPU_GetArrayParamNames(ctypes.c_int(i_node)), ctypes.POINTER(c_char_p)) param_name_list = [] for i in range(n_param): param_name_p = param_name_pp[i] @@ -1110,9 +1054,7 @@ def GetNArrayVar(i_node): def GetArrayVarNames(i_node): "Get list of scalar variable names" n_var = GetNArrayVar(i_node) - var_name_pp = ctypes.cast( - NESTGPU_GetArrayVarNames(ctypes.c_int(i_node)), ctypes.POINTER(c_char_p) - ) + var_name_pp = ctypes.cast(NESTGPU_GetArrayVarNames(ctypes.c_int(i_node)), ctypes.POINTER(c_char_p)) var_name_list = [] for i in range(n_var): var_name_p = var_name_pp[i] @@ -1132,9 +1074,7 @@ def SetNeuronStatus(nodes, var_name, val): if type(nodes) == NodeSeq: if IsNeuronScalParam(nodes.i0, var_name): SetNeuronScalParam(nodes.i0, nodes.n, var_name, val) - elif IsNeuronPortParam(nodes.i0, var_name) | IsNeuronArrayParam( - nodes.i0, var_name - ): + elif IsNeuronPortParam(nodes.i0, var_name) | IsNeuronArrayParam(nodes.i0, var_name): SetNeuronArrayParam(nodes.i0, nodes.n, var_name, val) elif IsNeuronScalVar(nodes.i0, var_name): SetNeuronScalVar(nodes.i0, nodes.n, var_name, val) @@ -1145,9 +1085,7 @@ def SetNeuronStatus(nodes, var_name, val): else: if IsNeuronScalParam(nodes[0], var_name): SetNeuronPtScalParam(nodes, var_name, val) - elif IsNeuronPortParam(nodes[0], var_name) | IsNeuronArrayParam( - nodes[0], var_name - ): + elif IsNeuronPortParam(nodes[0], var_name) | IsNeuronArrayParam(nodes[0], var_name): SetNeuronPtArrayParam(nodes, var_name, val) elif IsNeuronScalVar(nodes[0], var_name): SetNeuronPtScalVar(nodes, var_name, val) @@ -1197,9 +1135,7 @@ def ConnectMpiInit(): for i in range(argc): c_arg = ctypes.create_string_buffer(to_byte_str(sys.argv[i]), 100) c_var_name_list.append(c_arg) - ret = NESTGPU_ConnectMpiInit( - ctypes.c_int(argc), array_char_pt_type(*c_var_name_list) - ) + ret = NESTGPU_ConnectMpiInit(ctypes.c_int(argc), array_char_pt_type(*c_var_name_list)) if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) return ret @@ -1286,9 +1222,7 @@ def RandomUniform(n): def RandomNormal(n, mean, stddev): "Generate n random floats with normal distribution in CUDA memory" - ret = NESTGPU_RandomNormal( - ctypes.c_size_t(n), ctypes.c_float(mean), ctypes.c_float(stddev) - ) + ret = NESTGPU_RandomNormal(ctypes.c_size_t(n), ctypes.c_float(mean), ctypes.c_float(stddev)) if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) return ret @@ -1334,9 +1268,7 @@ def ConnectMpiInit(): for i in range(argc): c_arg = ctypes.create_string_buffer(to_byte_str(sys.argv[i]), 100) c_var_name_list.append(c_arg) - ret = NESTGPU_ConnectMpiInit( - ctypes.c_int(argc), array_char_pt_type(*c_var_name_list) - ) + ret = NESTGPU_ConnectMpiInit(ctypes.c_int(argc), array_char_pt_type(*c_var_name_list)) if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) return ret @@ -1386,9 +1318,7 @@ def ConnSpecInit(): def SetConnSpecParam(param_name, val): "Set connection parameter" - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) ret = NESTGPU_SetConnSpecParam(c_param_name, ctypes.c_int(val)) if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) @@ -1402,9 +1332,7 @@ def SetConnSpecParam(param_name, val): def ConnSpecIsParam(param_name): "Check name of connection parameter" - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) ret = NESTGPU_ConnSpecIsParam(c_param_name) != 0 if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) @@ -1430,9 +1358,7 @@ def SynSpecInit(): def SetSynSpecIntParam(param_name, val): "Set synapse int parameter" - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) ret = NESTGPU_SetSynSpecIntParam(c_param_name, ctypes.c_int(val)) if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) @@ -1446,9 +1372,7 @@ def SetSynSpecIntParam(param_name, val): def SetSynSpecFloatParam(param_name, val): "Set synapse float parameter" - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) ret = NESTGPU_SetSynSpecFloatParam(c_param_name, ctypes.c_float(val)) if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) @@ -1462,9 +1386,7 @@ def SetSynSpecFloatParam(param_name, val): def SetSynSpecFloatPtParam(param_name, arr): "Set synapse pointer to float parameter" - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) if (type(arr) is list) | (type(arr) is tuple): arr = (ctypes.c_float * len(arr))(*arr) arr_pt = ctypes.cast(arr, ctypes.c_void_p) @@ -1481,9 +1403,7 @@ def SetSynSpecFloatPtParam(param_name, arr): def SynSpecIsIntParam(param_name): "Check name of synapse int parameter" - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) ret = NESTGPU_SynSpecIsIntParam(c_param_name) != 0 if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) @@ -1497,9 +1417,7 @@ def SynSpecIsIntParam(param_name): def SynSpecIsFloatParam(param_name): "Check name of synapse float parameter" - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) ret = NESTGPU_SynSpecIsFloatParam(c_param_name) != 0 if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) @@ -1513,9 +1431,7 @@ def SynSpecIsFloatParam(param_name): def SynSpecIsFloatPtParam(param_name): "Check name of synapse pointer to float parameter" - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) ret = NESTGPU_SynSpecIsFloatPtParam(c_param_name) != 0 if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) @@ -1583,9 +1499,7 @@ def RuleArraySize(conn_dict, source, target): def SetSynParamFromArray(param_name, par_dict, array_size): arr_param_name = param_name + "_array" if not SynSpecIsFloatPtParam(arr_param_name): - raise ValueError( - "Synapse parameter cannot be set by" " arrays or distributions" - ) + raise ValueError("Synapse parameter cannot be set by" " arrays or distributions") arr = DictToArray(par_dict, array_size) array_pt = ctypes.cast(arr, ctypes.c_void_p) SetSynSpecFloatPtParam(arr_param_name, array_pt) @@ -1680,17 +1594,11 @@ def Connect(source, target, conn_dict, syn_dict): target_arr = (ctypes.c_int * len(target))(*target) target_arr_pt = ctypes.cast(target_arr, ctypes.c_void_p) if (type(source) == NodeSeq) & (type(target) != NodeSeq): - ret = NESTGPU_ConnectSeqGroup( - source.i0, source.n, target_arr_pt, len(target) - ) + ret = NESTGPU_ConnectSeqGroup(source.i0, source.n, target_arr_pt, len(target)) elif (type(source) != NodeSeq) & (type(target) == NodeSeq): - ret = NESTGPU_ConnectGroupSeq( - source_arr_pt, len(source), target.i0, target.n - ) + ret = NESTGPU_ConnectGroupSeq(source_arr_pt, len(source), target.i0, target.n) else: - ret = NESTGPU_ConnectGroupGroup( - source_arr_pt, len(source), target_arr_pt, len(target) - ) + ret = NESTGPU_ConnectGroupGroup(source_arr_pt, len(source), target_arr_pt, len(target)) if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) return ret @@ -1784,9 +1692,7 @@ def RemoteConnect(i_source_host, source, i_target_host, target, conn_dict, syn_d else: raise ValueError("Unknown synapse parameter") if (type(source) == NodeSeq) & (type(target) == NodeSeq): - ret = NESTGPU_RemoteConnectSeqSeq( - i_source_host, source.i0, source.n, i_target_host, target.i0, target.n - ) + ret = NESTGPU_RemoteConnectSeqSeq(i_source_host, source.i0, source.n, i_target_host, target.i0, target.n) else: if type(source) != NodeSeq: @@ -1955,9 +1861,7 @@ def GetConnections(source=None, target=None, syn_group=-1): conn_list = [] for i_conn in range(n_conn.value): - conn_id = ConnectionId( - conn_arr[i_conn * 3], conn_arr[i_conn * 3 + 1], conn_arr[i_conn * 3 + 2] - ) + conn_id = ConnectionId(conn_arr[i_conn * 3], conn_arr[i_conn * 3 + 1], conn_arr[i_conn * 3 + 2]) conn_list.append(conn_id) ret = conn_list @@ -2086,9 +1990,7 @@ def CreateSynGroup(model_name, status_dict=None): elif status_dict != None: raise ValueError("Wrong argument in CreateSynGroup") - c_model_name = ctypes.create_string_buffer( - to_byte_str(model_name), len(model_name) + 1 - ) + c_model_name = ctypes.create_string_buffer(to_byte_str(model_name), len(model_name) + 1) i_syn_group = NESTGPU_CreateSynGroup(c_model_name) if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) @@ -2150,9 +2052,7 @@ def IsSynGroupParam(syn_group, param_name): raise ValueError("Wrong argument type in IsSynGroupParam") i_syn_group = syn_group.i_syn_group - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) ret = NESTGPU_IsSynGroupParam(ctypes.c_int(i_syn_group), c_param_name) != 0 if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) @@ -2170,9 +2070,7 @@ def GetSynGroupParam(syn_group, param_name): raise ValueError("Wrong argument type in GetSynGroupParam") i_syn_group = syn_group.i_syn_group - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) ret = NESTGPU_GetSynGroupParam(ctypes.c_int(i_syn_group), c_param_name) @@ -2192,12 +2090,8 @@ def SetSynGroupParam(syn_group, param_name, val): raise ValueError("Wrong argument type in SetSynGroupParam") i_syn_group = syn_group.i_syn_group - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) - ret = NESTGPU_SetSynGroupParam( - ctypes.c_int(i_syn_group), c_param_name, ctypes.c_float(val) - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) + ret = NESTGPU_SetSynGroupParam(ctypes.c_int(i_syn_group), c_param_name, ctypes.c_float(val)) if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) diff --git a/python/Potjans_2014/eval_microcircuit_time.py b/python/Potjans_2014/eval_microcircuit_time.py index 56cecac97..9dbb3956f 100644 --- a/python/Potjans_2014/eval_microcircuit_time.py +++ b/python/Potjans_2014/eval_microcircuit_time.py @@ -76,9 +76,7 @@ print( "\nTimes:\n" - + " Total time: {:.3f} s\n".format( # of Rank {}:\n'.format( .Rank()) + - time_simulate - time_start - ) + + " Total time: {:.3f} s\n".format(time_simulate - time_start) # of Rank {}:\n'.format( .Rank()) + + " Time to initialize: {:.3f} s\n".format(time_network - time_start) + " Time to create: {:.3f} s\n".format(time_create - time_network) + " Time to connect: {:.3f} s\n".format(time_connect - time_create) diff --git a/python/Potjans_2014/helpers.py b/python/Potjans_2014/helpers.py index 1b7e2b09f..ac7f89b01 100644 --- a/python/Potjans_2014/helpers.py +++ b/python/Potjans_2014/helpers.py @@ -240,9 +240,7 @@ def plot_raster(path, name, begin, end, N_scaling): last_node_id = node_ids[-1, -1] mod_node_ids = np.abs(node_ids - last_node_id) + 1 - label_pos = [ - (mod_node_ids[i, 0] + mod_node_ids[i + 1, 1]) / 2.0 for i in np.arange(0, 8, 2) - ] + label_pos = [(mod_node_ids[i, 0] + mod_node_ids[i + 1, 1]) / 2.0 for i in np.arange(0, 8, 2)] stp = 1 if N_scaling > 0.1: @@ -297,11 +295,7 @@ def firing_rates(path, name, begin, end): all_mean_rates.append(np.mean(rate_per_neuron)) all_std_rates.append(np.std(rate_per_neuron)) print("Mean rates: {} spikes/s".format(np.around(all_mean_rates, decimals=3))) - print( - "Standard deviation of rates: {} spikes/s".format( - np.around(all_std_rates, decimals=3) - ) - ) + print("Standard deviation of rates: {} spikes/s".format(np.around(all_std_rates, decimals=3))) def boxplot(path, populations): @@ -331,9 +325,7 @@ def boxplot(path, populations): rates_per_neuron_rev = [] for i in np.arange(len(populations))[::-1]: - rates_per_neuron_rev.append( - np.loadtxt(os.path.join(path, ("rate" + str(i) + ".dat"))) - ) + rates_per_neuron_rev.append(np.loadtxt(os.path.join(path, ("rate" + str(i) + ".dat")))) plt.figure(figsize=(8, 6)) bp = plt.boxplot( diff --git a/python/Potjans_2014/network.py b/python/Potjans_2014/network.py index eb26feb52..1c0b17003 100644 --- a/python/Potjans_2014/network.py +++ b/python/Potjans_2014/network.py @@ -189,9 +189,7 @@ def evaluate(self, raster_plot_interval, firing_rates_interval): self.net_dict["N_scaling"], ) - print( - "Interval to compute firing rates: {} ms".format(firing_rates_interval) - ) + print("Interval to compute firing rates: {} ms".format(firing_rates_interval)) helpers.firing_rates( self.data_path, "spike_detector", @@ -214,19 +212,11 @@ def __derive_parameters(self): ) # scaled numbers of neurons and synapses - self.num_neurons = np.round( - (self.net_dict["full_num_neurons"] * self.net_dict["N_scaling"]) - ).astype(int) + self.num_neurons = np.round((self.net_dict["full_num_neurons"] * self.net_dict["N_scaling"])).astype(int) self.num_synapses = np.round( - ( - full_num_synapses - * self.net_dict["N_scaling"] - * self.net_dict["K_scaling"] - ) - ).astype(int) - self.ext_indegrees = np.round( - (self.net_dict["K_ext"] * self.net_dict["K_scaling"]) + (full_num_synapses * self.net_dict["N_scaling"] * self.net_dict["K_scaling"]) ).astype(int) + self.ext_indegrees = np.round((self.net_dict["K_ext"] * self.net_dict["K_scaling"])).astype(int) # conversion from PSPs to PSCs PSC_over_PSP = helpers.postsynaptic_potential_to_current( @@ -291,13 +281,9 @@ def __derive_parameters(self): if self.Rank == 0: message = "" if self.net_dict["N_scaling"] != 1: - message += "Neuron numbers are scaled by a factor of {:.3f}.\n".format( - self.net_dict["N_scaling"] - ) + message += "Neuron numbers are scaled by a factor of {:.3f}.\n".format(self.net_dict["N_scaling"]) if self.net_dict["K_scaling"] != 1: - message += "Indegrees are scaled by a factor of {:.3f}.".format( - self.net_dict["K_scaling"] - ) + message += "Indegrees are scaled by a factor of {:.3f}.".format(self.net_dict["K_scaling"]) message += "\n Weights and DC input are adjusted to compensate.\n" print(message) @@ -361,20 +347,13 @@ def __create_neuronal_populations(self): # print(population.n) if self.net_dict["V0_type"] == "optimized": - V_rel_mean = ( - self.net_dict["neuron_params"]["V0_mean"]["optimized"][i] - E_L - ) + V_rel_mean = self.net_dict["neuron_params"]["V0_mean"]["optimized"][i] - E_L V_std = self.net_dict["neuron_params"]["V0_std"]["optimized"][i] elif self.net_dict["V0_type"] == "original": - V_rel_mean = ( - self.net_dict["neuron_params"]["V0_mean"]["original"] - E_L, - ) + V_rel_mean = (self.net_dict["neuron_params"]["V0_mean"]["original"] - E_L,) V_std = self.net_dict["neuron_params"]["V0_std"]["original"] else: - raise Exception( - "V0_type incorrect. " - + 'Valid options are "optimized" and "original".' - ) + raise Exception("V0_type incorrect. " + 'Valid options are "optimized" and "original".') # print("V_rel_mean", V_rel_mean) # print("V_std", V_std) @@ -452,9 +431,7 @@ def __create_thalamic_stim_input(self): if self.Rank == 0: print("Creating thalamic input for external stimulation.") - self.thalamic_population = ngpu.Create( - "parrot_neuron", n=self.stim_dict["num_th_neurons"] - ) + self.thalamic_population = ngpu.Create("parrot_neuron", n=self.stim_dict["num_th_neurons"]) self.poisson_th = ngpu.Create("poisson_generator") self.poisson_th.set( @@ -477,9 +454,7 @@ def __connect_neuronal_populations(self): } w_mean = self.weight_matrix_mean[i][j] - w_std = abs( - self.weight_matrix_mean[i][j] * self.net_dict["weight_rel_std"] - ) + w_std = abs(self.weight_matrix_mean[i][j] * self.net_dict["weight_rel_std"]) if w_mean < 0: w_min = w_mean - 3.0 * w_std @@ -491,10 +466,7 @@ def __connect_neuronal_populations(self): # i_receptor = 0 d_mean = self.net_dict["delay_matrix_mean"][i][j] - d_std = ( - self.net_dict["delay_matrix_mean"][i][j] - * self.net_dict["delay_rel_std"] - ) + d_std = self.net_dict["delay_matrix_mean"][i][j] * self.net_dict["delay_rel_std"] d_min = self.sim_resolution d_max = d_mean + 3.0 * d_std diff --git a/python/Potjans_2014/network_params.py b/python/Potjans_2014/network_params.py index 49d2dc078..652694aa1 100644 --- a/python/Potjans_2014/network_params.py +++ b/python/Potjans_2014/network_params.py @@ -73,9 +73,7 @@ def get_exc_inh_matrix(val_exc, val_inh, num_pops): # necessary for the scaling of the network. # The values were optained by running this PyNEST microcircuit with 12 MPI # processes and both 'N_scaling' and 'K_scaling' set to 1. - "full_mean_rates": np.array( - [0.943, 3.026, 4.368, 5.882, 7.733, 8.664, 1.096, 7.851] - ), + "full_mean_rates": np.array([0.943, 3.026, 4.368, 5.882, 7.733, 8.664, 1.096, 7.851]), # connection probabilities (the first index corresponds to the targets # and the second to the sources) "conn_probs": np.array( diff --git a/python/Potjans_2014/run_microcircuit.py b/python/Potjans_2014/run_microcircuit.py index 3ff887901..d0ab39273 100644 --- a/python/Potjans_2014/run_microcircuit.py +++ b/python/Potjans_2014/run_microcircuit.py @@ -77,12 +77,8 @@ # The computation of spike rates discards the presimulation time to exclude # initialization artifacts. -raster_plot_interval = np.array( - [stim_dict["th_start"] - 100.0, stim_dict["th_start"] + 100.0] -) -firing_rates_interval = np.array( - [sim_dict["t_presim"], sim_dict["t_presim"] + sim_dict["t_sim"]] -) +raster_plot_interval = np.array([stim_dict["th_start"] - 100.0, stim_dict["th_start"] + 100.0]) +firing_rates_interval = np.array([sim_dict["t_presim"], sim_dict["t_presim"] + sim_dict["t_sim"]]) net.evaluate(raster_plot_interval, firing_rates_interval) time_evaluate = time.time() @@ -92,9 +88,7 @@ print( "\nTimes:\n" - + " Total time: {:.3f} s\n".format( # of Rank {}:\n'.format( .Rank()) + - time_evaluate - time_start - ) + + " Total time: {:.3f} s\n".format(time_evaluate - time_start) # of Rank {}:\n'.format( .Rank()) + + " Time to initialize: {:.3f} s\n".format(time_network - time_start) + " Time to create: {:.3f} s\n".format(time_create - time_network) + " Time to connect: {:.3f} s\n".format(time_connect - time_create) diff --git a/python/Potjans_2014_hc/eval_microcircuit_time.py b/python/Potjans_2014_hc/eval_microcircuit_time.py index 56cecac97..9dbb3956f 100644 --- a/python/Potjans_2014_hc/eval_microcircuit_time.py +++ b/python/Potjans_2014_hc/eval_microcircuit_time.py @@ -76,9 +76,7 @@ print( "\nTimes:\n" - + " Total time: {:.3f} s\n".format( # of Rank {}:\n'.format( .Rank()) + - time_simulate - time_start - ) + + " Total time: {:.3f} s\n".format(time_simulate - time_start) # of Rank {}:\n'.format( .Rank()) + + " Time to initialize: {:.3f} s\n".format(time_network - time_start) + " Time to create: {:.3f} s\n".format(time_create - time_network) + " Time to connect: {:.3f} s\n".format(time_connect - time_create) diff --git a/python/Potjans_2014_hc/helpers.py b/python/Potjans_2014_hc/helpers.py index 1b7e2b09f..ac7f89b01 100644 --- a/python/Potjans_2014_hc/helpers.py +++ b/python/Potjans_2014_hc/helpers.py @@ -240,9 +240,7 @@ def plot_raster(path, name, begin, end, N_scaling): last_node_id = node_ids[-1, -1] mod_node_ids = np.abs(node_ids - last_node_id) + 1 - label_pos = [ - (mod_node_ids[i, 0] + mod_node_ids[i + 1, 1]) / 2.0 for i in np.arange(0, 8, 2) - ] + label_pos = [(mod_node_ids[i, 0] + mod_node_ids[i + 1, 1]) / 2.0 for i in np.arange(0, 8, 2)] stp = 1 if N_scaling > 0.1: @@ -297,11 +295,7 @@ def firing_rates(path, name, begin, end): all_mean_rates.append(np.mean(rate_per_neuron)) all_std_rates.append(np.std(rate_per_neuron)) print("Mean rates: {} spikes/s".format(np.around(all_mean_rates, decimals=3))) - print( - "Standard deviation of rates: {} spikes/s".format( - np.around(all_std_rates, decimals=3) - ) - ) + print("Standard deviation of rates: {} spikes/s".format(np.around(all_std_rates, decimals=3))) def boxplot(path, populations): @@ -331,9 +325,7 @@ def boxplot(path, populations): rates_per_neuron_rev = [] for i in np.arange(len(populations))[::-1]: - rates_per_neuron_rev.append( - np.loadtxt(os.path.join(path, ("rate" + str(i) + ".dat"))) - ) + rates_per_neuron_rev.append(np.loadtxt(os.path.join(path, ("rate" + str(i) + ".dat")))) plt.figure(figsize=(8, 6)) bp = plt.boxplot( diff --git a/python/Potjans_2014_hc/network.py b/python/Potjans_2014_hc/network.py index b500a377d..cc54abd59 100644 --- a/python/Potjans_2014_hc/network.py +++ b/python/Potjans_2014_hc/network.py @@ -189,9 +189,7 @@ def evaluate(self, raster_plot_interval, firing_rates_interval): self.net_dict["N_scaling"], ) - print( - "Interval to compute firing rates: {} ms".format(firing_rates_interval) - ) + print("Interval to compute firing rates: {} ms".format(firing_rates_interval)) helpers.firing_rates( self.data_path, "spike_detector", @@ -214,19 +212,11 @@ def __derive_parameters(self): ) # scaled numbers of neurons and synapses - self.num_neurons = np.round( - (self.net_dict["full_num_neurons"] * self.net_dict["N_scaling"]) - ).astype(int) + self.num_neurons = np.round((self.net_dict["full_num_neurons"] * self.net_dict["N_scaling"])).astype(int) self.num_synapses = np.round( - ( - full_num_synapses - * self.net_dict["N_scaling"] - * self.net_dict["K_scaling"] - ) - ).astype(int) - self.ext_indegrees = np.round( - (self.net_dict["K_ext"] * self.net_dict["K_scaling"]) + (full_num_synapses * self.net_dict["N_scaling"] * self.net_dict["K_scaling"]) ).astype(int) + self.ext_indegrees = np.round((self.net_dict["K_ext"] * self.net_dict["K_scaling"])).astype(int) # conversion from PSPs to PSCs PSC_over_PSP = helpers.postsynaptic_potential_to_current( @@ -291,13 +281,9 @@ def __derive_parameters(self): if self.Rank == 0: message = "" if self.net_dict["N_scaling"] != 1: - message += "Neuron numbers are scaled by a factor of {:.3f}.\n".format( - self.net_dict["N_scaling"] - ) + message += "Neuron numbers are scaled by a factor of {:.3f}.\n".format(self.net_dict["N_scaling"]) if self.net_dict["K_scaling"] != 1: - message += "Indegrees are scaled by a factor of {:.3f}.".format( - self.net_dict["K_scaling"] - ) + message += "Indegrees are scaled by a factor of {:.3f}.".format(self.net_dict["K_scaling"]) message += "\n Weights and DC input are adjusted to compensate.\n" print(message) @@ -358,20 +344,13 @@ def __create_neuronal_populations(self): ngpu.SetStatus(population, {"I_e": I_e}) if self.net_dict["V0_type"] == "optimized": - V_rel_mean = ( - self.net_dict["neuron_params"]["V0_mean"]["optimized"][i] - E_L - ) + V_rel_mean = self.net_dict["neuron_params"]["V0_mean"]["optimized"][i] - E_L V_std = self.net_dict["neuron_params"]["V0_std"]["optimized"][i] elif self.net_dict["V0_type"] == "original": - V_rel_mean = ( - self.net_dict["neuron_params"]["V0_mean"]["original"] - E_L, - ) + V_rel_mean = (self.net_dict["neuron_params"]["V0_mean"]["original"] - E_L,) V_std = self.net_dict["neuron_params"]["V0_std"]["original"] else: - raise Exception( - "V0_type incorrect. " - + 'Valid options are "optimized" and "original".' - ) + raise Exception("V0_type incorrect. " + 'Valid options are "optimized" and "original".') # print("V_rel_mean", V_rel_mean) # print("V_std", V_std) @@ -449,9 +428,7 @@ def __create_thalamic_stim_input(self): if self.Rank == 0: print("Creating thalamic input for external stimulation.") - self.thalamic_population = ngpu.Create( - "parrot_neuron", n=self.stim_dict["num_th_neurons"] - ) + self.thalamic_population = ngpu.Create("parrot_neuron", n=self.stim_dict["num_th_neurons"]) self.poisson_th = ngpu.Create("poisson_generator") self.poisson_th.set( @@ -474,9 +451,7 @@ def __connect_neuronal_populations(self): } w_mean = self.weight_matrix_mean[i][j] - w_std = abs( - self.weight_matrix_mean[i][j] * self.net_dict["weight_rel_std"] - ) + w_std = abs(self.weight_matrix_mean[i][j] * self.net_dict["weight_rel_std"]) if w_mean < 0: w_min = w_mean - 3.0 * w_std @@ -488,10 +463,7 @@ def __connect_neuronal_populations(self): # i_receptor = 0 d_mean = self.net_dict["delay_matrix_mean"][i][j] - d_std = ( - self.net_dict["delay_matrix_mean"][i][j] - * self.net_dict["delay_rel_std"] - ) + d_std = self.net_dict["delay_matrix_mean"][i][j] * self.net_dict["delay_rel_std"] d_min = self.sim_resolution d_max = d_mean + 3.0 * d_std diff --git a/python/Potjans_2014_hc/network_params.py b/python/Potjans_2014_hc/network_params.py index 83d37a459..5c4fa1aa3 100644 --- a/python/Potjans_2014_hc/network_params.py +++ b/python/Potjans_2014_hc/network_params.py @@ -73,9 +73,7 @@ def get_exc_inh_matrix(val_exc, val_inh, num_pops): # necessary for the scaling of the network. # The values were optained by running this PyNEST microcircuit with 12 MPI # processes and both 'N_scaling' and 'K_scaling' set to 1. - "full_mean_rates": np.array( - [0.943, 3.026, 4.368, 5.882, 7.733, 8.664, 1.096, 7.851] - ), + "full_mean_rates": np.array([0.943, 3.026, 4.368, 5.882, 7.733, 8.664, 1.096, 7.851]), # connection probabilities (the first index corresponds to the targets # and the second to the sources) "conn_probs": np.array( diff --git a/python/Potjans_2014_hc/run_microcircuit.py b/python/Potjans_2014_hc/run_microcircuit.py index 3ff887901..d0ab39273 100644 --- a/python/Potjans_2014_hc/run_microcircuit.py +++ b/python/Potjans_2014_hc/run_microcircuit.py @@ -77,12 +77,8 @@ # The computation of spike rates discards the presimulation time to exclude # initialization artifacts. -raster_plot_interval = np.array( - [stim_dict["th_start"] - 100.0, stim_dict["th_start"] + 100.0] -) -firing_rates_interval = np.array( - [sim_dict["t_presim"], sim_dict["t_presim"] + sim_dict["t_sim"]] -) +raster_plot_interval = np.array([stim_dict["th_start"] - 100.0, stim_dict["th_start"] + 100.0]) +firing_rates_interval = np.array([sim_dict["t_presim"], sim_dict["t_presim"] + sim_dict["t_sim"]]) net.evaluate(raster_plot_interval, firing_rates_interval) time_evaluate = time.time() @@ -92,9 +88,7 @@ print( "\nTimes:\n" - + " Total time: {:.3f} s\n".format( # of Rank {}:\n'.format( .Rank()) + - time_evaluate - time_start - ) + + " Total time: {:.3f} s\n".format(time_evaluate - time_start) # of Rank {}:\n'.format( .Rank()) + + " Time to initialize: {:.3f} s\n".format(time_network - time_start) + " Time to create: {:.3f} s\n".format(time_create - time_network) + " Time to connect: {:.3f} s\n".format(time_connect - time_create) diff --git a/python/Potjans_2014_s/eval_microcircuit_time.py b/python/Potjans_2014_s/eval_microcircuit_time.py index 56cecac97..9dbb3956f 100644 --- a/python/Potjans_2014_s/eval_microcircuit_time.py +++ b/python/Potjans_2014_s/eval_microcircuit_time.py @@ -76,9 +76,7 @@ print( "\nTimes:\n" - + " Total time: {:.3f} s\n".format( # of Rank {}:\n'.format( .Rank()) + - time_simulate - time_start - ) + + " Total time: {:.3f} s\n".format(time_simulate - time_start) # of Rank {}:\n'.format( .Rank()) + + " Time to initialize: {:.3f} s\n".format(time_network - time_start) + " Time to create: {:.3f} s\n".format(time_create - time_network) + " Time to connect: {:.3f} s\n".format(time_connect - time_create) diff --git a/python/Potjans_2014_s/helpers.py b/python/Potjans_2014_s/helpers.py index 1b7e2b09f..ac7f89b01 100644 --- a/python/Potjans_2014_s/helpers.py +++ b/python/Potjans_2014_s/helpers.py @@ -240,9 +240,7 @@ def plot_raster(path, name, begin, end, N_scaling): last_node_id = node_ids[-1, -1] mod_node_ids = np.abs(node_ids - last_node_id) + 1 - label_pos = [ - (mod_node_ids[i, 0] + mod_node_ids[i + 1, 1]) / 2.0 for i in np.arange(0, 8, 2) - ] + label_pos = [(mod_node_ids[i, 0] + mod_node_ids[i + 1, 1]) / 2.0 for i in np.arange(0, 8, 2)] stp = 1 if N_scaling > 0.1: @@ -297,11 +295,7 @@ def firing_rates(path, name, begin, end): all_mean_rates.append(np.mean(rate_per_neuron)) all_std_rates.append(np.std(rate_per_neuron)) print("Mean rates: {} spikes/s".format(np.around(all_mean_rates, decimals=3))) - print( - "Standard deviation of rates: {} spikes/s".format( - np.around(all_std_rates, decimals=3) - ) - ) + print("Standard deviation of rates: {} spikes/s".format(np.around(all_std_rates, decimals=3))) def boxplot(path, populations): @@ -331,9 +325,7 @@ def boxplot(path, populations): rates_per_neuron_rev = [] for i in np.arange(len(populations))[::-1]: - rates_per_neuron_rev.append( - np.loadtxt(os.path.join(path, ("rate" + str(i) + ".dat"))) - ) + rates_per_neuron_rev.append(np.loadtxt(os.path.join(path, ("rate" + str(i) + ".dat")))) plt.figure(figsize=(8, 6)) bp = plt.boxplot( diff --git a/python/Potjans_2014_s/network.py b/python/Potjans_2014_s/network.py index b36db893c..c3c62901d 100644 --- a/python/Potjans_2014_s/network.py +++ b/python/Potjans_2014_s/network.py @@ -187,9 +187,7 @@ def evaluate(self, raster_plot_interval, firing_rates_interval): self.net_dict["N_scaling"], ) - print( - "Interval to compute firing rates: {} ms".format(firing_rates_interval) - ) + print("Interval to compute firing rates: {} ms".format(firing_rates_interval)) helpers.firing_rates( self.data_path, "spike_detector", @@ -212,19 +210,11 @@ def __derive_parameters(self): ) # scaled numbers of neurons and synapses - self.num_neurons = np.round( - (self.net_dict["full_num_neurons"] * self.net_dict["N_scaling"]) - ).astype(int) + self.num_neurons = np.round((self.net_dict["full_num_neurons"] * self.net_dict["N_scaling"])).astype(int) self.num_synapses = np.round( - ( - full_num_synapses - * self.net_dict["N_scaling"] - * self.net_dict["K_scaling"] - ) - ).astype(int) - self.ext_indegrees = np.round( - (self.net_dict["K_ext"] * self.net_dict["K_scaling"]) + (full_num_synapses * self.net_dict["N_scaling"] * self.net_dict["K_scaling"]) ).astype(int) + self.ext_indegrees = np.round((self.net_dict["K_ext"] * self.net_dict["K_scaling"])).astype(int) # conversion from PSPs to PSCs PSC_over_PSP = helpers.postsynaptic_potential_to_current( @@ -289,13 +279,9 @@ def __derive_parameters(self): if self.Rank == 0: message = "" if self.net_dict["N_scaling"] != 1: - message += "Neuron numbers are scaled by a factor of {:.3f}.\n".format( - self.net_dict["N_scaling"] - ) + message += "Neuron numbers are scaled by a factor of {:.3f}.\n".format(self.net_dict["N_scaling"]) if self.net_dict["K_scaling"] != 1: - message += "Indegrees are scaled by a factor of {:.3f}.".format( - self.net_dict["K_scaling"] - ) + message += "Indegrees are scaled by a factor of {:.3f}.".format(self.net_dict["K_scaling"]) message += "\n Weights and DC input are adjusted to compensate.\n" print(message) @@ -347,20 +333,13 @@ def __create_neuronal_populations(self): ) if self.net_dict["V0_type"] == "optimized": - V_rel_mean = ( - self.net_dict["neuron_params"]["V0_mean"]["optimized"][i] - E_L - ) + V_rel_mean = self.net_dict["neuron_params"]["V0_mean"]["optimized"][i] - E_L V_std = self.net_dict["neuron_params"]["V0_std"]["optimized"][i] elif self.net_dict["V0_type"] == "original": - V_rel_mean = ( - self.net_dict["neuron_params"]["V0_mean"]["original"] - E_L, - ) + V_rel_mean = (self.net_dict["neuron_params"]["V0_mean"]["original"] - E_L,) V_std = self.net_dict["neuron_params"]["V0_std"]["original"] else: - raise Exception( - "V0_type incorrect. " - + 'Valid options are "optimized" and "original".' - ) + raise Exception("V0_type incorrect. " + 'Valid options are "optimized" and "original".') # print("V_rel_mean", V_rel_mean) # print("V_std", V_std) @@ -438,9 +417,7 @@ def __create_thalamic_stim_input(self): if self.Rank == 0: print("Creating thalamic input for external stimulation.") - self.thalamic_population = ngpu.Create( - "parrot_neuron", n=self.stim_dict["num_th_neurons"] - ) + self.thalamic_population = ngpu.Create("parrot_neuron", n=self.stim_dict["num_th_neurons"]) self.poisson_th = ngpu.Create("poisson_generator") self.poisson_th.set( @@ -463,9 +440,7 @@ def __connect_neuronal_populations(self): } w_mean = self.weight_matrix_mean[i][j] - w_std = abs( - self.weight_matrix_mean[i][j] * self.net_dict["weight_rel_std"] - ) + w_std = abs(self.weight_matrix_mean[i][j] * self.net_dict["weight_rel_std"]) if w_mean < 0: w_min = w_mean - 3.0 * w_std @@ -477,10 +452,7 @@ def __connect_neuronal_populations(self): i_receptor = 0 d_mean = self.net_dict["delay_matrix_mean"][i][j] - d_std = ( - self.net_dict["delay_matrix_mean"][i][j] - * self.net_dict["delay_rel_std"] - ) + d_std = self.net_dict["delay_matrix_mean"][i][j] * self.net_dict["delay_rel_std"] d_min = self.sim_resolution d_max = d_mean + 3.0 * d_std diff --git a/python/Potjans_2014_s/network_params.py b/python/Potjans_2014_s/network_params.py index 3e8e5c478..c4e36e757 100644 --- a/python/Potjans_2014_s/network_params.py +++ b/python/Potjans_2014_s/network_params.py @@ -73,9 +73,7 @@ def get_exc_inh_matrix(val_exc, val_inh, num_pops): # necessary for the scaling of the network. # The values were optained by running this PyNEST microcircuit with 12 MPI # processes and both 'N_scaling' and 'K_scaling' set to 1. - "full_mean_rates": np.array( - [0.943, 3.026, 4.368, 5.882, 7.733, 8.664, 1.096, 7.851] - ), + "full_mean_rates": np.array([0.943, 3.026, 4.368, 5.882, 7.733, 8.664, 1.096, 7.851]), # connection probabilities (the first index corresponds to the targets # and the second to the sources) "conn_probs": np.array( diff --git a/python/Potjans_2014_s/run_microcircuit.py b/python/Potjans_2014_s/run_microcircuit.py index 3ff887901..d0ab39273 100644 --- a/python/Potjans_2014_s/run_microcircuit.py +++ b/python/Potjans_2014_s/run_microcircuit.py @@ -77,12 +77,8 @@ # The computation of spike rates discards the presimulation time to exclude # initialization artifacts. -raster_plot_interval = np.array( - [stim_dict["th_start"] - 100.0, stim_dict["th_start"] + 100.0] -) -firing_rates_interval = np.array( - [sim_dict["t_presim"], sim_dict["t_presim"] + sim_dict["t_sim"]] -) +raster_plot_interval = np.array([stim_dict["th_start"] - 100.0, stim_dict["th_start"] + 100.0]) +firing_rates_interval = np.array([sim_dict["t_presim"], sim_dict["t_presim"] + sim_dict["t_sim"]]) net.evaluate(raster_plot_interval, firing_rates_interval) time_evaluate = time.time() @@ -92,9 +88,7 @@ print( "\nTimes:\n" - + " Total time: {:.3f} s\n".format( # of Rank {}:\n'.format( .Rank()) + - time_evaluate - time_start - ) + + " Total time: {:.3f} s\n".format(time_evaluate - time_start) # of Rank {}:\n'.format( .Rank()) + + " Time to initialize: {:.3f} s\n".format(time_network - time_start) + " Time to create: {:.3f} s\n".format(time_create - time_network) + " Time to connect: {:.3f} s\n".format(time_connect - time_create) diff --git a/python/examples/brunel_array.py b/python/examples/brunel_array.py index fe6920b07..2dc247b9f 100644 --- a/python/examples/brunel_array.py +++ b/python/examples/brunel_array.py @@ -52,9 +52,7 @@ # Excitatory connections # connect excitatory neurons to port 0 of all neurons # normally distributed delays, weight Wex and CE connections per neuron -exc_delays = ngpu.RandomNormalClipped( - CE * n_neurons, mean_delay, std_delay, min_delay, mean_delay + 3 * std_delay -) +exc_delays = ngpu.RandomNormalClipped(CE * n_neurons, mean_delay, std_delay, min_delay, mean_delay + 3 * std_delay) exc_conn_dict = {"rule": "fixed_indegree", "indegree": CE} exc_syn_dict = {"weight": Wex, "delay": {"array": exc_delays}, "receptor": 0} @@ -64,9 +62,7 @@ # Inhibitory connections # connect inhibitory neurons to port 1 of all neurons # normally distributed delays, weight Win and CI connections per neuron -inh_delays = ngpu.RandomNormalClipped( - CI * n_neurons, mean_delay, std_delay, min_delay, mean_delay + 3 * std_delay -) +inh_delays = ngpu.RandomNormalClipped(CI * n_neurons, mean_delay, std_delay, min_delay, mean_delay + 3 * std_delay) inh_conn_dict = {"rule": "fixed_indegree", "indegree": CI} inh_syn_dict = {"weight": Win, "delay": {"array": inh_delays}, "receptor": 1} diff --git a/python/examples/temp_mpi.py b/python/examples/temp_mpi.py index d48b14119..87b7dbcc4 100644 --- a/python/examples/temp_mpi.py +++ b/python/examples/temp_mpi.py @@ -55,11 +55,7 @@ exc_neuron = [] inh_neuron = [] for i in range(mpi_np): - neuron.append( - ngpu.RemoteCreate( - i, "aeif_cond_beta_multisynapse", n_neurons, n_receptors - ).node_seq - ) + neuron.append(ngpu.RemoteCreate(i, "aeif_cond_beta_multisynapse", n_neurons, n_receptors).node_seq) exc_neuron.append(neuron[i][0:NE]) # excitatory neurons inh_neuron.append(neuron[i][NE:n_neurons]) # inhibitory neurons @@ -67,9 +63,7 @@ E_rev = [0.0, -85.0] tau_decay = [1.0, 1.0] tau_rise = [1.0, 1.0] -ngpu.SetStatus( - neuron[mpi_id], {"E_rev": E_rev, "tau_decay": tau_decay, "tau_rise": tau_rise} -) +ngpu.SetStatus(neuron[mpi_id], {"E_rev": E_rev, "tau_decay": tau_decay, "tau_rise": tau_rise}) # Excitatory local connections, defined on all hosts # connect excitatory neurons to port 0 of all neurons @@ -137,12 +131,8 @@ for i in range(mpi_np): for j in range(mpi_np): if i != j: - ngpu.RemoteConnect( - i, exc_neuron[i], j, neuron[j], re_conn_dict, re_syn_dict - ) - ngpu.RemoteConnect( - i, inh_neuron[i], j, neuron[j], ri_conn_dict, ri_syn_dict - ) + ngpu.RemoteConnect(i, exc_neuron[i], j, neuron[j], re_conn_dict, re_syn_dict) + ngpu.RemoteConnect(i, inh_neuron[i], j, neuron[j], ri_conn_dict, ri_syn_dict) ngpu.Simulate() diff --git a/python/hpc_benchmark/hpc_benchmark.py b/python/hpc_benchmark/hpc_benchmark.py index 4e09e06ab..4c7417ade 100644 --- a/python/hpc_benchmark/hpc_benchmark.py +++ b/python/hpc_benchmark/hpc_benchmark.py @@ -158,10 +158,7 @@ def convert_synapse_weight(tau_m, tau_syn, C_m): v_max = ( np.exp(1.0) / (tau_syn * C_m * b) - * ( - (np.exp(-t_rise / tau_m) - np.exp(-t_rise / tau_syn)) / b - - t_rise * np.exp(-t_rise / tau_syn) - ) + * ((np.exp(-t_rise / tau_m) - np.exp(-t_rise / tau_syn)) / b - t_rise * np.exp(-t_rise / tau_syn)) ) return 1.0 / v_max @@ -255,9 +252,7 @@ def build_network(): I_pops = [] for i in range(mpi_np): - neurons.append( - ngpu.RemoteCreate(i, "iaf_psc_alpha", NE + NI, 1, model_params).node_seq - ) + neurons.append(ngpu.RemoteCreate(i, "iaf_psc_alpha", NE + NI, 1, model_params).node_seq) E_pops.append(neurons[i][0:NE]) I_pops.append(neurons[i][NE : NE + NI]) @@ -289,9 +284,7 @@ def build_network(): rank_print("Creating excitatory stimulus generator.") # Convert synapse weight from mV to pA - conversion_factor = convert_synapse_weight( - model_params["tau_m"], model_params["tau_syn_ex"], model_params["C_m"] - ) + conversion_factor = convert_synapse_weight(model_params["tau_m"], model_params["tau_syn_ex"], model_params["C_m"]) JE_pA = conversion_factor * brunel_params["JE"] nu_thresh = model_params["Theta_rel"] / ( @@ -303,9 +296,7 @@ def build_network(): brunel_params["poisson_rate"] = rate E_stim = ngpu.Create("poisson_generator", 1, 1, {"rate": rate}) else: - inh_amp = dc_input_compensating_poisson( - rate, CI, tau_syn, brunel_params["g"] * JE_pA - ) + inh_amp = dc_input_compensating_poisson(rate, CI, tau_syn, brunel_params["g"] * JE_pA) ex_amp = dc_input_compensating_poisson(rate, CE, tau_syn, JE_pA) brunel_params["DC_amp_I"] = inh_amp brunel_params["DC_amp_E"] = ex_amp @@ -338,9 +329,7 @@ def build_network(): syn_dict_ex = {"weight": JE_pA, "delay": brunel_params["delay"]} if mpi_id == 0: - rank_print( - "Synaptic weights: JE={}; JI={}".format(JE_pA, JE_pA * brunel_params["g"]) - ) + rank_print("Synaptic weights: JE={}; JI={}".format(JE_pA, JE_pA * brunel_params["g"])) if not params["use_dc_input"]: rank_print("Connecting stimulus generators.") @@ -373,25 +362,17 @@ def build_network(): for i in range(mpi_np): for j in range(mpi_np): if i != j: - rank_print( - "Connecting excitatory {} -> excitatory {} population.".format(i, j) - ) + rank_print("Connecting excitatory {} -> excitatory {} population.".format(i, j)) my_remoteconnect(i, E_pops[i], j, neurons[j], e_conn_rule, syn_dict_ex) - rank_print( - "Connecting inhibitory {} -> excitatory {} population.".format(i, j) - ) + rank_print("Connecting inhibitory {} -> excitatory {} population.".format(i, j)) my_remoteconnect(i, I_pops[i], j, neurons[j], i_conn_rule, syn_dict_in) - rank_print( - "Connecting excitatory {} -> inhibitory {} population.".format(i, j) - ) + rank_print("Connecting excitatory {} -> inhibitory {} population.".format(i, j)) - rank_print( - "Connecting inhibitory {} -> inhibitory {} population.".format(i, j) - ) + rank_print("Connecting inhibitory {} -> inhibitory {} population.".format(i, j)) # read out time used for building time_connect_remote = perf_counter_ns() @@ -501,9 +482,7 @@ def run_simulation(): raster_plot(e_data, i_data) if params["check_conns"]: - with open( - os.path.join(params["path_name"], f"connections_{mpi_id}.json"), "w" - ) as f: + with open(os.path.join(params["path_name"], f"connections_{mpi_id}.json"), "w") as f: json.dump(conns, f, indent=4) k_status = ngpu.GetKernelStatus() @@ -511,18 +490,12 @@ def run_simulation(): rank_print(json.dumps(info_dict, indent=4)) - with open( - os.path.join(params["path_name"], params["log_file"] + f"_{mpi_id}.json"), "w" - ) as f: + with open(os.path.join(params["path_name"], params["log_file"] + f"_{mpi_id}.json"), "w") as f: json.dump(info_dict, f, indent=4) def my_connect(source, target, conn_dict, syn_dict): - rank_print( - "MY id {} LOCAL Source {} {} | Target {} {}".format( - mpi_id, source.i0, source.n, target.i0, target.n - ) - ) + rank_print("MY id {} LOCAL Source {} {} | Target {} {}".format(mpi_id, source.i0, source.n, target.i0, target.n)) ngpu.Connect(source, target, conn_dict, syn_dict) @@ -538,10 +511,7 @@ def my_remoteconnect(source_host, source, target_host, target, conn_dict, syn_di def get_conn_dict_array(source, target): """Retrieve neural connections as an array of dictionaries.""" connectionIdArray = ngpu.GetConnections(source, target) - res = [ - {"i_source": i.i_source, "i_group": i.i_group, "i_conn": i.i_conn} - for i in connectionIdArray - ] + res = [{"i_source": i.i_source, "i_group": i.i_group, "i_conn": i.i_conn} for i in connectionIdArray] return res @@ -577,16 +547,12 @@ def get_spike_times(neurons): # Save data if len(e_data) > 0: e_array = np.array(e_data) - e_fn = os.path.join( - brunel_params["filestem"], brunel_params["recorder_label"] + "_e_pop.dat" - ) + e_fn = os.path.join(brunel_params["filestem"], brunel_params["recorder_label"] + "_e_pop.dat") np.savetxt(e_fn, e_array, fmt="%d\t%.3f", header="sender time_ms", comments="") if len(i_data) > 0: i_array = np.array(i_data) - i_fn = os.path.join( - brunel_params["filestem"], brunel_params["recorder_label"] + "_i_pop.dat" - ) + i_fn = os.path.join(brunel_params["filestem"], brunel_params["recorder_label"] + "_i_pop.dat") np.savetxt(i_fn, i_array, fmt="%d\t%.3f", header="sender time_ms", comments="") return ( diff --git a/python/test/test_brunel_array.py b/python/test/test_brunel_array.py index 4230c303e..b7e64cf16 100644 --- a/python/test/test_brunel_array.py +++ b/python/test/test_brunel_array.py @@ -54,9 +54,7 @@ # Excitatory connections # connect excitatory neurons to port 0 of all neurons # normally distributed delays, weight Wex and CE connections per neuron -exc_delays = ngpu.RandomNormalClipped( - CE * n_neurons, mean_delay, std_delay, min_delay, mean_delay + 3 * std_delay -) +exc_delays = ngpu.RandomNormalClipped(CE * n_neurons, mean_delay, std_delay, min_delay, mean_delay + 3 * std_delay) exc_conn_dict = {"rule": "fixed_indegree", "indegree": CE} exc_syn_dict = {"weight": Wex, "delay": {"array": exc_delays}, "receptor": 0} @@ -66,9 +64,7 @@ # Inhibitory connections # connect inhibitory neurons to port 1 of all neurons # normally distributed delays, weight Win and CI connections per neuron -inh_delays = ngpu.RandomNormalClipped( - CI * n_neurons, mean_delay, std_delay, min_delay, mean_delay + 3 * std_delay -) +inh_delays = ngpu.RandomNormalClipped(CI * n_neurons, mean_delay, std_delay, min_delay, mean_delay + 3 * std_delay) inh_conn_dict = {"rule": "fixed_indegree", "indegree": CI} inh_syn_dict = {"weight": Win, "delay": {"array": inh_delays}, "receptor": 1} diff --git a/python/test/test_stdp/cases/case1.py b/python/test/test_stdp/cases/case1.py index d29fa8716..3380743d2 100644 --- a/python/test/test_stdp/cases/case1.py +++ b/python/test/test_stdp/cases/case1.py @@ -92,9 +92,7 @@ def STDPUpdate(w, Dt, tau_plus, tau_minus, Wplus, alpha, mu_plus, mu_minus, Wmax Wplus = Wmax * lambd Dt1 = 1.0 -w1 = STDPUpdate( - weight_stdp, Dt1, tau_plus, tau_minus, Wplus, alpha, mu_plus, mu_minus, Wmax -) +w1 = STDPUpdate(weight_stdp, Dt1, tau_plus, tau_minus, Wplus, alpha, mu_plus, mu_minus, Wmax) Dt2 = 3.0 w2 = STDPUpdate(w1, Dt2, tau_plus, tau_minus, Wplus, alpha, mu_plus, mu_minus, Wmax) diff --git a/python/test/test_stdp/cases/case10.py b/python/test/test_stdp/cases/case10.py index 9bb242b08..e26845081 100644 --- a/python/test/test_stdp/cases/case10.py +++ b/python/test/test_stdp/cases/case10.py @@ -92,9 +92,7 @@ def STDPUpdate(w, Dt, tau_plus, tau_minus, Wplus, alpha, mu_plus, mu_minus, Wmax Wplus = Wmax * lambd Dt = -2.0 -w1 = STDPUpdate( - weight_stdp, Dt, tau_plus, tau_minus, Wplus, alpha, mu_plus, mu_minus, Wmax -) +w1 = STDPUpdate(weight_stdp, Dt, tau_plus, tau_minus, Wplus, alpha, mu_plus, mu_minus, Wmax) print("Expected theoretical weight: ", w1) diff --git a/python/test/test_stdp/cases/case2.py b/python/test/test_stdp/cases/case2.py index 2418186ad..519798b72 100644 --- a/python/test/test_stdp/cases/case2.py +++ b/python/test/test_stdp/cases/case2.py @@ -92,9 +92,7 @@ def STDPUpdate(w, Dt, tau_plus, tau_minus, Wplus, alpha, mu_plus, mu_minus, Wmax Wplus = Wmax * lambd Dt1 = -1.0 -w1 = STDPUpdate( - weight_stdp, Dt1, tau_plus, tau_minus, Wplus, alpha, mu_plus, mu_minus, Wmax -) +w1 = STDPUpdate(weight_stdp, Dt1, tau_plus, tau_minus, Wplus, alpha, mu_plus, mu_minus, Wmax) Dt2 = 3.0 w2 = STDPUpdate(w1, Dt2, tau_plus, tau_minus, Wplus, alpha, mu_plus, mu_minus, Wmax) diff --git a/python/test/test_stdp/cases/case3.py b/python/test/test_stdp/cases/case3.py index d95734aab..80d15385a 100644 --- a/python/test/test_stdp/cases/case3.py +++ b/python/test/test_stdp/cases/case3.py @@ -92,9 +92,7 @@ def STDPUpdate(w, Dt, tau_plus, tau_minus, Wplus, alpha, mu_plus, mu_minus, Wmax Wplus = Wmax * lambd Dt1 = -1.0 -w1 = STDPUpdate( - weight_stdp, Dt1, tau_plus, tau_minus, Wplus, alpha, mu_plus, mu_minus, Wmax -) +w1 = STDPUpdate(weight_stdp, Dt1, tau_plus, tau_minus, Wplus, alpha, mu_plus, mu_minus, Wmax) Dt2 = -3.5 w2 = STDPUpdate(w1, Dt2, tau_plus, tau_minus, Wplus, alpha, mu_plus, mu_minus, Wmax) diff --git a/python/test/test_stdp/cases/case4.py b/python/test/test_stdp/cases/case4.py index 61236d71a..e1b1e13f1 100644 --- a/python/test/test_stdp/cases/case4.py +++ b/python/test/test_stdp/cases/case4.py @@ -92,9 +92,7 @@ def STDPUpdate(w, Dt, tau_plus, tau_minus, Wplus, alpha, mu_plus, mu_minus, Wmax Wplus = Wmax * lambd Dt1 = 1.0 -w1 = STDPUpdate( - weight_stdp, Dt1, tau_plus, tau_minus, Wplus, alpha, mu_plus, mu_minus, Wmax -) +w1 = STDPUpdate(weight_stdp, Dt1, tau_plus, tau_minus, Wplus, alpha, mu_plus, mu_minus, Wmax) Dt2 = -3.5 w2 = STDPUpdate(w1, Dt2, tau_plus, tau_minus, Wplus, alpha, mu_plus, mu_minus, Wmax) diff --git a/python/test/test_stdp/cases/case5.py b/python/test/test_stdp/cases/case5.py index 440e1b9b2..8e678d553 100644 --- a/python/test/test_stdp/cases/case5.py +++ b/python/test/test_stdp/cases/case5.py @@ -92,9 +92,7 @@ def STDPUpdate(w, Dt, tau_plus, tau_minus, Wplus, alpha, mu_plus, mu_minus, Wmax Wplus = Wmax * lambd Dt = 2.0 -w1 = STDPUpdate( - weight_stdp, Dt, tau_plus, tau_minus, Wplus, alpha, mu_plus, mu_minus, Wmax -) +w1 = STDPUpdate(weight_stdp, Dt, tau_plus, tau_minus, Wplus, alpha, mu_plus, mu_minus, Wmax) print("Expected theoretical weight: ", w1) diff --git a/python/test/test_stdp/cases/case6.py b/python/test/test_stdp/cases/case6.py index 8c39a99de..5ed73742b 100644 --- a/python/test/test_stdp/cases/case6.py +++ b/python/test/test_stdp/cases/case6.py @@ -92,9 +92,7 @@ def STDPUpdate(w, Dt, tau_plus, tau_minus, Wplus, alpha, mu_plus, mu_minus, Wmax Wplus = Wmax * lambd Dt1 = -1.0 -w1 = STDPUpdate( - weight_stdp, Dt1, tau_plus, tau_minus, Wplus, alpha, mu_plus, mu_minus, Wmax -) +w1 = STDPUpdate(weight_stdp, Dt1, tau_plus, tau_minus, Wplus, alpha, mu_plus, mu_minus, Wmax) Dt2 = -3.0 w2 = STDPUpdate(w1, Dt2, tau_plus, tau_minus, Wplus, alpha, mu_plus, mu_minus, Wmax) diff --git a/python/test/test_stdp/cases/case7.py b/python/test/test_stdp/cases/case7.py index a22658e8d..eeb0898cd 100644 --- a/python/test/test_stdp/cases/case7.py +++ b/python/test/test_stdp/cases/case7.py @@ -92,9 +92,7 @@ def STDPUpdate(w, Dt, tau_plus, tau_minus, Wplus, alpha, mu_plus, mu_minus, Wmax Wplus = Wmax * lambd Dt1 = 1.0 -w1 = STDPUpdate( - weight_stdp, Dt1, tau_plus, tau_minus, Wplus, alpha, mu_plus, mu_minus, Wmax -) +w1 = STDPUpdate(weight_stdp, Dt1, tau_plus, tau_minus, Wplus, alpha, mu_plus, mu_minus, Wmax) Dt2 = -3.0 w2 = STDPUpdate(w1, Dt2, tau_plus, tau_minus, Wplus, alpha, mu_plus, mu_minus, Wmax) diff --git a/python/test/test_stdp/cases/case8.py b/python/test/test_stdp/cases/case8.py index 520b7a1d5..240ccd5d2 100644 --- a/python/test/test_stdp/cases/case8.py +++ b/python/test/test_stdp/cases/case8.py @@ -92,9 +92,7 @@ def STDPUpdate(w, Dt, tau_plus, tau_minus, Wplus, alpha, mu_plus, mu_minus, Wmax Wplus = Wmax * lambd Dt1 = 1.0 -w1 = STDPUpdate( - weight_stdp, Dt1, tau_plus, tau_minus, Wplus, alpha, mu_plus, mu_minus, Wmax -) +w1 = STDPUpdate(weight_stdp, Dt1, tau_plus, tau_minus, Wplus, alpha, mu_plus, mu_minus, Wmax) Dt2 = 3.5 w2 = STDPUpdate(w1, Dt2, tau_plus, tau_minus, Wplus, alpha, mu_plus, mu_minus, Wmax) diff --git a/python/test/test_stdp/cases/case9.py b/python/test/test_stdp/cases/case9.py index 029080532..2894d12f9 100644 --- a/python/test/test_stdp/cases/case9.py +++ b/python/test/test_stdp/cases/case9.py @@ -92,9 +92,7 @@ def STDPUpdate(w, Dt, tau_plus, tau_minus, Wplus, alpha, mu_plus, mu_minus, Wmax Wplus = Wmax * lambd Dt1 = -1.0 -w1 = STDPUpdate( - weight_stdp, Dt1, tau_plus, tau_minus, Wplus, alpha, mu_plus, mu_minus, Wmax -) +w1 = STDPUpdate(weight_stdp, Dt1, tau_plus, tau_minus, Wplus, alpha, mu_plus, mu_minus, Wmax) Dt2 = 3.5 w2 = STDPUpdate(w1, Dt2, tau_plus, tau_minus, Wplus, alpha, mu_plus, mu_minus, Wmax) diff --git a/python/test/test_stdp/long_test/test_stdp.py b/python/test/test_stdp/long_test/test_stdp.py index b438840e3..d87edd6a8 100644 --- a/python/test/test_stdp/long_test/test_stdp.py +++ b/python/test/test_stdp/long_test/test_stdp.py @@ -112,9 +112,7 @@ def STDPUpdate(w, Dt, tau_plus, tau_minus, Wplus, alpha, mu_plus, mu_minus, Wmax if (Dt > 1.0e-6) | (Dt < -1.0e-6): w1 = weight_stdp for ispike in range(n_spikes): - w1 = STDPUpdate( - w1, Dt, tau_plus, tau_minus, Wplus, alpha, mu_plus, mu_minus, Wmax - ) + w1 = STDPUpdate(w1, Dt, tau_plus, tau_minus, Wplus, alpha, mu_plus, mu_minus, Wmax) if ispike < n_spikes - 1: w1 = STDPUpdate( w1, diff --git a/pythonlib/nestgpu.py b/pythonlib/nestgpu.py index b3698af86..9406d9255 100644 --- a/pythonlib/nestgpu.py +++ b/pythonlib/nestgpu.py @@ -248,9 +248,7 @@ def Create(model_name, n_node=1, n_ports=1, status_dict=None): elif status_dict != None: raise ValueError("Wrong argument in Create") - c_model_name = ctypes.create_string_buffer( - to_byte_str(model_name), len(model_name) + 1 - ) + c_model_name = ctypes.create_string_buffer(to_byte_str(model_name), len(model_name) + 1) i_node = NESTGPU_Create(c_model_name, ctypes.c_int(n_node), ctypes.c_int(n_ports)) ret = NodeSeq(i_node, n_node) if GetErrorCode() != 0: @@ -286,16 +284,12 @@ def CreatePoissonGenerator(n_node, rate): def CreateRecord(file_name, var_name_list, i_node_list, i_port_list): "Create a record of neuron variables" n_node = len(i_node_list) - c_file_name = ctypes.create_string_buffer( - to_byte_str(file_name), len(file_name) + 1 - ) + c_file_name = ctypes.create_string_buffer(to_byte_str(file_name), len(file_name) + 1) array_int_type = ctypes.c_int * n_node array_char_pt_type = c_char_p * n_node c_var_name_list = [] for i in range(n_node): - c_var_name = ctypes.create_string_buffer( - to_byte_str(var_name_list[i]), len(var_name_list[i]) + 1 - ) + c_var_name = ctypes.create_string_buffer(to_byte_str(var_name_list[i]), len(var_name_list[i]) + 1) c_var_name_list.append(c_var_name) ret = NESTGPU_CreateRecord( @@ -372,12 +366,8 @@ def GetRecordData(i_record): def SetNeuronScalParam(i_node, n_node, param_name, val): "Set neuron scalar parameter value" - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) - ret = NESTGPU_SetNeuronScalParam( - ctypes.c_int(i_node), ctypes.c_int(n_node), c_param_name, ctypes.c_float(val) - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) + ret = NESTGPU_SetNeuronScalParam(ctypes.c_int(i_node), ctypes.c_int(n_node), c_param_name, ctypes.c_float(val)) if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) return ret @@ -396,9 +386,7 @@ def SetNeuronScalParam(i_node, n_node, param_name, val): def SetNeuronArrayParam(i_node, n_node, param_name, param_list): "Set neuron array parameter value" - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) array_size = len(param_list) array_float_type = ctypes.c_float * array_size ret = NESTGPU_SetNeuronArrayParam( @@ -426,14 +414,10 @@ def SetNeuronArrayParam(i_node, n_node, param_name, param_list): def SetNeuronPtScalParam(nodes, param_name, val): "Set neuron list scalar parameter value" n_node = len(nodes) - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) node_arr = (ctypes.c_int * len(nodes))(*nodes) node_pt = ctypes.cast(node_arr, ctypes.c_void_p) - ret = NESTGPU_SetNeuronPtScalParam( - node_pt, ctypes.c_int(n_node), c_param_name, ctypes.c_float(val) - ) + ret = NESTGPU_SetNeuronPtScalParam(node_pt, ctypes.c_int(n_node), c_param_name, ctypes.c_float(val)) if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) return ret @@ -453,9 +437,7 @@ def SetNeuronPtScalParam(nodes, param_name, val): def SetNeuronPtArrayParam(nodes, param_name, param_list): "Set neuron list array parameter value" n_node = len(nodes) - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) node_arr = (ctypes.c_int * len(nodes))(*nodes) node_pt = ctypes.cast(node_arr, ctypes.c_void_p) @@ -480,9 +462,7 @@ def SetNeuronPtArrayParam(nodes, param_name, param_list): def IsNeuronScalParam(i_node, param_name): "Check name of neuron scalar parameter" - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) ret = NESTGPU_IsNeuronScalParam(ctypes.c_int(i_node), c_param_name) != 0 if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) @@ -496,9 +476,7 @@ def IsNeuronScalParam(i_node, param_name): def IsNeuronPortParam(i_node, param_name): "Check name of neuron scalar parameter" - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) ret = NESTGPU_IsNeuronPortParam(ctypes.c_int(i_node), c_param_name) != 0 if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) @@ -512,9 +490,7 @@ def IsNeuronPortParam(i_node, param_name): def IsNeuronArrayParam(i_node, param_name): "Check name of neuron scalar parameter" - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) ret = NESTGPU_IsNeuronArrayParam(ctypes.c_int(i_node), c_param_name) != 0 if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) @@ -528,9 +504,7 @@ def IsNeuronArrayParam(i_node, param_name): def IsNeuronGroupParam(i_node, param_name): "Check name of neuron scalar parameter" - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) ret = NESTGPU_IsNeuronGroupParam(ctypes.c_int(i_node), c_param_name) != 0 if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) @@ -545,9 +519,7 @@ def IsNeuronGroupParam(i_node, param_name): def SetNeuronIntVar(i_node, n_node, var_name, val): "Set neuron integer variable value" c_var_name = ctypes.create_string_buffer(to_byte_str(var_name), len(var_name) + 1) - ret = NESTGPU_SetNeuronIntVar( - ctypes.c_int(i_node), ctypes.c_int(n_node), c_var_name, ctypes.c_int(val) - ) + ret = NESTGPU_SetNeuronIntVar(ctypes.c_int(i_node), ctypes.c_int(n_node), c_var_name, ctypes.c_int(val)) if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) return ret @@ -566,9 +538,7 @@ def SetNeuronIntVar(i_node, n_node, var_name, val): def SetNeuronScalVar(i_node, n_node, var_name, val): "Set neuron scalar variable value" c_var_name = ctypes.create_string_buffer(to_byte_str(var_name), len(var_name) + 1) - ret = NESTGPU_SetNeuronScalVar( - ctypes.c_int(i_node), ctypes.c_int(n_node), c_var_name, ctypes.c_float(val) - ) + ret = NESTGPU_SetNeuronScalVar(ctypes.c_int(i_node), ctypes.c_int(n_node), c_var_name, ctypes.c_float(val)) if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) return ret @@ -619,9 +589,7 @@ def SetNeuronPtIntVar(nodes, var_name, val): node_arr = (ctypes.c_int * len(nodes))(*nodes) node_pt = ctypes.cast(node_arr, ctypes.c_void_p) - ret = NESTGPU_SetNeuronPtIntVar( - node_pt, ctypes.c_int(n_node), c_var_name, ctypes.c_int(val) - ) + ret = NESTGPU_SetNeuronPtIntVar(node_pt, ctypes.c_int(n_node), c_var_name, ctypes.c_int(val)) if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) return ret @@ -644,9 +612,7 @@ def SetNeuronPtScalVar(nodes, var_name, val): node_arr = (ctypes.c_int * len(nodes))(*nodes) node_pt = ctypes.cast(node_arr, ctypes.c_void_p) - ret = NESTGPU_SetNeuronPtScalVar( - node_pt, ctypes.c_int(n_node), c_var_name, ctypes.c_float(val) - ) + ret = NESTGPU_SetNeuronPtScalVar(node_pt, ctypes.c_int(n_node), c_var_name, ctypes.c_float(val)) if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) return ret @@ -747,9 +713,7 @@ def IsNeuronArrayVar(i_node, var_name): def GetNeuronParamSize(i_node, param_name): "Get neuron parameter array size" - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) ret = NESTGPU_GetNeuronParamSize(ctypes.c_int(i_node), c_param_name) if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) @@ -763,12 +727,8 @@ def GetNeuronParamSize(i_node, param_name): def GetNeuronParam(i_node, n_node, param_name): "Get neuron parameter value" - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) - data_pt = NESTGPU_GetNeuronParam( - ctypes.c_int(i_node), ctypes.c_int(n_node), c_param_name - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) + data_pt = NESTGPU_GetNeuronParam(ctypes.c_int(i_node), ctypes.c_int(n_node), c_param_name) array_size = GetNeuronParamSize(i_node, param_name) data_list = [] @@ -796,9 +756,7 @@ def GetNeuronParam(i_node, n_node, param_name): def GetNeuronPtParam(nodes, param_name): "Get neuron list scalar parameter value" n_node = len(nodes) - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) node_arr = (ctypes.c_int * len(nodes))(*nodes) node_pt = ctypes.cast(node_arr, ctypes.c_void_p) data_pt = NESTGPU_GetNeuronPtParam(node_pt, ctypes.c_int(n_node), c_param_name) @@ -828,9 +786,7 @@ def GetNeuronPtParam(nodes, param_name): def GetArrayParam(i_node, n_node, param_name): "Get neuron array parameter" - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) data_list = [] for j_node in range(n_node): i_node1 = i_node + j_node @@ -850,9 +806,7 @@ def GetArrayParam(i_node, n_node, param_name): def GetNeuronListArrayParam(node_list, param_name): "Get neuron array parameter" - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) data_list = [] for i_node in node_list: row_list = [] @@ -876,9 +830,7 @@ def GetNeuronListArrayParam(node_list, param_name): def GetNeuronGroupParam(i_node, param_name): "Check name of neuron group parameter" - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) ret = NESTGPU_GetNeuronGroupParam(ctypes.c_int(i_node), c_param_name) if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) @@ -908,9 +860,7 @@ def GetNeuronVarSize(i_node, var_name): def GetNeuronIntVar(i_node, n_node, var_name): "Get neuron integer variable value" c_var_name = ctypes.create_string_buffer(to_byte_str(var_name), len(var_name) + 1) - data_pt = NESTGPU_GetNeuronIntVar( - ctypes.c_int(i_node), ctypes.c_int(n_node), c_var_name - ) + data_pt = NESTGPU_GetNeuronIntVar(ctypes.c_int(i_node), ctypes.c_int(n_node), c_var_name) data_list = [] for i_node in range(n_node): @@ -931,9 +881,7 @@ def GetNeuronIntVar(i_node, n_node, var_name): def GetNeuronVar(i_node, n_node, var_name): "Get neuron variable value" c_var_name = ctypes.create_string_buffer(to_byte_str(var_name), len(var_name) + 1) - data_pt = NESTGPU_GetNeuronVar( - ctypes.c_int(i_node), ctypes.c_int(n_node), c_var_name - ) + data_pt = NESTGPU_GetNeuronVar(ctypes.c_int(i_node), ctypes.c_int(n_node), c_var_name) array_size = GetNeuronVarSize(i_node, var_name) @@ -1059,9 +1007,7 @@ def GetNeuronStatus(nodes, var_name): raise ValueError("Unknown node type") c_var_name = ctypes.create_string_buffer(to_byte_str(var_name), len(var_name) + 1) if type(nodes) == NodeSeq: - if IsNeuronScalParam(nodes.i0, var_name) | IsNeuronPortParam( - nodes.i0, var_name - ): + if IsNeuronScalParam(nodes.i0, var_name) | IsNeuronPortParam(nodes.i0, var_name): ret = GetNeuronParam(nodes.i0, nodes.n, var_name) elif IsNeuronArrayParam(nodes.i0, var_name): ret = GetArrayParam(nodes.i0, nodes.n, var_name) @@ -1077,9 +1023,7 @@ def GetNeuronStatus(nodes, var_name): else: raise ValueError("Unknown neuron variable or parameter") else: - if IsNeuronScalParam(nodes[0], var_name) | IsNeuronPortParam( - nodes[0], var_name - ): + if IsNeuronScalParam(nodes[0], var_name) | IsNeuronPortParam(nodes[0], var_name): ret = GetNeuronPtParam(nodes, var_name) elif IsNeuronArrayParam(nodes[0], var_name): ret = GetNeuronListArrayParam(nodes, var_name) @@ -1132,9 +1076,7 @@ def GetNScalVar(i_node): def GetIntVarNames(i_node): "Get list of scalar variable names" n_var = GetNIntVar(i_node) - var_name_pp = ctypes.cast( - NESTGPU_GetIntVarNames(ctypes.c_int(i_node)), ctypes.POINTER(c_char_p) - ) + var_name_pp = ctypes.cast(NESTGPU_GetIntVarNames(ctypes.c_int(i_node)), ctypes.POINTER(c_char_p)) var_name_list = [] for i in range(n_var): var_name_p = var_name_pp[i] @@ -1153,9 +1095,7 @@ def GetIntVarNames(i_node): def GetScalVarNames(i_node): "Get list of scalar variable names" n_var = GetNScalVar(i_node) - var_name_pp = ctypes.cast( - NESTGPU_GetScalVarNames(ctypes.c_int(i_node)), ctypes.POINTER(c_char_p) - ) + var_name_pp = ctypes.cast(NESTGPU_GetScalVarNames(ctypes.c_int(i_node)), ctypes.POINTER(c_char_p)) var_name_list = [] for i in range(n_var): var_name_p = var_name_pp[i] @@ -1187,9 +1127,7 @@ def GetNPortVar(i_node): def GetPortVarNames(i_node): "Get list of scalar variable names" n_var = GetNPortVar(i_node) - var_name_pp = ctypes.cast( - NESTGPU_GetPortVarNames(ctypes.c_int(i_node)), ctypes.POINTER(c_char_p) - ) + var_name_pp = ctypes.cast(NESTGPU_GetPortVarNames(ctypes.c_int(i_node)), ctypes.POINTER(c_char_p)) var_name_list = [] for i in range(n_var): var_name_p = var_name_pp[i] @@ -1222,9 +1160,7 @@ def GetNScalParam(i_node): def GetScalParamNames(i_node): "Get list of scalar parameter names" n_param = GetNScalParam(i_node) - param_name_pp = ctypes.cast( - NESTGPU_GetScalParamNames(ctypes.c_int(i_node)), ctypes.POINTER(c_char_p) - ) + param_name_pp = ctypes.cast(NESTGPU_GetScalParamNames(ctypes.c_int(i_node)), ctypes.POINTER(c_char_p)) param_name_list = [] for i in range(n_param): param_name_p = param_name_pp[i] @@ -1257,9 +1193,7 @@ def GetNPortParam(i_node): def GetPortParamNames(i_node): "Get list of scalar parameter names" n_param = GetNPortParam(i_node) - param_name_pp = ctypes.cast( - NESTGPU_GetPortParamNames(ctypes.c_int(i_node)), ctypes.POINTER(c_char_p) - ) + param_name_pp = ctypes.cast(NESTGPU_GetPortParamNames(ctypes.c_int(i_node)), ctypes.POINTER(c_char_p)) param_name_list = [] for i in range(n_param): param_name_p = param_name_pp[i] @@ -1292,9 +1226,7 @@ def GetNArrayParam(i_node): def GetArrayParamNames(i_node): "Get list of scalar parameter names" n_param = GetNArrayParam(i_node) - param_name_pp = ctypes.cast( - NESTGPU_GetArrayParamNames(ctypes.c_int(i_node)), ctypes.POINTER(c_char_p) - ) + param_name_pp = ctypes.cast(NESTGPU_GetArrayParamNames(ctypes.c_int(i_node)), ctypes.POINTER(c_char_p)) param_name_list = [] for i in range(n_param): param_name_p = param_name_pp[i] @@ -1327,9 +1259,7 @@ def GetNGroupParam(i_node): def GetGroupParamNames(i_node): "Get list of scalar parameter names" n_param = GetNGroupParam(i_node) - param_name_pp = ctypes.cast( - NESTGPU_GetGroupParamNames(ctypes.c_int(i_node)), ctypes.POINTER(c_char_p) - ) + param_name_pp = ctypes.cast(NESTGPU_GetGroupParamNames(ctypes.c_int(i_node)), ctypes.POINTER(c_char_p)) param_name_list = [] for i in range(n_param): param_name_p = param_name_pp[i] @@ -1362,9 +1292,7 @@ def GetNArrayVar(i_node): def GetArrayVarNames(i_node): "Get list of scalar variable names" n_var = GetNArrayVar(i_node) - var_name_pp = ctypes.cast( - NESTGPU_GetArrayVarNames(ctypes.c_int(i_node)), ctypes.POINTER(c_char_p) - ) + var_name_pp = ctypes.cast(NESTGPU_GetArrayVarNames(ctypes.c_int(i_node)), ctypes.POINTER(c_char_p)) var_name_list = [] for i in range(n_var): var_name_p = var_name_pp[i] @@ -1393,9 +1321,7 @@ def SetNeuronStatus(nodes, var_name, val): SetNeuronGroupParam(nodes, var_name, val) elif IsNeuronScalParam(nodes.i0, var_name): SetNeuronScalParam(nodes.i0, nodes.n, var_name, val) - elif IsNeuronPortParam(nodes.i0, var_name) | IsNeuronArrayParam( - nodes.i0, var_name - ): + elif IsNeuronPortParam(nodes.i0, var_name) | IsNeuronArrayParam(nodes.i0, var_name): SetNeuronArrayParam(nodes.i0, nodes.n, var_name, val) elif IsNeuronIntVar(nodes.i0, var_name): SetNeuronIntVar(nodes.i0, nodes.n, var_name, val) @@ -1408,9 +1334,7 @@ def SetNeuronStatus(nodes, var_name, val): else: if IsNeuronScalParam(nodes[0], var_name): SetNeuronPtScalParam(nodes, var_name, val) - elif IsNeuronPortParam(nodes[0], var_name) | IsNeuronArrayParam( - nodes[0], var_name - ): + elif IsNeuronPortParam(nodes[0], var_name) | IsNeuronArrayParam(nodes[0], var_name): SetNeuronPtArrayParam(nodes, var_name, val) elif IsNeuronIntVar(nodes[0], var_name): SetNeuronPtIntVar(nodes, var_name, val) @@ -1460,9 +1384,7 @@ def ConnectMpiInit(): for i in range(argc): c_arg = ctypes.create_string_buffer(to_byte_str(sys.argv[i]), 100) c_var_name_list.append(c_arg) - ret = NESTGPU_ConnectMpiInit( - ctypes.c_int(argc), array_char_pt_type(*c_var_name_list) - ) + ret = NESTGPU_ConnectMpiInit(ctypes.c_int(argc), array_char_pt_type(*c_var_name_list)) if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) return ret @@ -1554,9 +1476,7 @@ def RandomUniform(n): def RandomNormal(n, mean, stddev): "Generate n random floats with normal distribution in CUDA memory" - ret = NESTGPU_RandomNormal( - ctypes.c_size_t(n), ctypes.c_float(mean), ctypes.c_float(stddev) - ) + ret = NESTGPU_RandomNormal(ctypes.c_size_t(n), ctypes.c_float(mean), ctypes.c_float(stddev)) if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) return ret @@ -1633,9 +1553,7 @@ def ConnSpecInit(): def SetConnSpecParam(param_name, val): "Set connection parameter" - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) ret = NESTGPU_SetConnSpecParam(c_param_name, ctypes.c_int(val)) if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) @@ -1649,9 +1567,7 @@ def SetConnSpecParam(param_name, val): def ConnSpecIsParam(param_name): "Check name of connection parameter" - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) ret = NESTGPU_ConnSpecIsParam(c_param_name) != 0 if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) @@ -1677,9 +1593,7 @@ def SynSpecInit(): def SetSynSpecIntParam(param_name, val): "Set synapse int parameter" - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) ret = NESTGPU_SetSynSpecIntParam(c_param_name, ctypes.c_int(val)) if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) @@ -1693,9 +1607,7 @@ def SetSynSpecIntParam(param_name, val): def SetSynSpecFloatParam(param_name, val): "Set synapse float parameter" - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) ret = NESTGPU_SetSynSpecFloatParam(c_param_name, ctypes.c_float(val)) if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) @@ -1709,9 +1621,7 @@ def SetSynSpecFloatParam(param_name, val): def SetSynSpecFloatPtParam(param_name, arr): "Set synapse pointer to float parameter" - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) if (type(arr) is list) | (type(arr) is tuple): arr = (ctypes.c_float * len(arr))(*arr) arr_pt = ctypes.cast(arr, ctypes.c_void_p) @@ -1728,9 +1638,7 @@ def SetSynSpecFloatPtParam(param_name, arr): def SynSpecIsIntParam(param_name): "Check name of synapse int parameter" - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) ret = NESTGPU_SynSpecIsIntParam(c_param_name) != 0 if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) @@ -1744,9 +1652,7 @@ def SynSpecIsIntParam(param_name): def SynSpecIsFloatParam(param_name): "Check name of synapse float parameter" - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) ret = NESTGPU_SynSpecIsFloatParam(c_param_name) != 0 if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) @@ -1760,9 +1666,7 @@ def SynSpecIsFloatParam(param_name): def SynSpecIsFloatPtParam(param_name): "Check name of synapse pointer to float parameter" - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) ret = NESTGPU_SynSpecIsFloatPtParam(c_param_name) != 0 if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) @@ -1833,9 +1737,7 @@ def RuleArraySize(conn_dict, source, target): def SetSynParamFromArray(param_name, par_dict, array_size): arr_param_name = param_name + "_array" if not SynSpecIsFloatPtParam(arr_param_name): - raise ValueError( - "Synapse parameter cannot be set by" " arrays or distributions" - ) + raise ValueError("Synapse parameter cannot be set by" " arrays or distributions") arr = DictToArray(par_dict, array_size) array_pt = ctypes.cast(arr, ctypes.c_void_p) @@ -1932,17 +1834,11 @@ def Connect(source, target, conn_dict, syn_dict): target_arr = (ctypes.c_int * len(target))(*target) target_arr_pt = ctypes.cast(target_arr, ctypes.c_void_p) if (type(source) == NodeSeq) & (type(target) != NodeSeq): - ret = NESTGPU_ConnectSeqGroup( - source.i0, source.n, target_arr_pt, len(target) - ) + ret = NESTGPU_ConnectSeqGroup(source.i0, source.n, target_arr_pt, len(target)) elif (type(source) != NodeSeq) & (type(target) == NodeSeq): - ret = NESTGPU_ConnectGroupSeq( - source_arr_pt, len(source), target.i0, target.n - ) + ret = NESTGPU_ConnectGroupSeq(source_arr_pt, len(source), target.i0, target.n) else: - ret = NESTGPU_ConnectGroupGroup( - source_arr_pt, len(source), target_arr_pt, len(target) - ) + ret = NESTGPU_ConnectGroupGroup(source_arr_pt, len(source), target_arr_pt, len(target)) if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) gc.enable() @@ -2037,9 +1933,7 @@ def RemoteConnect(i_source_host, source, i_target_host, target, conn_dict, syn_d else: raise ValueError("Unknown synapse parameter") if (type(source) == NodeSeq) & (type(target) == NodeSeq): - ret = NESTGPU_RemoteConnectSeqSeq( - i_source_host, source.i0, source.n, i_target_host, target.i0, target.n - ) + ret = NESTGPU_RemoteConnectSeqSeq(i_source_host, source.i0, source.n, i_target_host, target.i0, target.n) else: if type(source) != NodeSeq: @@ -2218,9 +2112,7 @@ def GetConnections(source=None, target=None, syn_group=-1): conn_list = [] for i_conn in range(n_conn.value): - conn_id = ConnectionId( - conn_arr[i_conn * 3], conn_arr[i_conn * 3 + 1], conn_arr[i_conn * 3 + 2] - ) + conn_id = ConnectionId(conn_arr[i_conn * 3], conn_arr[i_conn * 3 + 1], conn_arr[i_conn * 3 + 2]) conn_list.append(conn_id) ret = conn_list @@ -2351,9 +2243,7 @@ def CreateSynGroup(model_name, status_dict=None): elif status_dict != None: raise ValueError("Wrong argument in CreateSynGroup") - c_model_name = ctypes.create_string_buffer( - to_byte_str(model_name), len(model_name) + 1 - ) + c_model_name = ctypes.create_string_buffer(to_byte_str(model_name), len(model_name) + 1) i_syn_group = NESTGPU_CreateSynGroup(c_model_name) if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) @@ -2415,9 +2305,7 @@ def IsSynGroupParam(syn_group, param_name): raise ValueError("Wrong argument type in IsSynGroupParam") i_syn_group = syn_group.i_syn_group - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) ret = NESTGPU_IsSynGroupParam(ctypes.c_int(i_syn_group), c_param_name) != 0 if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) @@ -2435,9 +2323,7 @@ def GetSynGroupParam(syn_group, param_name): raise ValueError("Wrong argument type in GetSynGroupParam") i_syn_group = syn_group.i_syn_group - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) ret = NESTGPU_GetSynGroupParam(ctypes.c_int(i_syn_group), c_param_name) @@ -2457,12 +2343,8 @@ def SetSynGroupParam(syn_group, param_name, val): raise ValueError("Wrong argument type in SetSynGroupParam") i_syn_group = syn_group.i_syn_group - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) - ret = NESTGPU_SetSynGroupParam( - ctypes.c_int(i_syn_group), c_param_name, ctypes.c_float(val) - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) + ret = NESTGPU_SetSynGroupParam(ctypes.c_int(i_syn_group), c_param_name, ctypes.c_float(val)) if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) @@ -2597,9 +2479,7 @@ def GetRecSpikeTimes(nodes): spike_times_pt = ctypes.cast(spike_times, c_float_ppp) spike_time_list = [] - ret1 = NESTGPU_GetRecSpikeTimes( - ctypes.c_int(nodes.i0), ctypes.c_int(nodes.n), n_spike_times_pt, spike_times_pt - ) + ret1 = NESTGPU_GetRecSpikeTimes(ctypes.c_int(nodes.i0), ctypes.c_int(nodes.n), n_spike_times_pt, spike_times_pt) for i_n in range(nodes.n): spike_time_list.append([]) n_spike = n_spike_times_pt[0][i_n] @@ -2628,12 +2508,8 @@ def SetNeuronGroupParam(nodes, param_name, val): if type(nodes) != NodeSeq: raise ValueError("Wrong argument type in SetNeuronGroupParam") - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) - ret = NESTGPU_SetNeuronGroupParam( - ctypes.c_int(nodes.i0), ctypes.c_int(nodes.n), c_param_name, ctypes.c_float(val) - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) + ret = NESTGPU_SetNeuronGroupParam(ctypes.c_int(nodes.i0), ctypes.c_int(nodes.n), c_param_name, ctypes.c_float(val)) if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) return ret @@ -2680,9 +2556,7 @@ def GetBoolParamNames(): def IsBoolParam(param_name): "Check name of kernel boolean parameter" - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) ret = NESTGPU_IsBoolParam(c_param_name) != 0 if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) @@ -2697,9 +2571,7 @@ def IsBoolParam(param_name): def GetBoolParam(param_name): "Get kernel boolean parameter value" - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) ret = NESTGPU_GetBoolParam(c_param_name) @@ -2716,9 +2588,7 @@ def GetBoolParam(param_name): def SetBoolParam(param_name, val): "Set kernel boolean parameter value" - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) ret = NESTGPU_SetBoolParam(c_param_name, ctypes.c_bool(val)) if GetErrorCode() != 0: @@ -2767,9 +2637,7 @@ def GetFloatParamNames(): def IsFloatParam(param_name): "Check name of kernel float parameter" - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) ret = NESTGPU_IsFloatParam(c_param_name) != 0 if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) @@ -2784,9 +2652,7 @@ def IsFloatParam(param_name): def GetFloatParam(param_name): "Get kernel float parameter value" - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) ret = NESTGPU_GetFloatParam(c_param_name) @@ -2803,9 +2669,7 @@ def GetFloatParam(param_name): def SetFloatParam(param_name, val): "Set kernel float parameter value" - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) ret = NESTGPU_SetFloatParam(c_param_name, ctypes.c_float(val)) if GetErrorCode() != 0: @@ -2854,9 +2718,7 @@ def GetIntParamNames(): def IsIntParam(param_name): "Check name of kernel int parameter" - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) ret = NESTGPU_IsIntParam(c_param_name) != 0 if GetErrorCode() != 0: raise ValueError(GetErrorMessage()) @@ -2871,9 +2733,7 @@ def IsIntParam(param_name): def GetIntParam(param_name): "Get kernel int parameter value" - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) ret = NESTGPU_GetIntParam(c_param_name) @@ -2890,9 +2750,7 @@ def GetIntParam(param_name): def SetIntParam(param_name, val): "Set kernel int parameter value" - c_param_name = ctypes.create_string_buffer( - to_byte_str(param_name), len(param_name) + 1 - ) + c_param_name = ctypes.create_string_buffer(to_byte_str(param_name), len(param_name) + 1) ret = NESTGPU_SetIntParam(c_param_name, ctypes.c_int(val)) if GetErrorCode() != 0: @@ -2963,12 +2821,8 @@ def RemoteCreate(i_host, model_name, n_node=1, n_ports=1, status_dict=None): elif status_dict != None: raise ValueError("Wrong argument in RemoteCreate") - c_model_name = ctypes.create_string_buffer( - to_byte_str(model_name), len(model_name) + 1 - ) - i_node = NESTGPU_RemoteCreate( - ctypes.c_int(i_host), c_model_name, ctypes.c_int(n_node), ctypes.c_int(n_ports) - ) + c_model_name = ctypes.create_string_buffer(to_byte_str(model_name), len(model_name) + 1) + i_node = NESTGPU_RemoteCreate(ctypes.c_int(i_host), c_model_name, ctypes.c_int(n_node), ctypes.c_int(n_ports)) node_seq = NodeSeq(i_node, n_node) ret = RemoteNodeSeq(i_host, node_seq) if GetErrorCode() != 0: diff --git a/src/write_iaf_psc_exp_hc_params.py b/src/write_iaf_psc_exp_hc_params.py index dc8aee476..7b67e364b 100644 --- a/src/write_iaf_psc_exp_hc_params.py +++ b/src/write_iaf_psc_exp_hc_params.py @@ -12,16 +12,9 @@ def propagator_32(tau_syn, tau, C, h): - P32_linear = ( - 1.0 / (2.0 * C * tau * tau) * h * h * (tau_syn - tau) * np.exp(-h / tau) - ) + P32_linear = 1.0 / (2.0 * C * tau * tau) * h * h * (tau_syn - tau) * np.exp(-h / tau) P32_singular = h / C * np.exp(-h / tau) - P32 = ( - -tau - / (C * (1 - tau / tau_syn)) - * np.exp(-h / tau_syn) - * np.expm1(h * (1 / tau_syn - 1 / tau)) - ) + P32 = -tau / (C * (1 - tau / tau_syn)) * np.exp(-h / tau_syn) * np.expm1(h * (1 / tau_syn - 1 / tau)) dev_P32 = abs(P32 - P32_singular)