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

Dev #99

Open
wants to merge 18 commits into
base: dev
Choose a base branch
from
Open

Dev #99

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
86 changes: 45 additions & 41 deletions benchmarks/engines/busyring/arbor/ring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ using arb::cell_size_type;
using arb::cell_member_type;
using arb::cell_kind;
using arb::time_type;
using arb::cell_probe_address;
using arb::cable_probe_membrane_voltage;

// Writes voltage trace as a json file.
void write_trace_json(std::string fname, const arb::trace_data<double>& trace);
Expand Down Expand Up @@ -127,12 +127,9 @@ class ring_recipe: public arb::recipe {
}

arb::probe_info get_probe(cell_member_type id) const override {
// Get the appropriate kind for measuring voltage.
cell_probe_address::probe_kind kind = cell_probe_address::membrane_voltage;
// Measure at the soma.
arb::segment_location loc(0, 0.0);

return arb::probe_info{id, kind, cell_probe_address{loc, kind}};
arb::mlocation loc{0, 0.0};
return arb::probe_info{id, 0, cable_probe_membrane_voltage{loc}};
}

private:
Expand All @@ -146,8 +143,7 @@ class ring_recipe: public arb::recipe {
struct cell_stats {
using size_type = unsigned;
size_type ncells = 0;
size_type nsegs = 0;
size_type ncomp = 0;
size_type nbranch = 0;

cell_stats(arb::recipe& r) {
#ifdef ARB_MPI_ENABLED
Expand All @@ -158,30 +154,26 @@ struct cell_stats {
size_type cells_per_rank = ncells/nranks;
size_type b = rank*cells_per_rank;
size_type e = (rank==nranks-1)? ncells: (rank+1)*cells_per_rank;
size_type nsegs_tmp = 0;
size_type ncomp_tmp = 0;
size_type nbranch_tmp = 0;
for (size_type i=b; i<e; ++i) {
auto c = arb::util::any_cast<arb::cable_cell>(r.get_cell_description(i));
nsegs_tmp += c.num_segments();
ncomp_tmp += c.num_compartments();
nbranch_tmp += c.morphology().num_branches();
}
MPI_Allreduce(&nsegs_tmp, &nsegs, 1, MPI_UNSIGNED, MPI_SUM, MPI_COMM_WORLD);
MPI_Allreduce(&ncomp_tmp, &ncomp, 1, MPI_UNSIGNED, MPI_SUM, MPI_COMM_WORLD);
MPI_Allreduce(&nbranch_tmp, &nbranch, 1, MPI_UNSIGNED, MPI_SUM, MPI_COMM_WORLD);
#else
ncells = r.num_cells();
for (size_type i=0; i<ncells; ++i) {
auto c = arb::util::any_cast<arb::cable_cell>(r.get_cell_description(i));
nsegs += c.num_segments();
ncomp += c.num_compartments();
nbranch += c.morphology().num_branches();
}
#endif
}

friend std::ostream& operator<<(std::ostream& o, const cell_stats& s) {
return o << "cell stats: "
<< s.ncells << " cells; "
<< s.nsegs << " segments; "
<< s.ncomp << " compartments.";
<< s.nbranch << " branches; "
<< 0 << " compartments; ";
}
};

Expand Down Expand Up @@ -336,13 +328,11 @@ double interp(const std::array<T,2>& r, unsigned i, unsigned n) {
}

arb::cable_cell branch_cell(arb::cell_gid_type gid, const cell_parameters& params) {
arb::cable_cell cell;

cell.default_parameters.axial_resistivity = 100;
arb::sample_tree tree;

// Add soma.
auto soma = cell.add_soma(12.6157/2.0); // For area of 500 μm².
soma->add_mechanism("hh");
double soma_radius = 12.6157/2.0;
tree.append(arb::mnpos, {{0,0,0,soma_radius}, 1}); // For area of 500 μm².

std::vector<std::vector<unsigned>> levels;
levels.push_back({0});
Expand All @@ -353,7 +343,7 @@ arb::cable_cell branch_cell(arb::cell_gid_type gid, const cell_parameters& param

double dend_radius = 0.5; // Diameter of 1 μm for each cable.

unsigned nsec = 1;
double dist_from_soma = soma_radius;
for (unsigned i=0; i<params.max_depth; ++i) {
// Branch prob at this level.
double bp = interp(params.branch_probs, i, params.max_depth);
Expand All @@ -366,37 +356,51 @@ arb::cable_cell branch_cell(arb::cell_gid_type gid, const cell_parameters& param
for (unsigned sec: levels[i]) {
for (unsigned j=0; j<2; ++j) {
if (dis(gen)<bp) {
sec_ids.push_back(nsec++);
auto dend = cell.add_cable(sec, arb::section_kind::dendrite, dend_radius, dend_radius, l);
dend->set_compartments(nc);
dend->add_mechanism("pas");
auto z = dist_from_soma;
auto p = tree.append(sec, {{0,0,z,dend_radius}, 3});
if (nc>1) {
auto dz = l/nc;
for (unsigned k=1; k<nc; ++k) {
p = tree.append(p, {{0,0,z+k*dz, dend_radius}, 3});
}
}
sec_ids.push_back(tree.append(p, {{0,0,z+l,dend_radius}, 3}));
}
}
}
if (sec_ids.empty()) {
break;
}
levels.push_back(sec_ids);

dist_from_soma += l;
}

arb::label_dict d;

using arb::reg::tagged;
d.set("soma", tagged(1));
d.set("dendrites", join(tagged(3), tagged(4)));

arb::cable_cell cell(arb::morphology(tree, true), d);

cell.paint("soma", "hh");
cell.paint("dendrites", "pas");
cell.default_parameters.axial_resistivity = 100; // [Ω·cm]

// Add spike threshold detector at the soma.
cell.add_detector({0,0}, 10);
cell.place(arb::mlocation{0,0}, arb::threshold_detector{10});

// Add a synapse to the soma for ring network.
// Attach at the soma to minimise delay between event delivery
// and subsequent spikes, which makes it easier to tune firing rate.
cell.add_synapse({0, 0.5}, "expsyn");
// Add a synapse to the mid point of the first dendrite.
cell.place(arb::mlocation{1, 0.5}, "expsyn");

// Add additional synapses to random locations on the cell.
std::uniform_real_distribution<double> pos_dis(0, 1);
std::uniform_int_distribution<cell_lid_type> seg_dis(1, nsec-1);
// Add additional synapses that will not be connected to anything.
for (unsigned i=1u; i<params.synapses; ++i) {
const auto seg = seg_dis(gen);
const auto pos = pos_dis(gen);

cell.add_synapse({seg, pos}, "expsyn");
cell.place(arb::mlocation{1, 0.5}, "expsyn");
}

// Make a CV between every sample in the sample tree.
cell.default_parameters.discretization = arb::cv_policy_every_sample();

return cell;
}

22 changes: 19 additions & 3 deletions common/bin/comparex
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ variable X:
X.abserr.lb max(0, |delta|-interperr)
X.relerr abserr / max |reference|
X.relerr.lb abserr.lb / max |reference|

X.abserr.rms sqrt(mean(delta^2))
X.abserr.rms.lb sqrt(mean(maximum(delta-interperr, 0)^2))
X.relerr.rms sqrt(mean(delta^2)) / max |reference|
X.relerr.rms.lb sqrt(mean(maximum(delta-interperr, 0)^2)) / max |reference|

"""

P.add_argument('input', metavar='FILE', help='input dataset')
Expand Down Expand Up @@ -166,18 +172,28 @@ for var in varlist:
warn(opts.prog, 'no common points for variable \'{}\'', var)
continue

abserr = np.asscalar(np.max(abs(delta)))
abserr_lb = max(0, np.asscalar(np.max(abs(delta)-interperr)))
delta_lb = np.maximum(abs(delta)-interperr, np.zeros_like(delta))

abserr = np.max(abs(delta)).item()
abserr_lb = np.max(delta_lb).item()
abserr_rms = np.sqrt(np.mean(np.square(delta))).item()
abserr_rms_lb = np.sqrt(np.mean(np.square(delta_lb))).item()

r_absmax = np.asscalar(np.max(abs(r.reindex_like(delta))))
r_absmax = np.max(abs(r.reindex_like(delta))).item()
relerr = abserr/r_absmax if r_absmax>0 else 0
relerr_lb = abserr_lb/r_absmax if r_absmax>0 else 0
relerr_rms = abserr_rms/r_absmax if r_absmax>0 else 0
relerr_rms_lb = abserr_rms_lb/r_absmax if r_absmax>0 else 0

out[var+'.delta'] = delta
out[var+'.interperr'] = interperr
out[var+'.abserr'] = abserr
out[var+'.abserr.lb'] = abserr_lb
out[var+'.abserr.rms'] = abserr_rms
out[var+'.abserr.rms.lb'] = abserr_rms_lb
out[var+'.relerr'] = relerr
out[var+'.relerr.lb'] = relerr_lb
out[var+'.relerr.rms'] = relerr_rms
out[var+'.relerr.rms.lb'] = relerr_rms_lb

out.to_netcdf(opts.output)
2 changes: 1 addition & 1 deletion common/bin/tsplotx
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def gather_ts_plots(tss, groupby):

for ts in tss:
key = tuple([ts.meta.get(g) for g in groupby])
if key is () or None in key or key not in group_lookup:
if key == () or None in key or key not in group_lookup:
pretty_key=', '.join([unicode(k)+u'='+unicode(v) for k,v in zip(groupby, key) if v is not None])
pd = PlotData(pretty_key)
pd.series = [ts]
Expand Down
25 changes: 13 additions & 12 deletions docs/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,18 @@ The simulation engines to install are provided as arguments.
Further options for installing the simulation engines in a user-specified path and customising
the build environment can be provided:

==================== ================= ======================================================
Flag Default value Explanation
==================== ================= ======================================================
simulator none Which simulation engines to download and install.
Any number of the following: {``arbor``, ``neuron``, ``coreneuron``, ``all``}.
``--prefix`` current path Path for downloading, compiling, installing simulation engines.
Also used to store inputs and outputs from benchmarks and validation tests.
Can be either a relative or absolute path.
``--env`` none Optional script for configuring the environment and build steps.
See :ref:`customenv`.
==================== ================= ======================================================
========================= ================= ======================================================
Flag Default value Explanation
========================= ================= ======================================================
simulator none Which simulation engines to download and install.
Any number of the following: {``arbor``, ``neuron``, ``coreneuron``, ``all``}.
``--prefix`` current path Path for downloading, compiling, installing simulation engines.
Also used to store inputs and outputs from benchmarks and validation tests.
Can be either a relative or absolute path.
``--env`` none Optional script for configuring the environment and build steps.
See :ref:`customenv`.
``--disable-validation`` false Suppress building of validation.
======================== ================= ======================================================

.. _customenv:

Expand Down Expand Up @@ -184,7 +185,7 @@ Variable Default value Explanat
``ns_arb_arch`` ``native`` `The CPU architecture target <https://arbor.readthedocs.io/en/latest/install.html#architecture>`_
for Arbor. Must be set when cross compiling.
Default ``native`` targets the architecture used to configure NSuite.
``ns_arb_with_gpu`` ``OFF`` Whether to build Arbor with NVIDIA GPU support.
``ns_arb_with_gpu`` ``none`` Whether to build Arbor with GPU support, valid choices are (none|cuda|cuda-clang|hip)
``ns_arb_vectorize`` ``ON`` Whether to use explicit vectorization for Arbor.
======================== =========================================== ======================================================

Expand Down
41 changes: 23 additions & 18 deletions install-local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@ Setup NSuite framework, build and install simulators, benchmarks,
and validation tests.

Options:
--pyvenv=VENVOPT Customize use of Python virtual environment (see below)
--env=SCRIPT Source SCRIPT before building.
--prefix=PATH Use PATH as base for install and other run-time
working directories.

TARGET is one of:
arbor Build Arbor.
neuron Build NEURON.
coreneuron Build CoreNEURON.
all Build all simulators.
--pyvenv=VENVOPT Customize use of Python virtual environment (see below)
--env=SCRIPT Source SCRIPT before building.
--prefix=PATH Use PATH as base for install and other run-time
working directories.
--disable-validation Skip building of validation tests.
TARGET is one of:
arbor Build Arbor.
neuron Build NEURON.
coreneuron Build CoreNEURON.
all Build all simulators.

Building a TARGET will also build any associated tests and
benchmarks as required.

By default, a Python virtual environment is created in which required modules
are installed if they are missing in the system environment.
VENVOPT is one of:
disable Do not use a Python virtualenv at all.
inherit Use a virtualenv, using site packages.
enable Use a virtualenv, ignoring site packages (default).
disable Do not use a Python virtualenv at all.
inherit Use a virtualenv, using site packages.
enable Use a virtualenv, ignoring site packages (default).

_end_
}
Expand Down Expand Up @@ -83,6 +83,9 @@ do
shift
ns_prefix=$1
;;
--disable-validation )
ns_disable_validation=true
;;
* )
echo "unknown option '$1'"
usage
Expand Down Expand Up @@ -201,11 +204,13 @@ cd "$ns_base_path"
[ "$ns_build_coreneuron" = true ] && echo && source "$ns_base_path/scripts/build_coreneuron.sh"
cd "$ns_base_path"

# Always attempt to build validation models/generators.
echo
msghi "Building validation tests and generators"
source "$ns_base_path/scripts/build_validation_models.sh"
cd "$ns_base_path"
# attempt to build validation models/generators.
if [ "$ns_disable_validation" != "true" ]; then
echo
msghi "Building validation tests and generators"
source "$ns_base_path/scripts/build_validation_models.sh"
cd "$ns_base_path"
fi

echo
msghi "Installation finished"
Expand Down
4 changes: 3 additions & 1 deletion scripts/build_arbor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ fi
cd "$arb_build_path"
cmake_args=-DCMAKE_INSTALL_PREFIX:PATH="$ns_install_path"
cmake_args="$cmake_args -DARB_WITH_MPI=$ns_with_mpi"
cmake_args="$cmake_args -DARB_WITH_GPU=$ns_arb_with_gpu"
if [ "$ns_arb_with_gpu" != "none" ]; then
cmake_args="$cmake_args -DARB_GPU=$ns_arb_with_gpu"
fi
cmake_args="$cmake_args -DARB_ARCH=$ns_arb_arch"
cmake_args="$cmake_args -DARB_VECTORIZE=$ns_arb_vectorize"
if [ "$ns_arb_xcompile_modcc" == "ON" ]; then
Expand Down
4 changes: 2 additions & 2 deletions scripts/environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ default_environment() {
# Arbor specific

ns_arb_git_repo=https://github.com/arbor-sim/arbor.git
ns_arb_branch=v0.2.2
ns_arb_branch=master

ns_arb_arch=native
ns_arb_with_gpu=OFF
ns_arb_with_gpu=none
ns_arb_vectorize=ON
ns_arb_xcompile_modcc=OFF

Expand Down
2 changes: 1 addition & 1 deletion systems/daint-gpu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ns_cc=$(which cc)
ns_cxx=$(which CC)
ns_with_mpi=ON

ns_arb_with_gpu=ON
ns_arb_with_gpu=cuda
ns_arb_arch=haswell

export CRAYPE_LINK_TYPE=dynamic
Expand Down
2 changes: 1 addition & 1 deletion systems/jureca-gpu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ ns_cc=$(which mpicc)
ns_cxx=$(which mpicxx)
ns_with_mpi=ON

ns_arb_with_gpu=ON
ns_arb_with_gpu=cuda
ns_arb_arch=haswell
ns_arb_branch=master

Expand Down
2 changes: 1 addition & 1 deletion systems/juwels-gpu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ ns_cc=$(which mpicc)
ns_cxx=$(which mpicxx)
ns_with_mpi=ON

ns_arb_with_gpu=ON
ns_arb_with_gpu=cuda
ns_arb_arch=skylake-avx512

ns_arb_branch=master
Expand Down
Loading