Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Linting with Pylint #150

Merged
merged 45 commits into from
Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
6713a24
initial pylint config
nathanaelbosch Aug 13, 2020
5eff86e
Unrelated small tox fix (unused line)
nathanaelbosch Aug 17, 2020
acb56ec
added some more exceptions to pylint, which will influence my order o…
nathanaelbosch Aug 13, 2020
21212cd
renamed github workflow and added pylint
nathanaelbosch Aug 13, 2020
7d5ef3d
added black and pylint to the default tox envs
nathanaelbosch Aug 13, 2020
82cb7a9
Added some more pylint exceptions for now
nathanaelbosch Aug 17, 2020
2063aae
Fixed "useless-super-delegation"
nathanaelbosch Aug 17, 2020
433d04a
Fixed "unused-import"
nathanaelbosch Aug 17, 2020
55e35e3
Fixed "empty-docstring"
nathanaelbosch Aug 17, 2020
e66918d
More exceptions for now
nathanaelbosch Aug 17, 2020
c830000
Fixed "trailing-whitespace"
nathanaelbosch Aug 17, 2020
1f633c3
Fixed "unneeded-not"
nathanaelbosch Aug 17, 2020
bdf419c
Fixed "consider-using-in"
nathanaelbosch Aug 17, 2020
cbc113c
Fixed "consider-merging-isinstance"
nathanaelbosch Aug 17, 2020
84cc9af
Fixed "inconsistent-return-statements"
nathanaelbosch Aug 17, 2020
9f52892
Fixed "simplifiable-if-statement"
nathanaelbosch Aug 17, 2020
624b05e
Fixed "unidiomatic-typecheck"
nathanaelbosch Aug 17, 2020
c65f535
Fixed "super-init-not-called"
nathanaelbosch Aug 17, 2020
d185400
Fixed "wildcard-import"
nathanaelbosch Aug 17, 2020
2762eb9
Fixed "anomalous-backslash-in-string"
nathanaelbosch Aug 17, 2020
21c97c7
Many more disabled messages, but all checks pass
nathanaelbosch Aug 17, 2020
a5f7cee
Fixed "unused-wildcard-import"
nathanaelbosch Aug 17, 2020
8834b33
Fixed "line-too-long"
nathanaelbosch Aug 17, 2020
193ad6a
Only lint `./src` for now, not `./test`
nathanaelbosch Aug 18, 2020
46b4672
Fixed "empty-docstring" in ./tests
nathanaelbosch Aug 18, 2020
69596de
Fixed "wildcard-import" in ./tests
nathanaelbosch Aug 18, 2020
0b9aa1f
Fixed "unused-import" in ./tests
nathanaelbosch Aug 18, 2020
c7b4655
Added exceptions for "cell-var-from-loop" in some tests
nathanaelbosch Aug 18, 2020
2502c79
Fixed "no-member" and "c-extension-no-member"
nathanaelbosch Aug 18, 2020
45dab4c
Added exception for a "consider-using-in" in a test
nathanaelbosch Aug 18, 2020
4b41e9e
Add tests back into pylint, but with even more exceptions
nathanaelbosch Aug 18, 2020
b46e5a2
Final exception to pass the tests
nathanaelbosch Aug 18, 2020
e142859
Fixed "wrong-import-order" by adding an in-file exception
nathanaelbosch Aug 18, 2020
a7b8236
Grouped the docstring exceptions
nathanaelbosch Aug 18, 2020
e75199d
Fixed "wrong-import-order" in tests
nathanaelbosch Aug 18, 2020
eb412b6
Fixed "unused-variable"
nathanaelbosch Aug 18, 2020
adad439
Fixed "wrong-impor-order" in tests for real
nathanaelbosch Aug 18, 2020
22311d8
Added mccabe complexity checker
nathanaelbosch Aug 18, 2020
970f953
Added more pylint extensions
nathanaelbosch Aug 18, 2020
e12dae6
Merge branch 'master' into pylint
JonathanWenger Aug 18, 2020
6e847a5
Fixed sphinx warnings
nathanaelbosch Aug 18, 2020
e932102
Changed pylint to run on a per-module basis, more srictly
nathanaelbosch Aug 19, 2020
f21a742
Added the benchmarks to pylint
nathanaelbosch Aug 19, 2020
4470023
More comments for the pylint config in pyproject.toml
nathanaelbosch Aug 19, 2020
7c282b3
Moved the "missing docu" exceptions to a per-module basis
nathanaelbosch Aug 19, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .github/workflows/black.yml → .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,12 @@ jobs:
run: pip install tox
- name: Run black through tox
run: tox -e black

pylint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- name: Install tox
run: pip install tox
- name: Run pylint through tox
run: tox -e pylint
1 change: 0 additions & 1 deletion benchmarks/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

34 changes: 33 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,36 @@ exclude = '''
| build
| dist
)/
'''
'''


[tool.pylint.messages_control]
# Exceptions suggested from Black: bad-continuation, bad-whitespace
disable = """
bad-continuation,
bad-whitespace,

invalid-name,

no-else-return,
no-else-raise,
"""
# Many more `disable`s are defined in `./tox.ini` on a per-module basis!

[tool.pylint.format]
max-line-length = "88"

[tool.pylint.master]
extension-pkg-whitelist = "numpy"
# Extensions that might be of interest in the future:
# pylint.extensions.docstyle,
# pylint.extensions.check_elif,
# pylint.extensions.docparams,
load-plugins = """
pylint.extensions.mccabe,
pylint.extensions.redefined_variable_type,
pylint.extensions.overlapping_exceptions,
"""

[tool.pylint.design]
max-complexity = "14"
1 change: 1 addition & 0 deletions src/probnum/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
diffeq
Probabilistic solvers for ordinary differential equations.
"""
# pylint: disable=wrong-import-order

from . import diffeq
from . import filtsmooth
Expand Down
6 changes: 2 additions & 4 deletions src/probnum/diffeq/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
"""
"""

from .ode import *
from .odefiltsmooth import *
from .steprule import *
Expand Down Expand Up @@ -30,7 +27,8 @@
"ODESolution",
]

# Set correct module paths (for superclasses). Corrects links and module paths in documentation.
# Set correct module paths (for superclasses).
# Corrects links and module paths in documentation.
ODE.__module__ = "probnum.diffeq"
ODESolver.__module__ = "probnum.diffeq"
StepRule.__module__ = "probnum.diffeq"
3 changes: 0 additions & 3 deletions src/probnum/diffeq/ode/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
"""
"""

from .ivp import *
from .ode import *

Expand Down
4 changes: 2 additions & 2 deletions src/probnum/diffeq/ode/ivp.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
there might be more ode-based problems,
such as bvp.
"""
# pylint: disable=unused-variable

import numpy as np

Expand Down Expand Up @@ -284,8 +285,7 @@ class IVP(ODE):
"""

def __init__(self, timespan, initrv, rhs, jac=None, hess=None, sol=None):
"""
"""

self.initrv = initrv
super().__init__(timespan=timespan, rhs=rhs, jac=jac, hess=hess, sol=sol)

Expand Down
2 changes: 1 addition & 1 deletion src/probnum/diffeq/ode/ode.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def hessian(self, t, y, **kwargs):
since for any directions :math:`v_1, v_2` the outcome of
:math:`H_f(t_0, y_0) \\cdot v_1 \\cdot v_2` is expected to contain
the incline of :math:`f_i` in direction :math:`(v_1, v_2)`.
"""
""" # pylint: disable=line-too-long
if self._hess is None:
raise NotImplementedError
else:
Expand Down
22 changes: 11 additions & 11 deletions src/probnum/diffeq/odefiltsmooth/ivp2filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"""

import numpy as np
from probnum.filtsmooth import *

from probnum.filtsmooth import ExtendedKalman, UnscentedKalman
from probnum.filtsmooth.statespace.discrete import DiscreteGaussianModel
from probnum.prob import RandomVariable
from probnum.prob.distributions import Normal, Dirac
Expand All @@ -14,19 +15,19 @@ def ivp2ekf0(ivp, prior, evlvar):
"""
Computes measurement model and initial distribution
for KF based on IVP and prior.

**Initialdistribution:**

Conditions the initial distribution of the Gaussian filter
onto the initial values.

- If preconditioning is set to ``False``, it conditions
the initial distribution :math:`\mathcal{N}(0, I)`
the initial distribution :math:`\\mathcal{N}(0, I)`
on the initial values :math:`(x_0, f(t_0, x_0), ...)` using
as many available deri vatives as possible.

- If preconditioning is set to ``True``, it conditions
the initial distribution :math:`\mathcal{N}(0, P P^\\top)`
the initial distribution :math:`\\mathcal{N}(0, P P^\\top)`
on the initial values :math:`(x_0, f(t_0, x_0), ...)` using
as many available derivatives as possible.
Note that the projection matrices :math:`H_0` and :math:`H_1`
Expand All @@ -35,7 +36,7 @@ def ivp2ekf0(ivp, prior, evlvar):

**Measurement model:**

Returns a measurement model :math:`\mathcal{N}(g(m), R)`
Returns a measurement model :math:`\\mathcal{N}(g(m), R)`
involving computing the discrepancy

.. math:: g(m) = H_1 m(t) - f(t, H_0 m(t)).
Expand All @@ -51,7 +52,7 @@ def ivp2ekf0(ivp, prior, evlvar):
model, :math:`H_0` and :math:`H_1`
become :math:`H_0 P^{-1}` and :math:`H_1 P^{-1}` which has
to be taken into account. In this case,

- EKF0 thinks :math:`J_g(m) = H_1 P^{-1}`
- EKF1 thinks :math:`J_g(m) = H_1 P^{-1} - J_f(t, H_0 P^{-1} m(t)) (H_0 P^{-1})^\\top`
- UKF again thinks: ''What is a Jacobian?''
Expand All @@ -65,7 +66,7 @@ def ivp2ekf0(ivp, prior, evlvar):

evlvar : float,
measurement variance; in the literature, this is "R"
"""
""" # pylint: disable=line-too-long
measmod = _measmod_ekf0(ivp, prior, evlvar)
initrv = _initialdistribution(ivp, prior)
return ExtendedKalman(prior, measmod, initrv)
Expand Down Expand Up @@ -143,8 +144,7 @@ def ivp2ukf(ivp, prior, evlvar):


def _measmod_ukf(ivp, prior, measvar):
"""
"""

spatialdim = prior.spatialdim
h0 = prior.proj2coord(coord=0)
h1 = prior.proj2coord(coord=1)
Expand All @@ -160,7 +160,7 @@ def diff(t, **kwargs):

def _initialdistribution(ivp, prior):
"""
Conditions initialdistribution :math:`\mathcal{N}(0, P P^\\top)`
Conditions initialdistribution :math:`\\mathcal{N}(0, P P^\\top)`
on the initial values :math:`(x_0, f(t_0, x_0), ...)` using
as many available derivatives as possible.

Expand Down Expand Up @@ -203,7 +203,7 @@ def _initialdistribution(ivp, prior):


def _initialdistribution_no_precond(ivp, prior):
""" """

x0 = ivp.initialdistribution.mean()
dx0 = ivp.rhs(ivp.t0, x0)
ddx0 = _ddx(ivp.t0, x0, ivp)
Expand Down
2 changes: 0 additions & 2 deletions src/probnum/diffeq/odefiltsmooth/ivpfiltsmooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from probnum.prob.distributions import Normal
from probnum.diffeq import odesolver
from probnum.diffeq.odefiltsmooth.prior import ODEPrior
from probnum.filtsmooth import *
from probnum.diffeq.odesolution import ODESolution


Expand Down Expand Up @@ -172,5 +171,4 @@ def _suggest_step(self, step, errorest):

@property
def prior(self):
""" """
return self.gfilt.dynamicmodel
25 changes: 10 additions & 15 deletions src/probnum/diffeq/odefiltsmooth/odefiltsmooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def _create_solver_object(


def _check_step_tol(step, tol):
""" """

both_none = tol is None and step is None
both_not_none = tol is not None and step is not None
if both_none or both_not_none:
Expand All @@ -264,14 +264,13 @@ def _check_step_tol(step, tol):


def _check_method(method):
""" """

if method not in ["ekf0", "ekf1", "ukf", "eks0", "eks1", "uks"]:
raise ValueError("Method not supported.")


def _string2prior(ivp, which_prior, precond_step, **kwargs):
"""
"""

ibm_family = ["ibm1", "ibm2", "ibm3", "ibm4"]
ioup_family = ["ioup1", "ioup2", "ioup3", "ioup4"]
matern_family = ["matern32", "matern52", "matern72", "matern92"]
Expand All @@ -286,8 +285,7 @@ def _string2prior(ivp, which_prior, precond_step, **kwargs):


def _string2ibm(ivp, which_prior, precond_step, **kwargs):
"""
"""

if "diffconst" in kwargs.keys():
diffconst = kwargs["diffconst"]
else:
Expand All @@ -305,8 +303,7 @@ def _string2ibm(ivp, which_prior, precond_step, **kwargs):


def _string2ioup(ivp, which_prior, precond_step, **kwargs):
"""
"""

if "diffconst" in kwargs.keys():
diffconst = kwargs["diffconst"]
else:
Expand All @@ -328,8 +325,7 @@ def _string2ioup(ivp, which_prior, precond_step, **kwargs):


def _string2matern(ivp, which_prior, precond_step, **kwargs):
"""
"""

if "diffconst" in kwargs.keys():
diffconst = kwargs["diffconst"]
else:
Expand All @@ -351,17 +347,16 @@ def _string2matern(ivp, which_prior, precond_step, **kwargs):


def _string2filter(_ivp, _prior, _method, **kwargs):
"""
"""

if "evlvar" in kwargs.keys():
evlvar = kwargs["evlvar"]
else:
evlvar = 0.0
if _method == "ekf0" or _method == "eks0":
if _method in ("ekf0", "eks0"):
return ivp2filter.ivp2ekf0(_ivp, _prior, evlvar)
elif _method == "ekf1" or _method == "eks1":
elif _method in ("ekf1", "eks1"):
return ivp2filter.ivp2ekf1(_ivp, _prior, evlvar)
elif _method == "ukf" or _method == "uks":
elif _method in ("ukf", "uks"):
return ivp2filter.ivp2ukf(_ivp, _prior, evlvar)
else:
raise ValueError("Type of filter not supported.")
8 changes: 4 additions & 4 deletions src/probnum/diffeq/odefiltsmooth/prior.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ODEPrior(LTISDEModel):
matrix that maps to filtering iteration to the Nordsieck vector,

.. math:: P = \\text{diag }(1, h, h^2, ..., h^q).

Here, :math:`h` is some expected average step size. Note that we
ignored the factorials in this matrix. Our setting makes it easy to
recover "no preconditioning" by choosing :math:`h=1`.
Expand Down Expand Up @@ -78,7 +78,6 @@ class ODEPrior(LTISDEModel):
"""

def __init__(self, driftmat, dispmat, ordint, spatialdim, precond_step=1.0):
""" """
self.ordint = ordint
self.spatialdim = spatialdim
self.precond, self.invprecond = self.precond2nordsieck(precond_step)
Expand Down Expand Up @@ -283,7 +282,8 @@ def _trans_ibm(self, start, stop):
step = stop - start

# This seems like the faster solution compared to fully vectorising.
# I suspect it is because np.math.factorial is much faster than scipy.special.factorial
# I suspect it is because np.math.factorial is much faster than
# scipy.special.factorial
ah_1d = np.diag(np.ones(self.ordint + 1), 0)
for i in range(self.ordint):
offdiagonal = (
Expand Down Expand Up @@ -394,7 +394,7 @@ def _driftmat_matern(ordint, spatialdim, lengthscale):

def _dispmat(ordint, spatialdim, diffconst):
"""
Returns I_D \otimes L
Returns I_D \\otimes L
diffconst = sigma**2
"""
dispvec = diffconst * np.eye(ordint + 1)[:, -1]
Expand Down
5 changes: 1 addition & 4 deletions src/probnum/diffeq/steprule.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,4 @@ def suggest(self, laststep, errorest, **kwargs):
return step

def is_accepted(self, proposedstep, errorest, **kwargs):
if errorest * proposedstep < self.tol_per_step:
return True
else:
return False
return errorest * proposedstep < self.tol_per_step
Loading