Skip to content

Commit

Permalink
Bump formatters and linters requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
jngrad committed Apr 17, 2024
1 parent e473c37 commit 6442bc8
Show file tree
Hide file tree
Showing 87 changed files with 375 additions and 355 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ repos:
always_run: false
files: '.*\.(py|pyx|pxd)'
exclude: '\.pylintrc|.*.\.py\.in|^libs/'
args: ["--ignore=E266,E402,E701,W291,W293", "--in-place", "--aggressive"]
args: ["--ignore=E266,E402,E701,W291,W293", "--in-place"]

- id: cmake-format
name: cmake-format
Expand Down
4 changes: 2 additions & 2 deletions maintainer/benchmarks/benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def get_timings(system, n_steps, n_iterations, verbose=True):
energy = system.analysis.energy()["total"]
verlet = system.cell_system.get_state()["verlet_reuse"]
print(
f"step {i}, time: {1000*t:.1f} ms, verlet: {verlet:.2f}, energy: {energy:.2e}")
f"step {i}, time: {1000 * t:.1f} ms, verlet: {verlet:.2f}, energy: {energy:.2e}")
return np.array(timings)


Expand Down Expand Up @@ -131,7 +131,7 @@ def write_report(filepath, n_proc, timings, n_steps, label=''):
cmd = " ".join(x for x in sys.argv[1:] if not x.startswith("--output"))
avg, ci = get_average_time(timings)
header = '"script","arguments","cores","mean","ci","nsteps","duration","label"\n'
report = f'"{script}","{cmd}",{n_proc},{avg:.3e},{ci:.3e},{n_steps},{np.sum(timings):.1f},"{label}"\n'
report = f'"{script}","{cmd}",{n_proc},{avg:.3e},{ci:.3e},{n_steps},{np.sum(timings):.1f},"{label}"\n' # nopep8
if pathlib.Path(filepath).is_file():
header = ''
with open(filepath, "a") as f:
Expand Down
8 changes: 5 additions & 3 deletions maintainer/benchmarks/mc_acid_base_reservoir.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def calc_donnan_coefficient(c_acid, I_res, charge=-1):
NUM_SAMPLES = 100
INTEGRATION_STEPS_PER_SAMPLE = 100
assert TOTAL_NUM_MC_STEPS % NUM_SAMPLES == 0, \
f"Total number of MC steps must be divisible by total number of samples, got {TOTAL_NUM_MC_STEPS} and {NUM_SAMPLES}"
f"Total number of MC steps must be divisible by total number of samples, got {TOTAL_NUM_MC_STEPS} and {NUM_SAMPLES}" # nopep8
MC_STEPS_PER_SAMPLE = TOTAL_NUM_MC_STEPS // NUM_SAMPLES

# definitions of reduced units
Expand Down Expand Up @@ -266,7 +266,8 @@ def report_progress(system, i, next_i):
n_All = len(system.part)
if i == next_i:
print(
f"run {i:d} time {system.time:.3g} completed {i / NUM_SAMPLES * 100:.0f}%",
f"run {i:d} time {system.time:.3g} completed "
f"{i / NUM_SAMPLES * 100:.0f}%",
f"instantaneous values: All {n_All:d} Na {n_Na:d} Cl {n_Cl:d}",
f"A {n_A:d} alpha {n_A / N_ACID:.3f}")
if i == 0:
Expand Down Expand Up @@ -308,7 +309,8 @@ def report_progress(system, i, next_i):
energy = system.analysis.energy()["total"]
verlet = system.cell_system.get_state()["verlet_reuse"]
print(
f"step {i}, time MD: {t_MD:.2e}, time MC: {t_MC:.2e}, verlet: {verlet:.2f}, energy: {energy:.2e}")
f"step {i}, time MD: {t_MD:.2e}, time MC: {t_MC:.2e}, "
f"verlet: {verlet:.2f}, energy: {energy:.2e}")

# average time
avg_MC, ci_MC = benchmarks.get_average_time(timings_MC)
Expand Down
6 changes: 4 additions & 2 deletions maintainer/format/autopep8.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
#
# Copyright (C) 2018-2022 The ESPResSo project
#
# This file is part of ESPResSo.
Expand All @@ -15,10 +16,11 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#


AUTOPEP8_VER=1.6.0
PYCODESTYLE_VER=2.8.0
AUTOPEP8_VER=2.1.0
PYCODESTYLE_VER=2.11.1

python3 -m autopep8 --help 2>&1 > /dev/null
if [ "$?" = "0" ]; then
Expand Down
4 changes: 3 additions & 1 deletion maintainer/format/clang-format.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
#
# Copyright (C) 2018-2022 The ESPResSo project
#
# This file is part of ESPResSo.
Expand All @@ -15,8 +16,9 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

CLANG_FORMAT_VER=14.0
CLANG_FORMAT_VER=18.1
if hash clang-format-${CLANG_FORMAT_VER} 2>/dev/null; then
CLANGFORMAT="$(which clang-format-${CLANG_FORMAT_VER})"
elif hash clang-format-${CLANG_FORMAT_VER%.*} 2>/dev/null; then
Expand Down
2 changes: 2 additions & 0 deletions maintainer/format/cmake-format.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
#
# Copyright (C) 2018-2022 The ESPResSo project
#
# This file is part of ESPResSo.
Expand All @@ -15,6 +16,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

CMAKE_FORMAT_VER=0.6.13
python3 -m cmakelang.format 2>&1 > /dev/null
Expand Down
3 changes: 2 additions & 1 deletion maintainer/format/ex_flag.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
#
# Copyright (C) 2018-2022 The ESPResSo project
#
# This file is part of ESPResSo.
Expand All @@ -15,6 +16,6 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

#

chmod -x "$@"
5 changes: 3 additions & 2 deletions maintainer/lint/pre_commit.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
#
# Copyright (C) 2018-2022 The ESPResSo project
#
# This file is part of ESPResSo.
Expand All @@ -15,9 +16,9 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#


python3 -m pre_commit 2>&1 >/dev/null
pre-commit 2>&1 >/dev/null
if [ "$?" = "0" ]; then
precommit="python3 -m pre_commit"
else
Expand Down
4 changes: 3 additions & 1 deletion maintainer/lint/pylint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/sh
# Copyright (C) 2018-2022 The ESPResSo project
#
# Copyright (C) 2018-2024 The ESPResSo project
#
# This file is part of ESPResSo.
#
Expand All @@ -15,6 +16,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#


python3 -m pylint --help 2>&1 > /dev/null
Expand Down
19 changes: 10 additions & 9 deletions maintainer/walberla_kernels/code_generation_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def new_generate_members(*args, **kwargs):
if token in output:
i = output.index(token)
vartype = output[:i].split("\n")[-1].strip()
output += f"\nstd::function<void(IBlock *, {vartype}&, {vartype}&, {vartype}&)> block_offset_generator = [](IBlock * const, {vartype}&, {vartype}&, {vartype}&) {{ }};"
output += f"\nstd::function<void(IBlock *, {vartype}&, {vartype}&, {vartype}&)> block_offset_generator = [](IBlock * const, {vartype}&, {vartype}&, {vartype}&) {{ }};" # nopep8
return output

def new_generate_refs_for_kernel_parameters(*args, **kwargs):
Expand Down Expand Up @@ -83,12 +83,13 @@ def earmark_generated_kernels():
walberla_commit = f.read()
token = "// kernel generated with"
earmark = (
f"{token} pystencils v{pystencils.__version__}, lbmpy v{lbmpy.__version__}, "
f"lbmpy_walberla/pystencils_walberla from waLBerla commit {walberla_commit}"
f"{token} pystencils v{pystencils.__version__}, "
f"lbmpy v{lbmpy.__version__}, "
f"lbmpy_walberla/pystencils_walberla from "
f"waLBerla commit {walberla_commit}"
)
for filename in os.listdir("."):
if not filename.endswith(
".tmpl.h") and filename.endswith((".h", ".cpp", ".cu")):
if filename.endswith((".h", ".cpp", ".cu", ".cuh")):
with open(filename, "r+") as f:
content = f.read()
if token not in content:
Expand All @@ -100,7 +101,7 @@ def earmark_generated_kernels():
pos = content.find("//=====", 5)
pos = content.find("\n", pos) + 1
f.seek(pos)
f.write(f"\n{earmark}\n{content[pos:]}")
f.write(f"\n{earmark}\n{content[pos:].rstrip()}\n")


def guard_generated_kernels_clang_format():
Expand All @@ -117,9 +118,9 @@ def guard_generated_kernels_clang_format():
if not all_ns:
continue
for ns in all_ns:
content = re.sub(rf"(?<=[^a-zA-Z0-9_]){ns}(?=[^a-zA-Z0-9_])",
f"internal_{hashlib.md5(ns.encode('utf-8')).hexdigest()}",
content)
ns_hash = hashlib.md5(ns.encode('utf-8')).hexdigest()
content = re.sub(f"(?<=[^a-zA-Z0-9_]){ns}(?=[^a-zA-Z0-9_])",
f"internal_{ns_hash}", content)
with open(filename, "w") as f:
f.write(content)

Expand Down
37 changes: 15 additions & 22 deletions maintainer/walberla_kernels/custom_additional_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,8 @@ def __call__(self, field, direction_symbol, index_field, **kwargs):
conds = [
sp.Equality(
direction_symbol,
ps.typing.CastFunc(
d + 1,
np.int32)) for d in range(
len(accesses))]
ps.typing.CastFunc(d + 1, np.int32))
for d in range(len(accesses))]

# use conditional
conditional = None
Expand Down Expand Up @@ -137,8 +135,7 @@ def __init__(self, stencil, boundary_object):

@property
def constructor_arguments(self):
return f", std::function<{self.data_type}(const Cell &, const shared_ptr<StructuredBlockForest>&, IBlock&)>& " \
"dirichletCallback "
return f", std::function<{self.data_type}(const Cell &, const shared_ptr<StructuredBlockForest>&, IBlock&)>& dirichletCallback "

@property
def initialiser_list(self):
Expand All @@ -153,15 +150,15 @@ def additional_parameters_for_fill_function(self):
return " const shared_ptr<StructuredBlockForest> &blocks, "

def data_initialisation(self, _):
init_list = [f"{self.data_type} InitialisatonAdditionalData = elementInitaliser(Cell(it.x(), it.y(), it.z()), "
"blocks, *block);", "element.value = InitialisatonAdditionalData;"]
init_list = [
f"{self.data_type} InitialisatonAdditionalData = elementInitaliser(Cell(it.x(), it.y(), it.z()), blocks, *block);",
"element.value = InitialisatonAdditionalData;"]

return "\n".join(init_list)

@property
def additional_member_variable(self):
return f"std::function<{self.data_type}(const Cell &, const shared_ptr<StructuredBlockForest>&, IBlock&)> " \
"elementInitaliser; "
return f"std::function<{self.data_type}(const Cell &, const shared_ptr<StructuredBlockForest>&, IBlock&)> elementInitaliser; "


class FluxAdditionalDataHandler(
Expand All @@ -174,8 +171,7 @@ def __init__(self, stencil, boundary_object):

@property
def constructor_arguments(self):
return f", std::function<Vector3<{self.data_type}>(const Cell &, const shared_ptr<StructuredBlockForest>&, IBlock&)>& " \
"fluxCallback "
return f", std::function<Vector3<{self.data_type}>(const Cell &, const shared_ptr<StructuredBlockForest>&, IBlock&)>& fluxCallback "

@property
def initialiser_list(self):
Expand All @@ -193,8 +189,8 @@ def data_initialisation(self, direction):
dirVec = self.stencil_info[direction][1]

init_list = [
f"Vector3<{self.data_type}> InitialisatonAdditionalData = elementInitaliser(Cell(it.x() + {dirVec[0]}, it.y() + {dirVec[1]}, it.z() + {dirVec[2]}), "
"blocks, *block);", "element.flux_0 = InitialisatonAdditionalData[0];",
f"Vector3<{self.data_type}> InitialisatonAdditionalData = elementInitaliser(Cell(it.x() + {dirVec[0]}, it.y() + {dirVec[1]}, it.z() + {dirVec[2]}), blocks, *block);",
"element.flux_0 = InitialisatonAdditionalData[0];",
"element.flux_1 = InitialisatonAdditionalData[1];"]
if self._dim == 3:
init_list.append(
Expand All @@ -204,13 +200,11 @@ def data_initialisation(self, direction):

@property
def additional_member_variable(self):
return f"std::function<Vector3<{self.data_type}>(const Cell &, const shared_ptr<StructuredBlockForest>&, IBlock&)> " \
"elementInitaliser; "
return f"std::function<Vector3<{self.data_type}>(const Cell &, const shared_ptr<StructuredBlockForest>&, IBlock&)> elementInitaliser; "


# this custom boundary generator is necessary because our boundary
# condition writes to several fields at once which is impossible with the
# shipped one
# this custom boundary generator is necessary because our boundary condition
# writes to several fields at once which is impossible with the shipped one
def generate_boundary(
generation_context,
stencil,
Expand Down Expand Up @@ -250,9 +244,8 @@ def generate_boundary(
index_struct_dtype,
layout=[0],
shape=(
ps.typing.TypedSymbol(
"indexVectorSize", ps.typing.BasicType(np.int32)
),
ps.typing.TypedSymbol("indexVectorSize",
ps.typing.BasicType(np.int32)),
1,
),
strides=(1, 1),
Expand Down
2 changes: 1 addition & 1 deletion maintainer/walberla_kernels/walberla_lbm_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def equations_to_code(equations, variable_prefix="",

def substitute_force_getter_cpp(code):
field_getter = "force->"
assert field_getter in code is not None, f"pattern '{field_getter} not found in '''\n{code}\n'''"
assert field_getter in code is not None, f"pattern '{field_getter} not found in '''\n{code}\n'''" # nopep8
return code.replace(field_getter, "force_field->")


Expand Down
11 changes: 6 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ nbformat==5.1.3
nbconvert==6.5.1
tqdm>=4.57.0
# linters and their dependencies
autopep8==1.6.0
pycodestyle==2.8.0
pylint>=2.12.2
astroid>=2.9.3
pep8==1.7.1
autopep8==2.1.0
pycodestyle==2.11.1
pylint>=3.0.3
astroid>=3.0.2
isort>=5.6.4
pre-commit>=2.17.0
pre-commit>=3.6.2
cmakelang==0.6.13
4 changes: 3 additions & 1 deletion samples/reaction_ensemble_complex_reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ def equations(variables):

print("concentrations sampled with the reaction ensemble vs. analytical solutions:")
for ptype in types:
print(f" type {types_name[ptype]}: {concentrations[ptype]:.4f} +/- {concentrations_95ci[ptype]:.4f} mol/l (95% CI), expected: {concentrations_numerical[ptype]:.4f} mol/l")
print(f" type {types_name[ptype]}: {concentrations[ptype]:.4f} "
f"+/- {concentrations_95ci[ptype]:.4f} mol/l (95% CI), "
f"expected: {concentrations_numerical[ptype]:.4f} mol/l")

K_sim = ((concentrations[type_C] / c_ref_in_mol_per_l)**nu_C
* (concentrations[type_D] / c_ref_in_mol_per_l)**nu_D
Expand Down
2 changes: 1 addition & 1 deletion samples/visualization_cellsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
system.time_step = 0.0005
system.cell_system.set_regular_decomposition(use_verlet_lists=True)
system.cell_system.skin = 0.4
#system.cell_system.node_grid = [i, j, k]
# system.cell_system.node_grid = [i, j, k]

for i in range(100):
system.part.add(pos=box * np.random.random(3))
Expand Down
4 changes: 2 additions & 2 deletions src/core/BondList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ class BondList {
template <class Archive> void serialize(Archive &ar, long int /* version */) {
if (Archive::is_loading::value) {
std::size_t size{};
ar &size;
ar & size;
m_storage.resize(size);
}

if (Archive::is_saving::value) {
auto size = m_storage.size();
ar &size;
ar & size;
}

ar &boost::serialization::make_array(m_storage.data(), m_storage.size());
Expand Down
2 changes: 1 addition & 1 deletion src/core/MpiCallbacks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ class MpiCallbacks {
if (m_comm.rank() == 0) {
try {
abort_loop();
} catch (...) {
} catch (...) { // NOLINT(bugprone-empty-catch)
}
}
}
Expand Down
Loading

0 comments on commit 6442bc8

Please sign in to comment.