Commit 7218276d authored by Gauthier Quesnel's avatar Gauthier Quesnel
Browse files

wip

parent 14fefa18
Pipeline #38366 failed with stage
in 1 minute and 18 seconds
......@@ -9,9 +9,11 @@ BinPackParameters: false
Standard: c++20
AlignOperands: true
AlignTrailingComments: true
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortFunctionsOnASingleLine: All
IndentCaseLabels: false
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
......
This diff is collapsed.
This diff is collapsed.
......@@ -72,13 +72,13 @@ static inline const char* dynamics_type_names[] = { "none",
static_assert(std::size(dynamics_type_names) ==
static_cast<sz>(dynamics_type_size()));
static inline const char* str_empty[] = { "" };
static inline const char* str_integrator[] = { "x-dot", "reset" };
static inline const char* str_empty[] = { "" };
static inline const char* str_integrator[] = { "x-dot", "reset" };
static inline const char* str_adaptative_integrator[] = { "quanta",
"x-dot",
"reset" };
static inline const char* str_in_1[] = { "in" };
static inline const char* str_in_2[] = { "in-1", "in-2" };
static inline const char* str_in_1[] = { "in" };
static inline const char* str_in_2[] = { "in-1", "in-2" };
static inline const char* str_in_3[] = { "in-1", "in-2", "in-3" };
static inline const char* str_in_4[] = { "in-1", "in-2", "in-3", "in-4" };
static inline const char* str_value_if_else[] = { "value",
......@@ -246,7 +246,7 @@ get_input_port_names(const dynamics_type type) noexcept
irt_unreachable();
}
static inline const char* str_out_1[] = { "out" };
static inline const char* str_out_1[] = { "out" };
static inline const char* str_out_cross[] = { "if-value",
"else-value",
"event" };
......@@ -389,12 +389,12 @@ get_output_port_names(const dynamics_type type) noexcept
class streambuf : public std::streambuf
{
public:
std::streambuf* m_stream_buffer = { nullptr };
std::streamsize m_file_position = { 0 };
int m_line_number = { 1 };
int m_last_line_number = { 1 };
int m_column = { 0 };
int m_prev_column = { -1 };
std::streambuf* m_stream_buffer = { nullptr };
std::streamsize m_file_position = { 0 };
int m_line_number = { 1 };
int m_last_line_number = { 1 };
int m_column = { 0 };
int m_prev_column = { -1 };
streambuf(std::streambuf* sbuf)
: m_stream_buffer(sbuf)
......@@ -417,7 +417,7 @@ protected:
if (traits_type::eq_int_type(rc, traits_type::to_int_type('\n'))) {
++m_line_number;
m_prev_column = m_column + 1;
m_column = -1;
m_column = -1;
}
++m_column;
......@@ -432,8 +432,8 @@ protected:
if (traits_type::eq_int_type(c, traits_type::to_int_type('\n'))) {
--m_line_number;
m_last_line_number = m_line_number;
m_column = m_prev_column;
m_prev_column = 0;
m_column = m_prev_column;
m_prev_column = 0;
}
--m_column;
......@@ -445,17 +445,17 @@ protected:
return m_stream_buffer->sungetc();
}
std::ios::pos_type seekoff(std::ios::off_type pos,
std::ios_base::seekdir dir,
std::ios::pos_type seekoff(std::ios::off_type pos,
std::ios_base::seekdir dir,
std::ios_base::openmode mode) override final
{
if (dir == std::ios_base::beg &&
pos == static_cast<std::ios::off_type>(0)) {
m_last_line_number = 1;
m_line_number = 1;
m_column = 0;
m_prev_column = -1;
m_file_position = 0;
m_line_number = 1;
m_column = 0;
m_prev_column = -1;
m_file_position = 0;
return m_stream_buffer->pubseekoff(pos, dir, mode);
}
......@@ -463,15 +463,15 @@ protected:
return std::streambuf::seekoff(pos, dir, mode);
}
std::ios::pos_type seekpos(std::ios::pos_type pos,
std::ios::pos_type seekpos(std::ios::pos_type pos,
std::ios_base::openmode mode) override final
{
if (pos == static_cast<std::ios::pos_type>(0)) {
m_last_line_number = 1;
m_line_number = 1;
m_column = 0;
m_prev_column = -1;
m_file_position = 0;
m_line_number = 1;
m_column = 0;
m_prev_column = -1;
m_file_position = 0;
return m_stream_buffer->pubseekpos(pos, mode);
}
......@@ -483,7 +483,7 @@ protected:
class reader
{
private:
streambuf buf;
streambuf buf;
std::istream is;
struct mapping
......@@ -500,6 +500,26 @@ private:
{
return index < other.index;
}
bool operator<(int i) const noexcept { return index < i; }
};
struct mapping_compare
{
bool operator()(const mapping& lhs, const mapping& rhs)
{
return lhs.index < rhs.index;
}
bool operator()(int index, const mapping& rhs)
{
return index < rhs.index;
}
bool operator()(const mapping& lhs, int index)
{
return lhs.index < index;
}
};
struct position
......@@ -516,13 +536,13 @@ private:
std::vector<model_id> map;
std::vector<position> positions; /* Stores positions of the models. */
std::vector<mapping> constant_mapping;
std::vector<mapping> binary_file_mapping;
std::vector<mapping> random_mapping;
std::vector<mapping> text_file_mapping;
std::vector<mapping> constant_mapping;
std::vector<mapping> binary_file_mapping;
std::vector<mapping> random_mapping;
std::vector<mapping> text_file_mapping;
int source_number = 0;
int model_number = 0;
int model_number = 0;
char temp_1[32];
char temp_2[32];
......@@ -535,18 +555,12 @@ public:
~reader() noexcept = default;
int model_error = 0;
int model_error = 0;
int connection_error = 0;
int line_error() const noexcept
{
return buf.m_line_number;
}
int line_error() const noexcept { return buf.m_line_number; }
int column_error() const noexcept
{
return buf.m_column;
}
int column_error() const noexcept { return buf.m_column; }
position get_position(const sz index) const noexcept
{
......@@ -569,8 +583,8 @@ public:
return status::success;
}
status operator()(simulation& sim,
external_source& srcs,
status operator()(simulation& sim,
external_source& srcs,
function_ref<void(const model_id)> f) noexcept
{
irt_return_if_bad(do_read_data_source(srcs));
......@@ -643,7 +657,7 @@ private:
status do_read_constant_source(external_source& srcs) noexcept
{
u32 id;
sz size;
sz size;
if (!(is >> id >> size))
return status::io_file_format_error;
......@@ -924,7 +938,7 @@ private:
irt_return_if_fail(mdl_dst, status::io_file_format_model_unknown);
output_port* out = nullptr;
input_port* in = nullptr;
input_port* in = nullptr;
irt_return_if_bad(get_output_port(*mdl_src, port_src_index, out));
irt_return_if_bad(get_input_port(*mdl_dst, port_dst_index, in));
......@@ -939,18 +953,18 @@ private:
}
bool convert(const std::string_view dynamics_name,
dynamics_type* type) noexcept
dynamics_type* type) noexcept
{
struct string_to_type
{
constexpr string_to_type(const std::string_view n,
const dynamics_type t)
const dynamics_type t)
: name(n)
, type(t)
{}
const std::string_view name;
dynamics_type type;
dynamics_type type;
};
static constexpr string_to_type table[] = {
......@@ -1015,7 +1029,7 @@ private:
std::lower_bound(std::begin(table),
std::end(table),
dynamics_name,
[](const string_to_type& l,
[](const string_to_type& l,
const std::string_view r) { return l.name < r; });
if (it != std::end(table) && it->name == dynamics_name) {
......@@ -1027,7 +1041,7 @@ private:
}
status do_read_dynamics(simulation& sim,
int id,
int id,
const char* dynamics_name) noexcept
{
dynamics_type type;
......@@ -1052,10 +1066,7 @@ private:
return status::success;
}
bool read(simulation& /*sim*/, none& /*dyn*/) noexcept
{
return true;
}
bool read(simulation& /*sim*/, none& /*dyn*/) noexcept { return true; }
bool read(simulation& /*sim*/, qss1_integrator& dyn) noexcept
{
......@@ -1294,10 +1305,7 @@ private:
dyn.default_input_coeffs[2] >> dyn.default_input_coeffs[3]);
}
bool read(simulation& /*sim*/, counter& /*dyn*/) noexcept
{
return true;
}
bool read(simulation& /*sim*/, counter& /*dyn*/) noexcept { return true; }
bool read(simulation& /*sim*/, queue& dyn) noexcept
{
......@@ -1305,65 +1313,61 @@ private:
}
bool read_source(simulation& /*sim*/,
source& src,
int index,
source& src,
int index,
external_source_type type)
{
switch (type) {
case external_source_type::binary_file: {
auto it = binary_find(
binary_file_mapping.begin(),
binary_file_mapping.end(),
index,
[](const auto elem, int i) { return i == elem.index; });
auto it = binary_find(binary_file_mapping.begin(),
binary_file_mapping.end(),
index,
mapping_compare());
if (it == binary_file_mapping.end())
return false;
src.type = ordinal(type);
src.id = it->value;
src.id = it->value;
return true;
};
case external_source_type::constant: {
auto it = binary_find(
constant_mapping.begin(),
constant_mapping.end(),
index,
[](const auto elem, int i) { return i == elem.index; });
auto it = binary_find(constant_mapping.begin(),
constant_mapping.end(),
index,
mapping_compare());
if (it == constant_mapping.end())
return false;
src.type = ordinal(type);
src.id = it->value;
src.id = it->value;
return true;
};
case external_source_type::text_file: {
auto it = binary_find(
text_file_mapping.begin(),
text_file_mapping.end(),
index,
[](const auto elem, int i) { return i == elem.index; });
auto it = binary_find(text_file_mapping.begin(),
text_file_mapping.end(),
index,
mapping_compare());
if (it == text_file_mapping.end())
return false;
src.type = ordinal(type);
src.id = it->value;
src.id = it->value;
return true;
};
case external_source_type::random: {
auto it = binary_find(
random_mapping.begin(),
random_mapping.end(),
index,
[](const auto elem, int i) { return i == elem.index; });
auto it = binary_find(random_mapping.begin(),
random_mapping.end(),
index,
mapping_compare());
if (it == random_mapping.end())
return false;
src.type = ordinal(type);
src.id = it->value;
src.id = it->value;
return true;
};
}
......@@ -1512,7 +1516,7 @@ private:
struct writer
{
std::ostream& os;
std::ostream& os;
std::vector<model_id> map;
writer(std::ostream& os_) noexcept
......@@ -1526,7 +1530,7 @@ struct writer
if (srcs.size() > 0u) {
constant_source* src = nullptr;
while (srcs.next(src)) {
const auto id = srcs.get_id(src);
const auto id = srcs.get_id(src);
const auto index = get_index(id);
os << index << ' ' << src->buffer.size();
......@@ -1545,7 +1549,7 @@ struct writer
if (srcs.size() > 0u) {
binary_file_source* src = nullptr;
while (srcs.next(src)) {
const auto id = srcs.get_id(src);
const auto id = srcs.get_id(src);
const auto index = get_index(id);
os << index << ' ' << std::quoted(src->file_path.string())
......@@ -1561,7 +1565,7 @@ struct writer
if (srcs.size() > 0u) {
text_file_source* src = nullptr;
while (srcs.next(src)) {
const auto id = srcs.get_id(src);
const auto id = srcs.get_id(src);
const auto index = get_index(id);
os << index << ' ' << std::quoted(src->file_path.string())
......@@ -1577,7 +1581,7 @@ struct writer
if (srcs.size() > 0u) {
random_source* src = nullptr;
while (srcs.next(src)) {
const auto id = srcs.get_id(src);
const auto id = srcs.get_id(src);
const auto index = get_index(id);
os << index << ' ' << distribution_str(src->distribution);
......@@ -1629,10 +1633,10 @@ struct writer
void write_model(const simulation& sim)
{
model* mdl = nullptr;
int id = 0;
int id = 0;
while (sim.models.next(mdl)) {
const auto mdl_id = sim.models.get_id(mdl);
map[id] = mdl_id;
map[id] = mdl_id;
os << id << " 0.0 0.0 ";
......@@ -1643,15 +1647,15 @@ struct writer
}
}
void write_model(const simulation& sim,
void write_model(const simulation& sim,
function_ref<void(model_id, float& x, float& y)> get_pos)
{
model* mdl = nullptr;
int id = 0;
int id = 0;
while (sim.models.next(mdl)) {
const auto mdl_id = sim.models.get_id(mdl);
map[id] = mdl_id;
map[id] = mdl_id;
float x = 0., y = 0.;
get_pos(mdl_id, x, y);
......@@ -1664,7 +1668,7 @@ struct writer
}
}
status operator()(const simulation& sim,
status operator()(const simulation& sim,
const external_source& srcs) noexcept
{
write_constant_sources(srcs.constant_sources);
......@@ -1686,8 +1690,8 @@ struct writer
}
status operator()(
const simulation& sim,
const external_source& srcs,
const simulation& sim,
const external_source& srcs,
function_ref<void(model_id, float&, float&)> get_pos) noexcept
{
write_constant_sources(srcs.constant_sources);
......
This diff is collapsed.
......@@ -102,17 +102,17 @@ make_neuron(irt::simulation* sim) noexcept
using namespace boost::ut;
irt::real tau_lif =
irt::one + static_cast<irt::real>(rand()) /
(static_cast<irt::real>(RAND_MAX / (irt::two - irt::one)));
(static_cast<irt::real>(RAND_MAX) / (irt::two - irt::one));
irt::real Vr_lif = irt::zero;
irt::real Vt_lif = irt::one;
auto& sum_lif = sim->alloc<irt::adder_2>();
auto& prod_lif = sim->alloc<irt::adder_2>();
auto& integrator_lif = sim->alloc<irt::integrator>();
auto& quantifier_lif = sim->alloc<irt::quantifier>();
auto& constant_lif = sim->alloc<irt::constant>();
auto& sum_lif = sim->alloc<irt::adder_2>();
auto& prod_lif = sim->alloc<irt::adder_2>();
auto& integrator_lif = sim->alloc<irt::integrator>();
auto& quantifier_lif = sim->alloc<irt::quantifier>();
auto& constant_lif = sim->alloc<irt::constant>();
auto& constant_cross_lif = sim->alloc<irt::constant>();
auto& cross_lif = sim->alloc<irt::cross>();
auto& cross_lif = sim->alloc<irt::cross>();
sum_lif.default_input_coeffs[0] = -irt::one;
sum_lif.default_input_coeffs[1] = irt::two * Vt_lif;
......@@ -120,15 +120,15 @@ make_neuron(irt::simulation* sim) noexcept
prod_lif.default_input_coeffs[0] = irt::one / tau_lif;
prod_lif.default_input_coeffs[1] = irt::zero;
constant_lif.default_value = irt::one;
constant_lif.default_value = irt::one;
constant_cross_lif.default_value = Vr_lif;
integrator_lif.default_current_value = irt::zero;
quantifier_lif.default_adapt_state = irt::quantifier::adapt_state::possible;
quantifier_lif.default_zero_init_offset = true;
quantifier_lif.default_step_size = irt::real(0.1);
quantifier_lif.default_past_length = 3;
quantifier_lif.default_step_size = irt::real(0.1);
quantifier_lif.default_past_length = 3;
cross_lif.default_threshold = Vt_lif;
......@@ -170,55 +170,55 @@ make_synapse(irt::simulation* sim,
long unsigned int /*source*/,
long unsigned int /*target*/,
irt::model& presynaptic_model,
int presynaptic_port,
int presynaptic_port,
irt::model& postsynaptic_model,
int postsynaptic_port)
int postsynaptic_port)
{
using namespace boost::ut;
irt::real taupre(20);
irt::real taupost = taupre;
irt::real gamax = irt::to_real(0.015);
irt::real dApre = irt::to_real(0.01);
irt::real dApost = -dApre * taupre / taupost * irt::to_real(1.05);
dApost = dApost * gamax;
dApre = dApre * gamax;
irt::real gamax = irt::to_real(0.015);
irt::real dApre = irt::to_real(0.01);
irt::real dApost = -dApre * taupre / taupost * irt::to_real(1.05);
dApost = dApost * gamax;
dApre = dApre * gamax;
auto& int_pre = sim->alloc<irt::integrator>();
auto& int_pre = sim->alloc<irt::integrator>();
auto& quant_pre = sim->alloc<irt::quantifier>();
auto& sum_pre = sim->alloc<irt::adder_2>();
auto& mult_pre = sim->alloc<irt::adder_2>();
auto& sum_pre = sim->alloc<irt::adder_2>();
auto& mult_pre = sim->alloc<irt::adder_2>();
auto& cross_pre = sim->alloc<irt::cross>();
auto& int_post = sim->alloc<irt::integrator>();
auto& int_post = sim->alloc<irt::integrator>();
auto& quant_post = sim->alloc<irt::quantifier>();
auto& sum_post = sim->alloc<irt::adder_2>();
auto& mult_post = sim->alloc<irt::adder_2>();
auto& sum_post = sim->alloc<irt::adder_2>();
auto& mult_post = sim->alloc<irt::adder_2>();
auto& cross_post = sim->alloc<irt::cross>();
auto& const_syn = sim->alloc<irt::constant>();
auto& const_syn = sim->alloc<irt::constant>();
auto& accumulator_syn = sim->alloc<irt::accumulator_2>();
cross_pre.default_threshold = irt::one;
int_pre.default_current_value = irt::zero;
quant_pre.default_adapt_state = irt::quantifier::adapt_state::possible;
cross_pre.default_threshold = irt::one;
int_pre.default_current_value = irt::zero;
quant_pre.default_adapt_state = irt::quantifier::adapt_state::possible;
quant_pre.default_zero_init_offset = true;
quant_pre.default_step_size = irt::to_real(1e-6);
quant_pre.default_past_length = 3;
sum_pre.default_input_coeffs[0] = irt::one;
sum_pre.default_input_coeffs[1] = dApre;
mult_pre.default_input_coeffs[0] = -irt::one / taupre;
mult_pre.default_input_coeffs[1] = irt::zero;
cross_post.default_threshold = irt::one;
quant_pre.default_step_size = irt::to_real(1e-6);
quant_pre.default_past_length = 3;
sum_pre.default_input_coeffs[0] = irt::one;
sum_pre.default_input_coeffs[1] = dApre;
mult_pre.default_input_coeffs[0] = -irt::one / taupre;
mult_pre.default_input_coeffs[1] = irt::zero;
cross_post.default_threshold = irt::one;
int_post.default_current_value = irt::zero;
quant_post.default_adapt_state = irt::quantifier::adapt_state::possible;
quant_post.default_zero_init_offset = true;
quant_post.default_step_size = irt::to_real(1e-6);
quant_post.default_past_length = 3;
sum_post.default_input_coeffs[0] = irt::one;
sum_post.default_input_coeffs[1] = dApost;
mult_post.default_input_coeffs[0] = -irt::one / taupost;
mult_post.default_input_coeffs[1] = irt::zero;
quant_post.default_step_size = irt::to_real(1e-6);
quant_post.default_past_length = 3;
sum_post.default_input_coeffs[0] = irt::one;
sum_post.default_input_coeffs[1] = dApost;
mult_post.default_input_coeffs[0] = -irt::one / taupost;
mult_post.default_input_coeffs[1] = irt::zero;
const_syn.default_value = irt::one;
......@@ -289,7 +289,7 @@ main()
"song_1_simulation"_test = [] {
irt::simulation sim;
// Neuron constants