Skip to content

Commit

Permalink
Apply linting and compiler diagnostics suggestions
Browse files Browse the repository at this point in the history
Simplify dependencies in CMake targets of the waLBerla bridge.
Fix several instances of -Wunused-parameter and -Wsign-compare.
Update pylint rules and address them in Python scripts.
Bump version requirements in GitHub Actions.
  • Loading branch information
jngrad committed May 2, 2024
1 parent 92859c2 commit c123d8e
Show file tree
Hide file tree
Showing 85 changed files with 261 additions and 309 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Install pandoc
uses: r-lib/actions/setup-pandoc@v2
- name: Setup SSH agent
uses: webfactory/ssh-agent@v0.7.0
uses: webfactory/ssh-agent@v0.9.0
with:
ssh-private-key: ${{ secrets.GH_PAGES_SSH_PRIVATE_KEY }}
- name: Checkout
Expand Down
18 changes: 5 additions & 13 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ analyse-fallback-blocks=no
extension-pkg-allow-list=

# Files or directories to be skipped. They should be base names, not paths.
ignore=CVS build
ignore=build

# Files or directories matching the regular expression patterns are skipped.
# The regex matches against base names, not paths. The default value ignores
Expand All @@ -25,7 +25,7 @@ ignore-patterns=
# Use multiple processes to speed up Pylint. Specifying 0 will auto-detect the
# number of processors available to use, and will cap the count on Windows to
# avoid hangs.
jobs=2
jobs=4

# Control the amount of potential inferred values when inferring a single
# object. This can help the performance when dealing with large functions or
Expand All @@ -41,7 +41,7 @@ persistent=yes

# Minimum Python version to use for version dependent checks. Will default to
# the version used to run pylint.
py-version=3.12
py-version=3.10

# When enabled, pylint would attempt to guess common misconfiguration and emit
# user-friendly hints instead of false-positive error messages.
Expand Down Expand Up @@ -229,8 +229,7 @@ min-public-methods=2
[EXCEPTIONS]

# Exceptions that will emit a warning when caught.
overgeneral-exceptions=BaseException,
Exception
overgeneral-exceptions=builtins.BaseException,builtins.Exception


[FORMAT]
Expand All @@ -254,13 +253,6 @@ max-line-length=100
# Maximum number of lines in a module.
max-module-lines=1000

# List of optional constructs for which whitespace checking is disabled. `dict-
# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}.
# `trailing-comma` allows a space between comma and closing bracket: (a, ).
# `empty-line` allows space-only lines.
no-space-check=trailing-comma,
dict-separator

# Allow the body of a class to be on the same line as the declaration if body
# contains single statement.
single-line-class-stmt=no
Expand Down Expand Up @@ -303,7 +295,7 @@ known-third-party=enchant

# The type of string formatting that logging methods do. `old` means using %
# formatting, `new` is for `{}` formatting.
logging-format-style=old
logging-format-style=new

# Logging modules to check that the string format arguments are in logging
# function parameter format.
Expand Down
2 changes: 1 addition & 1 deletion maintainer/check_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import featuredefs

if len(sys.argv) != 2:
print("Usage: %s FILE" % sys.argv[0])
print(f"Usage: {sys.argv[0]} FILE")
exit(2)

fdefs = featuredefs.defs(sys.argv[1])
24 changes: 12 additions & 12 deletions samples/slice_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,30 +60,30 @@
partcls = system.part.add(id=id_list, pos=pos_list, type=type_list)
p0p1 = system.part.by_ids([0, 1])

print("TYPE\n%s" % partcls.type)
print(f"TYPE\n{partcls.type}")
p0p1.type = [3, 3]
print("TYPE_NEW\n%s" % partcls.type)
print(f"TYPE_NEW\n{partcls.type}")

print("POS\n%s" % partcls.pos)
print(f"POS\n%s" % partcls.pos)
system.part.by_ids(range(5)).pos = [[1, 1, 1], [2, 2, 2], [
3, 3, 3], [4, 4, 4], [5, 5, 5]]
print("POS_NEW\n%s" % partcls.pos)
print(f"POS_NEW\n{partcls.pos}")

print("V\n%s" % partcls.v)
print(f"V\n%s" % partcls.v)
p0p1.v = [[1, 2, 3], [2, 3, 4]]
print("V_NEW\n%s" % partcls.v)
print(f"V_NEW\n{partcls.v}")

print("F\n%s" % partcls.f)
print(f"F\n{partcls.f}")
p0p1.f = [[3, 4, 5], [4, 5, 6]]
print("F_NEW\n%s" % partcls.f)
print(f"F_NEW\n{partcls.f}")

if espressomd.has_features(["MASS"]):
print("MASS\n%s" % partcls.mass)
print(f"MASS\n{partcls.mass}")
p0p1.mass = [2, 3]
print("MASS_NEW\n%s" % partcls.mass)
print(f"MASS_NEW\n{partcls.mass}")

if espressomd.has_features(["ELECTROSTATICS"]):
print("Q\n%s" % partcls.q)
print(f"Q\n{partcls.q}")
system.part.by_ids(range(0, n_part, 2)).q = np.ones(n_part // 2)
system.part.by_ids(range(1, n_part, 2)).q = -np.ones(n_part // 2)
print("Q_NEW\n%s" % partcls.q)
print(f"Q_NEW\n{partcls.q}")
4 changes: 2 additions & 2 deletions samples/visualization_ljliquid.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
f"Simulate {n_part} particles in a cubic box {box_l} at density {density}.")
print("Interactions:\n")
act_min_dist = system.analysis.min_dist()
print(f"Start with minimal distance {act_min_dist}")
print(f"Start with minimal distance {act_min_dist:.3f}")

visualizer = espressomd.visualization.openGLLive(system)

Expand Down Expand Up @@ -127,7 +127,7 @@
#############################################################
# Integration #
#############################################################
print("\nStart integration: run %d times %d steps" % (int_n_times, int_steps))
print(f"\nStart integration: run {int_n_times} times {int_steps} steps")

# print initial energies
energies = system.analysis.energy()
Expand Down
2 changes: 1 addition & 1 deletion src/core/bond_breakage/bond_breakage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct QueueEntry {
// Serialization for synchronization across mpi ranks
friend class boost::serialization::access;
template <typename Archive>
void serialize(Archive &ar, const unsigned int version) {
void serialize(Archive &ar, unsigned int const /* version */) {
ar & particle_id;
ar & bond_partners;
ar & bond_type;
Expand Down
4 changes: 4 additions & 0 deletions src/core/cell_system/AtomDecomposition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ void AtomDecomposition::configure_neighbors() {

local().m_neighbors = Neighbors<Cell *>(red_neighbors, black_neighbors);
}

GhostCommunicator AtomDecomposition::prepare_comm() {
/* no need for comm for only 1 node */
if (m_comm.size() == 1) {
Expand All @@ -68,6 +69,7 @@ GhostCommunicator AtomDecomposition::prepare_comm() {

return ghost_comm;
}

void AtomDecomposition::configure_comms() {
m_exchange_ghosts_comm = prepare_comm();
m_collect_ghost_force_comm = prepare_comm();
Expand All @@ -90,6 +92,7 @@ void AtomDecomposition::configure_comms() {
}
}
}

void AtomDecomposition::mark_cells() {
m_local_cells.resize(1, std::addressof(local()));
m_ghost_cells.clear();
Expand All @@ -99,6 +102,7 @@ void AtomDecomposition::mark_cells() {
}
}
}

void AtomDecomposition::resort(bool global_flag,
std::vector<ParticleChange> &diff) {
for (auto &p : local().particles()) {
Expand Down
3 changes: 2 additions & 1 deletion src/core/cell_system/CellStructure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

#include <algorithm>
#include <cassert>
#include <cstddef>
#include <iterator>
#include <memory>
#include <set>
Expand Down Expand Up @@ -69,7 +70,7 @@ void CellStructure::check_particle_index() const {
}

/* checks: local particle id */
int local_part_cnt = 0;
std::size_t local_part_cnt = 0u;
for (int n = 0; n < get_max_local_particle_id() + 1; n++) {
if (get_local_particle(n) != nullptr) {
local_part_cnt++;
Expand Down
1 change: 1 addition & 0 deletions src/core/cell_system/HybridDecomposition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class HybridDecomposition : public ParticleDecomposition {
Utils::Vector3d max_cutoff() const override {
return m_n_square.max_cutoff();
}

Utils::Vector3d max_range() const override { return m_n_square.max_range(); }

boost::optional<BoxGeometry> minimum_image_distance() const override {
Expand Down
14 changes: 7 additions & 7 deletions src/core/cell_system/RegularDecomposition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int RegularDecomposition::position_to_cell_index(
Utils::Vector3d const &pos) const {
Utils::Vector3i cpos;

for (unsigned int i = 0u; i < 3u; i++) {
for (auto i = 0u; i < 3u; i++) {
cpos[i] = static_cast<int>(std::floor(pos[i] * inv_cell_size[i])) + 1 -
cell_offset[i];

Expand Down Expand Up @@ -306,7 +306,7 @@ void RegularDecomposition::create_cell_grid(double range) {
auto const volume = Utils::product(local_box_l);
auto const scale = std::cbrt(RegularDecomposition::max_num_cells / volume);

for (unsigned int i = 0; i < 3; i++) {
for (auto i = 0u; i < 3u; i++) {
/* this is at least 1 */
cell_grid[i] = static_cast<int>(std::ceil(local_box_l[i] * scale));
cell_range[i] = local_box_l[i] / static_cast<double>(cell_grid[i]);
Expand Down Expand Up @@ -336,11 +336,11 @@ void RegularDecomposition::create_cell_grid(double range) {
break;

/* find coordinate with the smallest cell range */
int min_ind = 0;
double min_size = cell_range[0];
auto min_ind = 0u;
auto min_size = cell_range[0];

for (int i = 1; i < 3; i++) {
if (cell_grid[i] > 1 && cell_range[i] < min_size) {
for (auto i = 1u; i < 3u; ++i) {
if (cell_grid[i] > 1 and cell_range[i] < min_size) {
min_ind = i;
min_size = cell_range[i];
}
Expand Down Expand Up @@ -369,7 +369,7 @@ void RegularDecomposition::create_cell_grid(double range) {

/* now set all dependent variables */
int new_cells = 1;
for (unsigned int i = 0; i < 3; i++) {
for (auto i = 0u; i < 3u; i++) {
ghost_cell_grid[i] = cell_grid[i] + 2;
new_cells *= ghost_cell_grid[i];
cell_size[i] = m_local_box.length()[i] / static_cast<double>(cell_grid[i]);
Expand Down
2 changes: 1 addition & 1 deletion src/core/cells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ static void search_distance_sanity_check_max_range(System::System const &system,
}
static void
search_distance_sanity_check_cell_structure(System::System const &system,
double const distance) {
double const) {
auto const &cell_structure = *system.cell_structure;
if (cell_structure.decomposition_type() == CellStructureType::HYBRID) {
throw std::runtime_error("Cannot search for neighbors in the hybrid "
Expand Down
11 changes: 5 additions & 6 deletions src/core/constraints/ShapeBasedConstraint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ ParticleForce ShapeBasedConstraint::force(Particle const &p,

if (dist > 0) {
outer_normal_vec = -dist_vec / dist;
pf = calc_central_radial_force(p, part_rep, ia_params, dist_vec, dist) +
pf = calc_central_radial_force(ia_params, dist_vec, dist) +
calc_central_radial_charge_force(p, part_rep, ia_params, dist_vec,
dist, get_ptr(coulomb_kernel)) +
calc_non_central_force(p, part_rep, ia_params, dist_vec, dist);
Expand All @@ -111,11 +111,10 @@ ParticleForce ShapeBasedConstraint::force(Particle const &p,
#endif
} else if (m_penetrable && (dist <= 0)) {
if ((!m_only_positive) && (dist < 0)) {
pf =
calc_central_radial_force(p, part_rep, ia_params, dist_vec, -dist) +
calc_central_radial_charge_force(p, part_rep, ia_params, dist_vec,
-dist, get_ptr(coulomb_kernel)) +
calc_non_central_force(p, part_rep, ia_params, dist_vec, -dist);
pf = calc_central_radial_force(ia_params, dist_vec, -dist) +
calc_central_radial_charge_force(p, part_rep, ia_params, dist_vec,
-dist, get_ptr(coulomb_kernel)) +
calc_non_central_force(p, part_rep, ia_params, dist_vec, -dist);

#ifdef DPD
if (m_system.thermostat->thermo_switch & THERMO_DPD) {
Expand Down
8 changes: 4 additions & 4 deletions src/core/electrostatics/coulomb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ struct LongRangePressure {
}
#endif // P3M

auto operator()(std::shared_ptr<DebyeHueckel> const &actor) const {
auto operator()(std::shared_ptr<DebyeHueckel> const &) const {
return Utils::Vector9d{};
}

auto operator()(std::shared_ptr<ReactionField> const &actor) const {
auto operator()(std::shared_ptr<ReactionField> const &) const {
return Utils::Vector9d{};
}

Expand Down Expand Up @@ -156,11 +156,11 @@ struct ShortRangeCutoff {
}
#endif // P3M
#ifdef MMM1D_GPU
auto operator()(std::shared_ptr<CoulombMMM1DGpu> const &actor) const {
auto operator()(std::shared_ptr<CoulombMMM1DGpu> const &) const {
return std::numeric_limits<double>::infinity();
}
#endif // MMM1D_GPU
auto operator()(std::shared_ptr<CoulombMMM1D> const &actor) const {
auto operator()(std::shared_ptr<CoulombMMM1D> const &) const {
return std::numeric_limits<double>::infinity();
}
#ifdef SCAFACOS
Expand Down
2 changes: 1 addition & 1 deletion src/core/electrostatics/elc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ struct elc_data {

/// pairwise contributions from the lowest and top layers
template <typename Kernel>
void dielectric_layers_contribution(CoulombP3M const &p3m,
void dielectric_layers_contribution(CoulombP3M const &,
BoxGeometry const &box_geo,
Utils::Vector3d const &pos1,
Utils::Vector3d const &pos2, double q1q2,
Expand Down
15 changes: 7 additions & 8 deletions src/core/electrostatics/icc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@

#include <algorithm>
#include <cmath>
#include <cstddef>
#include <limits>
#include <stdexcept>
#include <variant>
Expand Down Expand Up @@ -223,13 +224,13 @@ void icc_data::sanity_checks() const {
throw std::domain_error("Parameter 'first_id' must be >= 0");
if (eps_out <= 0.)
throw std::domain_error("Parameter 'eps_out' must be > 0");
if (areas.size() != n_icc)
if (areas.size() != static_cast<std::size_t>(n_icc))
throw std::invalid_argument("Parameter 'areas' has incorrect shape");
if (epsilons.size() != n_icc)
if (epsilons.size() != static_cast<std::size_t>(n_icc))
throw std::invalid_argument("Parameter 'epsilons' has incorrect shape");
if (sigmas.size() != n_icc)
if (sigmas.size() != static_cast<std::size_t>(n_icc))
throw std::invalid_argument("Parameter 'sigmas' has incorrect shape");
if (normals.size() != n_icc)
if (normals.size() != static_cast<std::size_t>(n_icc))
throw std::invalid_argument("Parameter 'normals' has incorrect shape");
}

Expand All @@ -245,12 +246,10 @@ void ICCStar::on_activation() const {
}

struct SanityChecksICC {
template <typename T>
void operator()(std::shared_ptr<T> const &actor) const {}
template <typename T> void operator()(std::shared_ptr<T> const &) const {}
#ifdef P3M
#ifdef CUDA
[[noreturn]] void
operator()(std::shared_ptr<CoulombP3MGPU> const &actor) const {
[[noreturn]] void operator()(std::shared_ptr<CoulombP3MGPU> const &) const {
throw std::runtime_error("ICC does not work with P3MGPU");
}
#endif // CUDA
Expand Down
2 changes: 1 addition & 1 deletion src/core/forces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ void System::System::calculate_forces() {

if (thermostat->lb and (propagation->used_propagations &
PropagationMode::TRANS_LB_MOMENTUM_EXCHANGE)) {
lb_couple_particles(time_step);
lb_couple_particles();
}

#ifdef CUDA
Expand Down
8 changes: 3 additions & 5 deletions src/core/forces_inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,12 @@
#include <optional>
#include <tuple>

inline ParticleForce calc_central_radial_force(Particle const &p1,
Particle const &p2,
IA_parameters const &ia_params,
inline ParticleForce calc_central_radial_force(IA_parameters const &ia_params,
Utils::Vector3d const &d,
double const dist) {

ParticleForce pf{};
double force_factor = 0;
auto force_factor = 0.;
/* Lennard-Jones */
#ifdef LENNARD_JONES
force_factor += lj_pair_force_factor(ia_params, dist);
Expand Down Expand Up @@ -219,7 +217,7 @@ inline void add_non_bonded_pair_force(
#ifdef EXCLUSIONS
if (do_nonbonded(p1, p2)) {
#endif
pf += calc_central_radial_force(p1, p2, ia_params, d, dist);
pf += calc_central_radial_force(ia_params, d, dist);
pf += calc_central_radial_charge_force(p1, p2, ia_params, d, dist,
coulomb_kernel);
pf += calc_non_central_force(p1, p2, ia_params, d, dist);
Expand Down
Loading

0 comments on commit c123d8e

Please sign in to comment.