Skip to content

Commit

Permalink
Examples compile.
Browse files Browse the repository at this point in the history
  • Loading branch information
thorstenhater committed Nov 28, 2023
1 parent efb612d commit 5d6e09b
Show file tree
Hide file tree
Showing 18 changed files with 72 additions and 107 deletions.
6 changes: 2 additions & 4 deletions example/bench/bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,12 @@ class bench_recipe: public arb::recipe {
}

arb::util::unique_any get_cell_description(arb::cell_gid_type gid) const override {
std::mt19937_64 rng(gid);

// The time_sequence of the cell produces the series of time points at
// which it will spike. We use a poisson_schedule with a random sequence
// seeded with the gid. In this way, a cell's random stream depends only
// on its gid, and will hence give reproducable results when run with
// different MPI ranks and threads.
auto sched = arb::poisson_schedule(1e-3*params_.cell.spike_freq_hz, rng);
auto sched = arb::poisson_schedule(params_.cell.spike_freq_hz*arb::units::Hz, gid);

return arb::benchmark_cell("src", "tgt", sched, params_.cell.realtime_ratio);
}
Expand Down Expand Up @@ -169,7 +167,7 @@ int main(int argc, char** argv) {
meters.checkpoint("model-build", context);

// Run the simulation for 100 ms, with time steps of 0.01 ms.
sim.run(params.duration, 0.01);
sim.run(params.duration*arb::units::ms, 0.01*arb::units::ms);
meters.checkpoint("model-run", context);

// write meters
Expand Down
8 changes: 2 additions & 6 deletions example/brunel/brunel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <fstream>
#include <iomanip>
#include <iostream>
#include <memory>
#include <optional>
#include <set>
#include <vector>
Expand Down Expand Up @@ -139,10 +138,7 @@ class brunel_recipe: public recipe {
}

std::vector<event_generator> event_generators(cell_gid_type gid) const override {
std::mt19937_64 G;
G.seed(gid + seed_);
time_type t0 = 0;
return {poisson_generator({"tgt"}, weight_ext_, t0, lambda_, G)};
return {poisson_generator({"tgt"}, weight_ext_, 0*arb::units::ms, lambda_*arb::units::kHz, gid + seed_)};
}

private:
Expand Down Expand Up @@ -263,7 +259,7 @@ int main(int argc, char** argv) {
meters.checkpoint("model-init", context);

// Run simulation.
sim.run(options.tfinal, options.dt);
sim.run(options.tfinal*arb::units::ms, options.dt*arb::units::ms);

meters.checkpoint("model-simulate", context);

Expand Down
13 changes: 5 additions & 8 deletions example/busyring/ring.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#include <fstream>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <array>
#include <cstring>
#include <functional>

#include <nlohmann/json.hpp>

Expand Down Expand Up @@ -113,7 +110,7 @@ class ring_recipe: public arb::recipe {
// This generates a single event that will kick start the spiking on the sub-ring.
std::vector<arb::event_generator> event_generators(cell_gid_type gid) const override {
if (gid%params_.ring_size == 0) {
return {arb::explicit_generator({"p"}, event_weight_, std::vector<float>{1.0f})};
return {arb::explicit_generator_from_milliseconds({"p"}, event_weight_, std::vector{1.0})};
} else {
return {};
}
Expand Down Expand Up @@ -231,7 +228,7 @@ int main(int argc, char** argv) {
// the cell_member type points to (cell 0, probe 0)
auto probe_id = arb::cell_address_type{0, "Um"};
// The schedule for sampling is 10 samples every 1 ms.
auto sched = arb::regular_schedule(0.1);
auto sched = arb::regular_schedule(0.1*arb::units::ms);
// Now attach the sampler at probe_id, with sampling schedule sched, writing to voltage
sim.add_sampler(arb::one_probe(probe_id), sched, arb::make_simple_sampler(voltage));
}
Expand All @@ -250,7 +247,7 @@ int main(int argc, char** argv) {
// Run the simulation.
if (root) sim.set_epoch_callback(arb::epoch_progress_bar());
if (root) std::cout << "running simulation\n" << std::endl;
sim.run(params.duration, params.dt);
sim.run(params.duration*arb::units::ms, params.dt*arb::units::ms);

meters.checkpoint("model-run", context);

Expand Down Expand Up @@ -423,7 +420,7 @@ arb::cable_cell complex_cell(arb::cell_gid_type gid, const cell_parameters& para
decor.place(syns, arb::synapse("expsyn"), "s");
}

decor.place(cntr, arb::threshold_detector{-20.0}, "d");
decor.place(cntr, arb::threshold_detector{-20.0*arb::units::mV}, "d");

decor.set_default(arb::cv_policy_every_segment());

Expand All @@ -446,7 +443,7 @@ arb::cable_cell branch_cell(arb::cell_gid_type gid, const cell_parameters& param
decor.set_default(arb::axial_resistivity{100}); // [Ω·cm]

// Add spike threshold detector at the soma.
decor.place(arb::mlocation{0,0}, arb::threshold_detector{10}, "d");
decor.place(arb::mlocation{0,0}, arb::threshold_detector{10*arb::units::mV}, "d");

// Add a synapse to proximal end of first dendrite.
decor.place(arb::mlocation{1, 0}, arb::synapse{"expsyn"}, "p");
Expand Down
6 changes: 3 additions & 3 deletions example/diffusion/diffusion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct linear: public recipe {
cell_kind get_cell_kind(cell_gid_type) const override { return cell_kind::cable; }
std::any get_global_properties(cell_kind) const override { return gprop; }
std::vector<probe_info> get_probes(cell_gid_type) const override { return {{cable_probe_ion_diff_concentration_cell{"na"}, "nad"}}; }
std::vector<event_generator> event_generators(cell_gid_type) const override { return {explicit_generator({"Zap"}, 0.005, std::vector<float>{0.f})}; }
std::vector<event_generator> event_generators(cell_gid_type) const override { return {explicit_generator_from_milliseconds({"Zap"}, 0.005, std::vector{0.})}; }
util::unique_any get_cell_description(cell_gid_type) const override {
// Stick morphology
// -----|-----
Expand Down Expand Up @@ -123,7 +123,7 @@ int main(int argc, char** argv) {
auto C = make_context({1, O.gpu});
auto R = linear{O.L, O.dx, O.Xi, O.dX};
simulation S(R, C, partition_load_balance(R, C));
S.add_sampler(all_probes, regular_schedule(O.ds), sampler);
S.run(O.T, O.dt);
S.add_sampler(all_probes, regular_schedule(O.ds*arb::units::ms), sampler);
S.run(O.T*arb::units::ms, O.dt*arb::units::ms);
out.close();
}
12 changes: 2 additions & 10 deletions example/drybench/drybench.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
/*
* A miniapp that demonstrates how to use dry_run mode
*
*/

#include <fstream>
#include <iomanip>
#include <iostream>

#include <nlohmann/json.hpp>
Expand Down Expand Up @@ -79,7 +73,6 @@ std::ostream& operator<<(std::ostream& o, const bench_params& p);
using arb::cell_gid_type;
using arb::cell_lid_type;
using arb::cell_size_type;
using arb::cell_member_type;
using arb::cell_kind;
using arb::time_type;

Expand All @@ -100,8 +93,7 @@ class tile_desc: public arb::tile {
}

arb::util::unique_any get_cell_description(cell_gid_type gid) const override {
using RNG = std::mt19937_64;
auto gen = arb::poisson_schedule(params_.cell.spike_freq_hz/1000, RNG(gid));
auto gen = arb::poisson_schedule(params_.cell.spike_freq_hz*arb::units::Hz, gid);
return arb::benchmark_cell("src", "tgt", std::move(gen), params_.cell.realtime_ratio);
}

Expand Down Expand Up @@ -162,7 +154,7 @@ int main(int argc, char** argv) {
meters.checkpoint("model-init", ctx);

// Run the simulation for 100 ms, with time steps of 0.025 ms.
sim.run(params.duration, 0.025);
sim.run(params.duration*arb::units::ms, 0.025*arb::units::ms);

meters.checkpoint("model-run", ctx);

Expand Down
18 changes: 10 additions & 8 deletions example/dryrun/branch_cell.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct cell_parameters {
unsigned synapses = 1;
};

cell_parameters parse_cell_parameters(nlohmann::json& json) {
inline cell_parameters parse_cell_parameters(nlohmann::json& json) {
cell_parameters params;
sup::param_from_json(params.max_depth, "depth", json);
sup::param_from_json(params.branch_probs, "branch-probs", json);
Expand All @@ -55,7 +55,7 @@ double interp(const std::array<T,2>& r, unsigned i, unsigned n) {
return r[0] + p*(r1-r0);
}

arb::cable_cell branch_cell(arb::cell_gid_type gid, const cell_parameters& params) {
inline arb::cable_cell branch_cell(arb::cell_gid_type gid, const cell_parameters& params) {
arb::segment_tree tree;

// Add soma.
Expand Down Expand Up @@ -110,12 +110,14 @@ arb::cable_cell branch_cell(arb::cell_gid_type gid, const cell_parameters& param
labels.set("dend", tagged(dtag));

auto decor = arb::decor()
.set_default(arb::axial_resistivity{100}) // [Ω·cm]
.paint("soma"_lab, arb::density("hh")) // Add HH dynamics to soma.
.paint("dend"_lab, arb::density("pas")) // Leaky current everywhere else.
.place(arb::mlocation{0,0}, arb::threshold_detector{10}, "detector") // Add spike threshold detector at the soma.
.place(arb::mlocation{0, 0.5}, arb::synapse("expsyn"), "synapse") // Add a synapse to the mid point of the first dendrite.
.set_default(arb::cv_policy_every_segment()); // Make a CV between every sample in the sample tree.
.set_default(arb::axial_resistivity{100}) // [Ω·cm]
.paint("soma"_lab, arb::density("hh")) // Add HH dynamics to soma.
.paint("dend"_lab, arb::density("pas")) // Leaky current everywhere else.
.place(arb::mlocation{0,0},
arb::threshold_detector{10*arb::units::mV},
"detector") // Add spike threshold detector at the soma.
.place(arb::mlocation{0, 0.5}, arb::synapse("expsyn"), "synapse") // Add a synapse to the mid point of the first dendrite.
.set_default(arb::cv_policy_every_segment()); // Make a CV between every sample in the sample tree.

// Add additional synapses that will not be connected to anything.
for (unsigned i=1u; i<params.synapses; ++i) {
Expand Down
14 changes: 4 additions & 10 deletions example/dryrun/dryrun.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/*
* A miniapp that demonstrates how to use dry_run mode
*
*/

#include <any>
#include <cassert>
#include <fstream>
Expand Down Expand Up @@ -56,7 +51,6 @@ run_params read_options(int argc, char** argv);
using arb::cell_gid_type;
using arb::cell_lid_type;
using arb::cell_size_type;
using arb::cell_member_type;
using arb::cell_kind;
using arb::time_type;

Expand Down Expand Up @@ -112,7 +106,7 @@ class tile_desc: public arb::tile {
std::vector<arb::event_generator> event_generators(cell_gid_type gid) const override {
std::vector<arb::event_generator> gens;
if (gid%20 == 0) {
gens.push_back(arb::explicit_generator({"synapse"}, event_weight_, std::vector<float>{1.0f}));
gens.push_back(arb::explicit_generator_from_milliseconds({"synapse"}, event_weight_, std::vector{1.0}));
}
return gens;
}
Expand Down Expand Up @@ -179,8 +173,8 @@ int main(int argc, char** argv) {

// The id of the only probe on the cell: the cell_member type points to (cell 0, probe 0)
auto probeset_id = arb::cell_address_type{0, "Um"};
// The schedule for sampling is 10 samples every 1 ms.
auto sched = arb::regular_schedule(1);
// The schedule for sampling every 1 ms.
auto sched = arb::regular_schedule(1*arb::units::ms);
// This is where the voltage samples will be stored as (time, value) pairs
arb::trace_vector<double> voltage;
// Now attach the sampler at probeset_id, with sampling schedule sched, writing to voltage
Expand All @@ -198,7 +192,7 @@ int main(int argc, char** argv) {
meters.checkpoint("model-init", ctx);

// Run the simulation for 100 ms, with time steps of 0.025 ms.
sim.run(params.duration, 0.025);
sim.run(params.duration*arb::units::ms, 0.025*arb::units::ms);

meters.checkpoint("model-run", ctx);

Expand Down
8 changes: 4 additions & 4 deletions example/gap_junctions/gap_junctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ int main(int argc, char** argv) {

// Set up the probe that will measure voltage in the cell.

auto sched = arb::regular_schedule(0.025);
auto sched = arb::regular_schedule(0.025*arb::units::ms);
// This is where the voltage samples will be stored as (time, value) pairs
std::vector<arb::trace_vector<double>> voltage_traces(decomp.num_local_cells());

Expand All @@ -200,7 +200,7 @@ int main(int argc, char** argv) {

std::cout << "running simulation" << std::endl;
// Run the simulation for 100 ms, with time steps of 0.025 ms.
sim.run(params.sim_duration, 0.025);
sim.run(params.sim_duration*arb::units::ms, 0.025*arb::units::ms);

meters.checkpoint("model-run", context);

Expand Down Expand Up @@ -283,7 +283,7 @@ arb::cable_cell gj_cell(cell_gid_type gid, unsigned ncell, double stim_duration)
.paint("(all)"_reg, arb::density{"kamt", {{"gbar", 0.004}}})
.paint("(all)"_reg, arb::density{"pas/e=-65", {{"g", 1.0/12000.0}}})
// Add a spike detector to the soma.
.place(arb::mlocation{0,0}, arb::threshold_detector{10}, "detector")
.place(arb::mlocation{0,0}, arb::threshold_detector{10*arb::units::mV}, "detector")
// Add two gap junction sites.
.place(arb::mlocation{0, 1}, arb::junction{"gj"}, "local_1")
.place(arb::mlocation{0, 0}, arb::junction{"gj"}, "local_0")
Expand All @@ -292,7 +292,7 @@ arb::cable_cell gj_cell(cell_gid_type gid, unsigned ncell, double stim_duration)

// Attach a stimulus to the first cell of the first group
if (!gid) {
auto stim = arb::i_clamp::box(0, stim_duration, 0.4);
auto stim = arb::i_clamp::box(0*arb::units::ms, stim_duration*arb::units::ms, 0.4*arb::units::nA);
decor.place(arb::mlocation{0, 0.5}, stim, "stim");
}

Expand Down
18 changes: 8 additions & 10 deletions example/generators/generators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <cassert>
#include <fstream>
#include <iomanip>
#include <iostream>

#include <nlohmann/json.hpp>

Expand Down Expand Up @@ -99,15 +98,14 @@ class generator_recipe: public arb::recipe {

// Add excitatory generator
gens.push_back(
arb::poisson_generator({"syn"}, // Target synapse index on cell `gid`
w_e, // Weight of events to deliver
t0, // Events start being delivered from this time
lambda_e, // Expected frequency (kHz)
RNG(29562872))); // Random number generator to use
arb::poisson_generator({"syn"}, // Target synapse index on cell `gid`
w_e, // Weight of events to deliver
t0*arb::units::ms, // Events start being delivered from this time
lambda_e*arb::units::kHz, // Expected frequency (kHz)
29562872)); // Random number generator to use

// Add inhibitory generator
gens.emplace_back(
arb::poisson_generator({"syn"}, w_i, t0, lambda_i, RNG(86543891)));
gens.emplace_back(arb::poisson_generator({"syn"}, w_i, t0*arb::units::ms, lambda_i*arb::units::kHz, 86543891));

return gens;
}
Expand Down Expand Up @@ -138,14 +136,14 @@ int main() {
// The id of the only probe on the cell: the cell_member type points to (cell 0, probe 0)
auto probeset_id = arb::cell_address_type{0, "Um"};
// The schedule for sampling is 10 samples every 1 ms.
auto sched = arb::regular_schedule(0.1);
auto sched = arb::regular_schedule(0.1*arb::units::ms);
// This is where the voltage samples will be stored as (time, value) pairs
arb::trace_vector<double> voltage;
// Now attach the sampler at probeset_id, with sampling schedule sched, writing to voltage
sim.add_sampler(arb::one_probe(probeset_id), sched, arb::make_simple_sampler(voltage));

// Run the simulation for 100 ms, with time steps of 0.01 ms.
sim.run(100, 0.01);
sim.run(100*arb::units::ms, 0.01*arb::units::ms);

// Write the samples to a json file.
write_trace_json(voltage.at(0));
Expand Down
7 changes: 3 additions & 4 deletions example/lfp/lfp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

using std::any;
using arb::util::any_cast;
using arb::util::any_ptr;
using arb::util::unique_any;
using arb::cell_gid_type;

Expand Down Expand Up @@ -185,7 +184,7 @@ int main(int argc, char** argv) {
const double dt = 0.1; // [ms]

// Weight 0.005 μS, onset at t = 0 ms, mean frequency 0.1 kHz.
auto events = arb::poisson_generator({"syn"}, .005, 0., 0.1, std::minstd_rand{});
auto events = arb::poisson_generator({"syn"}, .005, 0.*arb::units::ms, 100*arb::units::Hz);
lfp_demo_recipe recipe(events);
arb::simulation sim(recipe);

Expand All @@ -203,7 +202,7 @@ int main(int argc, char** argv) {

lfp_sampler lfp(placed_cell, current_cables, electrodes, 3.0);

auto sample_schedule = arb::regular_schedule(sample_dt);
auto sample_schedule = arb::regular_schedule(sample_dt*arb::units::ms);
sim.add_sampler(arb::one_probe({0, "Itotal"}), sample_schedule, lfp.callback());

arb::trace_vector<double, arb::mlocation> membrane_voltage;
Expand All @@ -215,7 +214,7 @@ int main(int argc, char** argv) {
arb::trace_vector<double> synapse_g;
sim.add_sampler(arb::one_probe({0, "expsyn-g"}), sample_schedule, make_simple_sampler(synapse_g));

sim.run(t_stop, dt);
sim.run(t_stop*arb::units::ms, dt*arb::units::ms);

// Output results in JSON format suitable for plotting by plot-lfp.py script.

Expand Down
4 changes: 2 additions & 2 deletions example/ornstein_uhlenbeck/ou.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ int main(int argc, char** argv) {
// setup sampler and add it to the simulation with regular schedule
std::vector<arb_value_type> data;
sampler s{data, ncvs, nsteps};
sim.add_sampler(arb::all_probes, arb::regular_schedule(dt), s);
sim.add_sampler(arb::all_probes, arb::regular_schedule(dt*arb::units::ms), s);

// run the simulation
sim.run(nsteps*dt, dt);
sim.run(nsteps*dt*arb::units::ms, dt*arb::units::ms);

// evaluate the mean for each time step across the ensembe of realizations
// (each control volume is a independent realization of the Ornstein-Uhlenbeck process)
Expand Down
Loading

0 comments on commit 5d6e09b

Please sign in to comment.