diff --git a/maintainer/CI/fix_style.sh b/maintainer/CI/fix_style.sh index d90fe4c6ebf..e6199bfb62f 100755 --- a/maintainer/CI/fix_style.sh +++ b/maintainer/CI/fix_style.sh @@ -25,7 +25,7 @@ if ! git diff-index --quiet HEAD -- && [ "${1}" != "-f" ]; then exit 1 fi -maintainer/lint/pre_commit.sh run --all-files || exit 1 +maintainer/lint/pre_commit.sh run --all-files if [ "${CI}" != "" ]; then git --no-pager diff > style.patch diff --git a/maintainer/gh_post_style_patch.py b/maintainer/gh_post_style_patch.py index 6de2ab18d6c..9cfbd69446c 100755 --- a/maintainer/gh_post_style_patch.py +++ b/maintainer/gh_post_style_patch.py @@ -43,13 +43,13 @@ MESSAGE = '''Your pull request does not meet our code formatting \ rules. {header}, please do one of the following: -- You can download a patch with my suggested changes - [here]({url}/artifacts/raw/style.patch), inspect it and make +- You can download a patch with my suggested changes \ + [here]({url}/artifacts/raw/style.patch), inspect it and make \ changes manually. -- You can directly apply it to your repository by running +- You can directly apply it to your repository by running \ `curl {url}/artifacts/raw/style.patch | git apply -`. -- You can run `maintainer/CI/fix_style.sh` to automatically fix your coding - style. This is the same command that I have executed to generate the patch +- You can run `maintainer/CI/fix_style.sh` to automatically fix your coding \ + style. This is the same command that I have executed to generate the patch \ above, but it requires certain tools to be installed on your computer. You can run `gitlab-runner exec docker style` afterwards to check if your \ diff --git a/src/python/espressomd/electrostatics.pyx b/src/python/espressomd/electrostatics.pyx index 884d931740f..92ea05ba72f 100644 --- a/src/python/espressomd/electrostatics.pyx +++ b/src/python/espressomd/electrostatics.pyx @@ -25,7 +25,7 @@ IF SCAFACOS == 1: from .scafacos import ScafacosConnector from . cimport scafacos from .utils cimport handle_errors -from .utils import is_valid_type, to_str +from .utils import is_valid_type, check_type_or_throw_except, to_str from . cimport checks from .analyze cimport partCfg, PartCfg from .particle_data cimport particle @@ -240,13 +240,13 @@ IF P3M == 1: or self._params["r_cut"] == default_params["r_cut"]): raise ValueError("P3M r_cut has to be >=0") - if not (is_valid_type(self._params["mesh"], int) - or len(self._params["mesh"]) == 3): - raise ValueError( - "P3M mesh has to be an integer or integer list of length 3") - - if (isinstance(self._params["mesh"], basestring) and len( - self._params["mesh"]) == 3): + if is_valid_type(self._params["mesh"], int): + if self._params["mesh"] % 2 != 0 and self._params["mesh"] != -1: + raise ValueError( + "P3M requires an even number of mesh points in all directions") + else: + check_type_or_throw_except(self._params["mesh"], 3, int, + "P3M mesh has to be an integer or integer list of length 3") if (self._params["mesh"][0] % 2 != 0 and self._params["mesh"][0] != -1) or \ (self._params["mesh"][1] % 2 != 0 and self._params["mesh"][1] != -1) or \ (self._params["mesh"][2] % 2 != 0 and self._params["mesh"][2] != -1): @@ -267,10 +267,9 @@ IF P3M == 1: or self._params["epsilon"] == "metallic"): raise ValueError("epsilon should be a double or 'metallic'") - if not (self._params["mesh_off"] == default_params["mesh_off"] - or len(self._params) != 3): - raise ValueError( - "mesh_off should be a list of length 3 and values between 0.0 and 1.0") + if self._params["mesh_off"] != default_params["mesh_off"]: + check_type_or_throw_except(self._params["mesh_off"], 3, float, + "mesh_off should be a (3,) array_like of values between 0.0 and 1.0") if not (self._params["alpha"] == default_params["alpha"] or self._params["alpha"] > 0): @@ -382,13 +381,13 @@ IF P3M == 1: or self._params["r_cut"] == default_params["r_cut"]): raise ValueError("P3M r_cut has to be >=0") - if not (is_valid_type(self._params["mesh"], int) - or len(self._params["mesh"]) == 3): - raise ValueError( - "P3M mesh has to be an integer or integer list of length 3") - - if (isinstance(self._params["mesh"], basestring) and len( - self._params["mesh"]) == 3): + if is_valid_type(self._params["mesh"], int): + if self._params["mesh"] % 2 != 0 and self._params["mesh"] != -1: + raise ValueError( + "P3M requires an even number of mesh points in all directions") + else: + check_type_or_throw_except(self._params["mesh"], 3, int, + "P3M mesh has to be an integer or integer list of length 3") if (self._params["mesh"][0] % 2 != 0 and self._params["mesh"][0] != -1) or \ (self._params["mesh"][1] % 2 != 0 and self._params["mesh"][1] != -1) or \ (self._params["mesh"][2] % 2 != 0 and self._params["mesh"][2] != -1): @@ -411,10 +410,9 @@ IF P3M == 1: raise ValueError( "epsilon should be a double or 'metallic'") - if not (self._params["mesh_off"] == default_params["mesh_off"] - or len(self._params) != 3): - raise ValueError( - "mesh_off should be a list of length 3 with values between 0.0 and 1.0") + if self._params["mesh_off"] != default_params["mesh_off"]: + check_type_or_throw_except(self._params["mesh_off"], 3, float, + "mesh_off should be a (3,) array_like of values between 0.0 and 1.0") def valid_keys(self): return ["mesh", "cao", "accuracy", "epsilon", "alpha", "r_cut", diff --git a/src/python/espressomd/magnetostatics.pyx b/src/python/espressomd/magnetostatics.pyx index d662e16eac0..5b0f7c73e16 100644 --- a/src/python/espressomd/magnetostatics.pyx +++ b/src/python/espressomd/magnetostatics.pyx @@ -24,7 +24,7 @@ IF SCAFACOS == 1: from . cimport scafacos from .utils cimport handle_errors -from .utils import is_valid_type, to_str +from .utils import is_valid_type, check_type_or_throw_except, to_str IF DIPOLES == 1: cdef class MagnetostaticInteraction(Actor): @@ -101,13 +101,13 @@ IF DP3M == 1: or self._params["r_cut"] == default_params["r_cut"]): raise ValueError("P3M r_cut has to be >=0") - if not (is_valid_type(self._params["mesh"], int) or len( - self._params["mesh"]) == 3): - raise ValueError( - "P3M mesh has to be an integer or integer list of length 3") - - if isinstance(self._params["mesh"], basestring) and len( - self._params["mesh"]) == 3: + if is_valid_type(self._params["mesh"], int): + if self._params["mesh"] % 2 != 0 and self._params["mesh"] != -1: + raise ValueError( + "P3M requires an even number of mesh points in all directions") + else: + check_type_or_throw_except(self._params["mesh"], 3, int, + "P3M mesh has to be an integer or integer list of length 3") if (self._params["mesh"][0] % 2 != 0 and self._params["mesh"][0] != -1) or \ (self._params["mesh"][1] % 2 != 0 and self._params["mesh"][1] != -1) or \ (self._params["mesh"][2] % 2 != 0 and self._params["mesh"][2] != -1): @@ -132,10 +132,9 @@ IF DP3M == 1: or self._params["inter"] > 0): raise ValueError("inter should be a positive integer") - if not (self._params["mesh_off"] == default_params["mesh_off"] - or len(self._params["mesh_off"]) == 3): - raise ValueError( - "mesh_off should be a (3,) array_like of values between 0.0 and 1.0") + if self._params["mesh_off"] != default_params["mesh_off"]: + check_type_or_throw_except(self._params["mesh_off"], 3, float, + "mesh_off should be a (3,) array_like of values between 0.0 and 1.0") def valid_keys(self): return ["prefactor", "alpha_L", "r_cut_iL", "mesh", "mesh_off", @@ -205,7 +204,7 @@ IF DP3M == 1: def python_dp3m_adaptive_tune(self): cdef char * log = NULL cdef int response - response = dp3m_adaptive_tune( & log) + response = dp3m_adaptive_tune(& log) handle_errors( "dipolar P3M_init: k-space cutoff is larger than half of box dimension") return response, log diff --git a/testsuite/scripts/samples/test_lb_profile.py b/testsuite/scripts/samples/test_lb_profile.py index ecf91ade378..7bf60bebea6 100644 --- a/testsuite/scripts/samples/test_lb_profile.py +++ b/testsuite/scripts/samples/test_lb_profile.py @@ -20,7 +20,7 @@ import numpy as np sample, skipIfMissingFeatures = importlib_wrapper.configure_and_import( - "@SAMPLES_DIR@/lb_profile.py") + "@SAMPLES_DIR@/lb_profile.py", gpu=True) @skipIfMissingFeatures