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 0000000..2159854 Binary files /dev/null and b/reference_data/soma.ref.h5 differ diff --git a/ringtest.py b/ringtest.py index f79da08..00345ca 100644 --- a/ringtest.py +++ b/ringtest.py @@ -160,6 +160,17 @@ def create_rings(): 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()