Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add CLI option for registering section-segment mapping info #27

Merged
merged 5 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions args.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
71 changes: 58 additions & 13 deletions commonutils.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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)):
Expand Down Expand Up @@ -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")
6 changes: 4 additions & 2 deletions reference_data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Binary file added reference_data/soma.ref.h5
Binary file not shown.
11 changes: 11 additions & 0 deletions ringtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading