Skip to content

Commit

Permalink
Modcc is now fmt only.
Browse files Browse the repository at this point in the history
  • Loading branch information
thorstenhater committed Aug 9, 2023
1 parent c525fc6 commit 09e6d1e
Show file tree
Hide file tree
Showing 38 changed files with 461 additions and 656 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ add_subdirectory(ext)
install(TARGETS ext-hwloc EXPORT arbor-targets)
install(TARGETS ext-random123 EXPORT arbor-targets)

target_link_libraries(arbor-private-deps INTERFACE ext-fmt)

# Keep track of packages we need to add to the generated CMake config
# file for arbor.

Expand Down
18 changes: 1 addition & 17 deletions arbor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,23 +135,7 @@ add_library(arbor ${arbor_sources} ${arbor-builtin-mechanisms})
target_link_libraries(arbor PRIVATE arbor-private-deps arbor-private-headers)
target_link_libraries(arbor PUBLIC arbor-public-deps arbor-public-headers)

if (ARB_USE_BUNDLED_FMT)
target_include_directories(arbor
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../ext/fmt/include>)

target_compile_definitions(arbor PRIVATE FMT_HEADER_ONLY)
else()
target_include_directories(arbor
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>)
find_package(fmt REQUIRED)
target_link_libraries(arbor PRIVATE fmt::fmt-header-only)
endif()
target_link_libraries(arbor INTERFACE ext-fmt)

if(ARB_WITH_CUDA_CLANG)
target_link_libraries(arbor PRIVATE ${CUDA_LIBRARIES})
Expand Down
36 changes: 36 additions & 0 deletions arbor/cable_cell_param.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
#include <arbor/s_expr.hpp>

#include "util/maputil.hpp"
#include "util/strprintf.hpp"
#include <fmt/format.h>
#include <fmt/ranges.h>
#include <fmt/std.h>

namespace arb {

Expand Down Expand Up @@ -171,4 +175,36 @@ decor& decor::set_default(defaultable what) {
return *this;
}

std::ostream& operator<<(std::ostream& os, const cable_cell_global_properties& props) {
const auto& D = props.default_parameters;
const auto& I = D.ion_data;
os << "{arbor.cable_global_properties\n"
" ions: {";
for (auto& [name, data]: props.ion_species) {
std::string xi = "None";
std::string xo = "None";
std::string ex = "None";
std::string mt = "'None'";
if (I.count(name)) {
const auto& props = I.at(name);
if (props.init_int_concentration) xi = util::to_string(*props.init_int_concentration);
if (props.init_ext_concentration) xo = util::to_string(*props.init_ext_concentration);
if (props.init_reversal_potential) ex = util::to_string(*props.init_reversal_potential);
if (D.reversal_potential_method.count(name)) mt ="'" + D.reversal_potential_method.at(name).name() + "'";
}
os << fmt::format("\n {{name: '{}', valence: {}, int_con: {}, ext_con: {}, rev_pot: {}, rev_pot_method: {}}}",
name,
data,
xi, xo, ex, mt);
}
os << "}\n"
<< fmt::format(" parameters: {Vm: {}, cm: {}, rL: {}, tempK: {}}\n",
D.init_membrane_potential ? util::to_string(*D.init_membrane_potential) : "None",
D.membrane_capacitance ? util::to_string(*D.membrane_capacitance) : "None",
D.axial_resistivity ? util::to_string(*D.axial_resistivity) : "None",
D.temperature_K ? util::to_string(*D.temperature_K) : "None")
<< "}";
return os;
}

} // namespace arb
3 changes: 3 additions & 0 deletions arbor/include/arbor/cable_cell_param.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <string>
#include <variant>
#include <any>
#include <ostream>

#include <arbor/export.hpp>
#include <arbor/arbexcept.hpp>
Expand Down Expand Up @@ -364,6 +365,8 @@ struct ARB_SYMBOL_VISIBLE cable_cell_global_properties {
add_ion(ion_name, charge, init_iconc, init_econc, 0, diffusivity);
default_parameters.reversal_potential_method[ion_name] = std::move(revpot_mechanism);
}

friend std::ostream& operator<<(std::ostream&, const cable_cell_global_properties&);
};

// Throw cable_cell_error if any default parameters are left unspecified,
Expand Down
15 changes: 15 additions & 0 deletions ext/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@ endif()
add_library(ext-tinyopt INTERFACE)
target_include_directories(ext-tinyopt INTERFACE tinyopt/include)

add_library(ext-fmt INTERFACE)
if (ARB_USE_BUNDLED_FMT)
target_include_directories(ext-fmt
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/fmt/include>)
target_compile_definitions(ext-fmt INTERFACE FMT_HEADER_ONLY)
install(TARGETS ext-fmt EXPORT arbor-targets)
else()
target_include_directories(ext-fmt
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>)
find_package(fmt REQUIRED)
target_link_libraries(ext-fmt INTERFACE fmt::fmt-header-only)
endif()

# functionality for adding external projects

Expand Down
2 changes: 2 additions & 0 deletions modcc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ else()
target_link_libraries(libmodcc PRIVATE fmt::fmt-header-only)
endif()

target_link_libraries(libmodcc INTERFACE ext-fmt)

set_target_properties(libmodcc PROPERTIES OUTPUT_NAME modcc)

export_visibility(libmodcc)
Expand Down
78 changes: 30 additions & 48 deletions modcc/blocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,93 +2,75 @@
#include <vector>

#include "blocks.hpp"
#include "io/pprintf.hpp"
#include "io/ostream_wrappers.hpp"

// Pretty-printers for block info.
#include "io/pprintf.hpp"

// Pretty-printers for block info.
using namespace io;

template <typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
separator s("[", " ");
for (auto& x: v) os << s << x;
for (const auto& x: v) os << s << x;
os << ']';

return os;
}

ARB_LIBMODCC_API std::ostream& operator<<(std::ostream& os, Id const& V) {
if(V.units.size())
os << "(" << V.token << "," << V.value << "," << V.units << ")";
else
os << "(" << V.token << "," << V.value << ",)";

os << '(' << V.token << ',' << V.value << ',';
if(V.units.size()) os << V.units << ',';
os << ')';
return os;
}

ARB_LIBMODCC_API std::ostream& operator<<(std::ostream& os, UnitsBlock::units_pair const& p) {
return os << "(" << p.first << ", " << p.second << ")";
return os << '(' << p.first << ", " << p.second << ')';
}

ARB_LIBMODCC_API std::ostream& operator<<(std::ostream& os, IonDep const& I) {
return os << "(" << I.name << ": read " << I.read << " write " << I.write << ")";
return os << '(' << I.name << " read=" << I.read << "write=" << I.write << ')';
}

ARB_LIBMODCC_API std::ostream& operator<<(std::ostream& os, moduleKind const& k) {
switch (k) {
case moduleKind::density: os << "density"; break;
case moduleKind::voltage: os << "voltage"; break;
case moduleKind::point: os << "point"; break;
case moduleKind::revpot: os << "revpot"; break;
case moduleKind::junction: os << "junction"; break;
default: os << "???"; break;
}
return os;
return os << to_string(k);
}

ARB_LIBMODCC_API std::ostream& operator<<(std::ostream& os, NeuronBlock const& N) {
os << blue("NeuronBlock") << std::endl;
os << " kind : " << N.kind << std::endl;
os << " name : " << N.name << std::endl;
os << " threadsafe : " << (N.threadsafe ? "yes" : "no") << std::endl;
os << " ranges : " << N.ranges << std::endl;
os << " globals : " << N.globals << std::endl;
os << " ions : " << N.ions << std::endl;

return os;
return os << fmt::format(FMT_COMPILE("{}\n"
" kind : {}\n"
" name : {}\n"
" threadsafe : {}\n"),
blue("NeuronBlock"),
to_string(N.kind),
N.name,
N.threadsafe)
<< " ranges : " << N.ranges << '\n'
<< " globals : " << N.globals << '\n'
<< " ions : " << N.ions << '\n';
}

ARB_LIBMODCC_API std::ostream& operator<<(std::ostream& os, StateBlock const& B) {
os << blue("StateBlock") << std::endl;
return os << " variables : " << B.state_variables << std::endl;

return os << blue("StateBlock") << std::endl
<< " variables : " << B.state_variables << std::endl;
}

ARB_LIBMODCC_API std::ostream& operator<<(std::ostream& os, UnitsBlock const& U) {
os << blue("UnitsBlock") << std::endl;
os << " aliases : " << U.unit_aliases << std::endl;

return os;
return os << blue("UnitsBlock") << std::endl
<< " aliases : " << U.unit_aliases << std::endl;
}

ARB_LIBMODCC_API std::ostream& operator<<(std::ostream& os, ParameterBlock const& P) {
os << blue("ParameterBlock") << std::endl;
os << " parameters : " << P.parameters << std::endl;

return os;
return os << blue("ParameterBlock") << std::endl
<< " parameters : " << P.parameters << std::endl;
}

ARB_LIBMODCC_API std::ostream& operator<<(std::ostream& os, AssignedBlock const& A) {
os << blue("AssignedBlock") << std::endl;
os << " parameters : " << A.parameters << std::endl;

return os;
return os << blue("AssignedBlock") << std::endl
<< " parameters : " << A.parameters << std::endl;
}

ARB_LIBMODCC_API std::ostream& operator<<(std::ostream& os, WhiteNoiseBlock const& W) {
os << blue("WhiteNoiseBlock") << std::endl;
os << " parameters : " << W.parameters << std::endl;

return os;
return os << blue("WhiteNoiseBlock") << std::endl
<< " parameters : " << W.parameters << std::endl;
}
37 changes: 21 additions & 16 deletions modcc/errorvisitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#include "visitor.hpp"
#include "expression.hpp"
#include <libmodcc/export.hpp>
#include "io/pprintf.hpp"

class ARB_LIBMODCC_API ErrorVisitor : public Visitor {
public:
struct ARB_LIBMODCC_API ErrorVisitor : public Visitor {
ErrorVisitor(std::string const& m)
: module_name_(m)
{}
Expand All @@ -29,26 +29,31 @@ class ARB_LIBMODCC_API ErrorVisitor : public Visitor {
void visit(InitialBlock *e) override;
void visit(IfExpression *e) override;

int num_errors() {return num_errors_;}
int num_warnings() {return num_warnings_;}
int num_errors() { return num_errors_; }
int num_warnings() { return num_warnings_; }

private:
template <typename ExpressionType>
void print_error(ExpressionType *e) {
if(e->has_error()) {
auto header = red("error: ")
+ white(pprintf("% % ", module_name_, e->location()));
std::cout << header << "\n "
<< e->error_message()
<< std::endl;
num_errors_++;
std::cout << fmt::format(FMT_COMPILE("{}: {} ({}:{})\n"
"{}\n"),
red("error"),
white(module_name_),
e->location().line,
e->location().column,
e->error_message());
++num_errors_;
}
if(e->has_warning()) {
auto header = purple("warning: ")
+ white(pprintf("% % ", module_name_, e->location()));
std::cout << header << "\n "
<< e->warning_message()
<< std::endl;
num_warnings_++;
std::cout << fmt::format(FMT_COMPILE("{}: {} ({}:{})\n"
"{}\n"),
purple("warning"),
white(module_name_),
e->location().line,
e->location().column,
e->warning_message());
++num_warnings_;
}
}

Expand Down
Loading

0 comments on commit 09e6d1e

Please sign in to comment.