From d40caf64ac24c6ddcf2c082f4b0b7f7ca50657c9 Mon Sep 17 00:00:00 2001 From: WeinaJi Date: Mon, 11 Mar 2024 14:08:09 +0100 Subject: [PATCH] Add CLI option for registering section-segment mapping info (#27) * add CLI option for registering report mapping and writing out sim.conf and report.conf * add reference data for soma report --- args.py | 6 ++++ commonutils.py | 71 ++++++++++++++++++++++++++++++------- reference_data/README.md | 6 ++-- reference_data/soma.ref.h5 | Bin 0 -> 13704 bytes ringtest.py | 11 ++++++ 5 files changed, 79 insertions(+), 15 deletions(-) create mode 100644 reference_data/soma.ref.h5 diff --git a/args.py b/args.py index 4eba934..0c43683 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("-registermapping", + dest='register_mapping', + action='store_true', + help="write section-segment mapping to gid_3.dat file, used for BBP reporting", + default=False) diff --git a/commonutils.py b/commonutils.py index a0b04ff..a8d1de0 100644 --- a/commonutils.py +++ b/commonutils.py @@ -1,6 +1,8 @@ import errno import os from neuron import h +from pathlib import Path +from typing import List def mkdir_p(path): try: @@ -107,14 +109,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 +117,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 +166,52 @@ 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') + +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("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/reference_data/README.md b/reference_data/README.md index e9e6bbd..686156e 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 -registermapping`) diff --git a/reference_data/soma.ref.h5 b/reference_data/soma.ref.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 99adedc..a1990c3 100644 --- a/ringtest.py +++ b/ringtest.py @@ -160,6 +160,17 @@ def prun(tstop): print("Error: multi-split is not supported with CoreNEURON\n") quit() + if args.register_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, 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 + ## Record spikes ## spike_record()