From 10ffd460a942a46865aca00781ed186a31c2f4b6 Mon Sep 17 00:00:00 2001 From: Weina Ji Date: Fri, 1 Mar 2024 19:58:19 +0100 Subject: [PATCH 1/5] add CLI option for registering report mapping and writing out sim.conf and report.conf --- args.py | 6 +++++ commonutils.py | 63 +++++++++++++++++++++++++++++++++++++++----------- ringtest.py | 10 ++++++++ 3 files changed, 66 insertions(+), 13 deletions(-) diff --git a/args.py b/args.py index 4eba934..a2f6a81 100644 --- a/args.py +++ b/args.py @@ -88,3 +88,9 @@ parser.add_argument("-multisplit", action='store_true', default=False, help="intra-rank thread balance. All pieces of cell on same rank.") + +parser.add_argument("-reportmapping", + dest='report_mapping', + action='store_true', + help="report mapping", + default=False) diff --git a/commonutils.py b/commonutils.py index a0b04ff..bcb2d8e 100644 --- a/commonutils.py +++ b/commonutils.py @@ -1,6 +1,7 @@ import errno import os from neuron import h +from pathlib import Path def mkdir_p(path): try: @@ -107,14 +108,6 @@ def setup_nrnbbcore_register_mapping(rings): #for recording recordlist = [] - #vector for soma sections and segment - somasec = h.Vector() - somaseg = h.Vector() - - #vector for dendrite sections and segment - densec = h.Vector() - denseg = h.Vector() - pc = h.ParallelContext() #all rings in the simulation @@ -123,11 +116,13 @@ def setup_nrnbbcore_register_mapping(rings): #every gid in the ring for gid in ring.gids: - #clear previous vector if any - somasec.size(0) - somaseg.size(0) - densec.size(0) - denseg.size(0) + #vector for soma sections and segment + somasec = h.Vector() + somaseg = h.Vector() + + #vector for dendrite sections and segment + densec = h.Vector() + denseg = h.Vector() #if gid exist on rank if (pc.gid_exists(gid)): @@ -170,3 +165,45 @@ def setup_nrnbbcore_register_mapping(rings): pc.nrnbbcore_register_mapping(gid, "dend", densec, denseg) return recordlist + +def write_report_config(output_file, report_name, target_name, report_type, report_variable, + unit, report_format, target_type, dt, start_time, end_time, gids, + buffer_size=8): + import struct + num_gids = len(gids) + report_conf = Path(output_file) + report_conf.parent.mkdir(parents=True, exist_ok=True) + with report_conf.open("wb") as fp: + # Write the formatted string to the file + fp.write(b"1\n") + fp.write(("%s %s %s %s %s %s %d %lf %lf %lf %d %d\n" % ( + report_name, + target_name, + report_type, + report_variable, + unit, + report_format, + target_type, + dt, + start_time, + end_time, + num_gids, + buffer_size + )).encode()) + # Write the array of integers to the file in binary format + fp.write(struct.pack(f'{num_gids}i', *gids)) + fp.write(b'\n') + fp.write(b"1\n") + fp.write(b"default 0\n") + fp.write(b"spikes.h5\n") + +def write_sim_config(output_file, coredata_dir, report_conf, tstop): + sim_conf = Path(output_file) + sim_conf.parent.mkdir(parents=True, exist_ok=True) + os.makedirs(coredata_dir, exist_ok=True) + with sim_conf.open("w") as fp: + fp.write(f"outpath=./\n") + fp.write(f"datpath=./{coredata_dir}\n") + fp.write(f"tstop={tstop}\n") + fp.write(f"report-conf='{report_conf}'\n") + fp.write("mpi=true\n") diff --git a/ringtest.py b/ringtest.py index 99adedc..0eb5865 100644 --- a/ringtest.py +++ b/ringtest.py @@ -160,6 +160,16 @@ def prun(tstop): print("Error: multi-split is not supported with CoreNEURON\n") quit() + if args.report_mapping: + setup_nrnbbcore_register_mapping(rings) + report_conf_file = "report.conf" + sim_conf_file = "sim.conf" + if settings.rank == 0: + write_report_config(report_conf_file, "soma.h5", "Mosaic", "compartment", "v", + "mV", "SONATA", 2, 0.1, 0, tstop, list(range(ncell))) + write_sim_config(sim_conf_file, "corenrn_data", report_conf_file, tstop) + coreneuron.sim_config=sim_conf_file + ## Record spikes ## spike_record() From c023882865b7affbed14fdd4c56772e79d1c50fe Mon Sep 17 00:00:00 2001 From: Weina Ji Date: Tue, 5 Mar 2024 16:25:03 +0100 Subject: [PATCH 2/5] add reference data for soma report --- reference_data/README.md | 6 ++++-- reference_data/soma.h5 | Bin 0 -> 13704 bytes ringtest.py | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 reference_data/soma.h5 diff --git a/reference_data/README.md b/reference_data/README.md index e9e6bbd..a62d9de 100644 --- a/reference_data/README.md +++ b/reference_data/README.md @@ -2,6 +2,8 @@ This repository also contains reference output from running the `ringtest.py` script. This can be compared against NEURON and CoreNEURON results in -integration tests. At present there is just one reference file generated using -NEURON (`special -python ringtest.py -tstop 100`) with the contemporary +integration tests. + +* spk1.100ms.std.ref : generated using NEURON (`special -python ringtest.py -tstop 100`) with the contemporary `master` commit b55c6e1630665a792ced67c6446ed4fb852c7f79. +* soma.h5 : generated using CORENEURON (`LIBSONATA_ZERO_BASED_GIDS=1 special -mpi -python ringtest.py -tstop 100 -coreneuron -reportmapping`) diff --git a/reference_data/soma.h5 b/reference_data/soma.h5 new file mode 100644 index 0000000000000000000000000000000000000000..215985429537a1c87843e1fb1242d92951f7d924 GIT binary patch literal 13704 zcmeI&dr(wW90%~b@{oKKm?c_Go7#j7m?cg42o_93YD}{l<&T75Ra71k7+ERo-4_eU zb6K@N%BE?0=vZb>R#Wb`ho&~!OOYwbYu$SE$)FI=SL<&@@V`{ey08?1+*T-@LN^#iSmdi~_fCUVAwas)#A0gE`eM&ysITUeB5U67ymxZKV!%(Ip+ zC@#t`EVY&d_F9)&3#^5u-Bn8S3#?jQd0)%^MV_zs0|UB8dC6DFBmZ8?|EDI1{Fd#8 z=KH^&{r}x-QU>ZV76CCSalwl<4bXSwiA$I93*8P2jEJ?GG3FZsV{UCRDI?bacRCAi*iCb4z*g>Q04quKfEDG{fyF=I1{-0j1xxtI3Fh790gJ3~fYr9T z!4|EwgFQLX1-50Y3U=Ut11!m`f{pvw4)(-m8(73|Dp-4L4%o&F6)dj#`gG>~+y-`d z`p?^$vvoPxQ=PeBo60`5u=S7mz}hy(q_O0yTELQ)$ATSAY6cr!Vwq~$N6Klab-fsl+pY(toe6${HRhJv=!;`gOU2|Pvr(dlGoBz85EbiGVu#7f4 z*phuNuoY)iu;(9ff+akpf_*;T0k*5v26knt9qjPBO0bulDp=zaF<>2k*}yXQyqLyZ zYi(fp^A7sio5LOkd+*K`u(nA<(^=(DEnt&gpW|n9XL!NxaN5A$NNEBqo8<%h<7hot z)&VbAXT@r;{l}ZYM#tBHEq${AtaFeD?2*hmu#O}**zhAYU=ubt!D6;}z}lBNz*0YU zgEbb}!CYfpVAZdwV8cIifL#}>f=zzc4z_=T4Xo<03Ra%D7%XL)3YPebIi2m@Z3CM! z>zeH>wf$+Z^^-HfKKiuY&wh0Iz|vB3)7XhX{;`E0M1W0M+zfW=9v@iPF4Uf4kcEBjZaz)wrzzA?2{j>!M?oO2^O=b3M}=6 z9c*Kl3v73^9jv&*3AQ;`1=~N<0haZX4eaIz?O-044eXT`70fr|cCa_1R4{+>o-}r7 zy$x*Grg!}8hAS3;4f~-9?1eKU(^+Dq53Dvb($79A^@5d$F9qAQya{Z_5+7Jrd;{3H z@D{Mw-(L+DdrLFe@!T4)b)5}h<`fT@$6W`uEZYrMGo}`7=w2t-nhp=xwkikMy(ipY zND3aTB^elF1WSpsW)J$K!i6s(|F^g_IbK6h1= ziXO)=)Q0|?KU_SOR+I@7`hF*Jo`Ct*zU#^O?M&#qo}AZWxvlSd7yHrv@=8wIlI7Xw zRg{=npV1=}7i(Vi7Y~^qvgCNkc@Elz_CCL1wup!M5{XCXJP`d(lKqaDUaS05%6T8D z-Th9|U?r(bROme}#Ud{9PSwK`nkVOD-iQ9%Xg?iBk59+gFd}eqL_q$oulF@d;9G&d th_40R_o1A2FQ&nEzj;|twj=Lb*`7R4wkyw<{atrM|7m5uMXz=&^>3WMyWRi* literal 0 HcmV?d00001 diff --git a/ringtest.py b/ringtest.py index 0eb5865..73007c7 100644 --- a/ringtest.py +++ b/ringtest.py @@ -166,7 +166,7 @@ def prun(tstop): sim_conf_file = "sim.conf" if settings.rank == 0: write_report_config(report_conf_file, "soma.h5", "Mosaic", "compartment", "v", - "mV", "SONATA", 2, 0.1, 0, tstop, list(range(ncell))) + "mV", "SONATA", 2, 1, 0, tstop, list(range(ncell))) write_sim_config(sim_conf_file, "corenrn_data", report_conf_file, tstop) coreneuron.sim_config=sim_conf_file From 9ab24ab5fb9d93b9ca8626ac2dafc514e142b9d6 Mon Sep 17 00:00:00 2001 From: Weina Ji Date: Tue, 5 Mar 2024 17:09:35 +0100 Subject: [PATCH 3/5] rename soma ref --- reference_data/{soma.h5 => soma.ref.h5} | Bin 1 file changed, 0 insertions(+), 0 deletions(-) rename reference_data/{soma.h5 => soma.ref.h5} (100%) diff --git a/reference_data/soma.h5 b/reference_data/soma.ref.h5 similarity index 100% rename from reference_data/soma.h5 rename to reference_data/soma.ref.h5 From 60680e3e1516ac23949cd744a12064687d46b332 Mon Sep 17 00:00:00 2001 From: Weina Ji Date: Mon, 11 Mar 2024 08:19:49 +0100 Subject: [PATCH 4/5] rename CLI option --- args.py | 6 +++--- reference_data/README.md | 2 +- ringtest.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/args.py b/args.py index a2f6a81..0c43683 100644 --- a/args.py +++ b/args.py @@ -89,8 +89,8 @@ parser.add_argument("-multisplit", action='store_true', default=False, help="intra-rank thread balance. All pieces of cell on same rank.") -parser.add_argument("-reportmapping", - dest='report_mapping', +parser.add_argument("-registermapping", + dest='register_mapping', action='store_true', - help="report mapping", + help="write section-segment mapping to gid_3.dat file, used for BBP reporting", default=False) diff --git a/reference_data/README.md b/reference_data/README.md index a62d9de..686156e 100644 --- a/reference_data/README.md +++ b/reference_data/README.md @@ -6,4 +6,4 @@ integration tests. * spk1.100ms.std.ref : generated using NEURON (`special -python ringtest.py -tstop 100`) with the contemporary `master` commit b55c6e1630665a792ced67c6446ed4fb852c7f79. -* soma.h5 : generated using CORENEURON (`LIBSONATA_ZERO_BASED_GIDS=1 special -mpi -python ringtest.py -tstop 100 -coreneuron -reportmapping`) +* soma.h5 : generated using CORENEURON (`LIBSONATA_ZERO_BASED_GIDS=1 special -mpi -python ringtest.py -tstop 100 -coreneuron -registermapping`) diff --git a/ringtest.py b/ringtest.py index 73007c7..d195181 100644 --- a/ringtest.py +++ b/ringtest.py @@ -160,7 +160,7 @@ def prun(tstop): print("Error: multi-split is not supported with CoreNEURON\n") quit() - if args.report_mapping: + if args.register_mapping: setup_nrnbbcore_register_mapping(rings) report_conf_file = "report.conf" sim_conf_file = "sim.conf" From 30cd087a8563532482815a8260a2f93a4ae9899b Mon Sep 17 00:00:00 2001 From: Weina Ji Date: Mon, 11 Mar 2024 12:44:06 +0100 Subject: [PATCH 5/5] address review comment --- commonutils.py | 16 ++++++++++++---- ringtest.py | 1 + 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/commonutils.py b/commonutils.py index bcb2d8e..a8d1de0 100644 --- a/commonutils.py +++ b/commonutils.py @@ -2,6 +2,7 @@ import os from neuron import h from pathlib import Path +from typing import List def mkdir_p(path): try: @@ -193,16 +194,23 @@ def write_report_config(output_file, report_name, target_name, report_type, repo # Write the array of integers to the file in binary format fp.write(struct.pack(f'{num_gids}i', *gids)) fp.write(b'\n') - fp.write(b"1\n") - fp.write(b"default 0\n") - fp.write(b"spikes.h5\n") + +def write_spike_config(output_file: str, spike_filename: str, + population_names: List[str], population_offsets: List[int]): + report_conf = Path(output_file) + num_population = len(population_names) + with report_conf.open("a") as fp: + fp.write(f"{num_population}\n") + for pop_name, offset in zip(population_names, population_offsets): + fp.write(f"{pop_name} {offset}\n") + fp.write(f"{spike_filename}\n") def write_sim_config(output_file, coredata_dir, report_conf, tstop): sim_conf = Path(output_file) sim_conf.parent.mkdir(parents=True, exist_ok=True) os.makedirs(coredata_dir, exist_ok=True) with sim_conf.open("w") as fp: - fp.write(f"outpath=./\n") + fp.write("outpath=./\n") fp.write(f"datpath=./{coredata_dir}\n") fp.write(f"tstop={tstop}\n") fp.write(f"report-conf='{report_conf}'\n") diff --git a/ringtest.py b/ringtest.py index d195181..a1990c3 100644 --- a/ringtest.py +++ b/ringtest.py @@ -167,6 +167,7 @@ def prun(tstop): if settings.rank == 0: write_report_config(report_conf_file, "soma.h5", "Mosaic", "compartment", "v", "mV", "SONATA", 2, 1, 0, tstop, list(range(ncell))) + write_spike_config(report_conf_file, "spikes.h5", ["default"], [0]) write_sim_config(sim_conf_file, "corenrn_data", report_conf_file, tstop) coreneuron.sim_config=sim_conf_file