Skip to content

Commit

Permalink
Fix error of linters (#38)
Browse files Browse the repository at this point in the history
* Fix import orders

* Add pyling ignore list

* Update the rcfile for pylint in tox.ini

* Update the .gitignore
  • Loading branch information
FanwangM authored Nov 5, 2024
1 parent fe0799b commit 2cca563
Show file tree
Hide file tree
Showing 22 changed files with 244 additions and 43 deletions.
165 changes: 161 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,163 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# Ignore (in-place) build results
*.pyc
# C extensions
*.so

# Ignore PyCharm
.idea
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
doc/_build/
doc/html/
doc/latex/
doc/man/
doc/xml/
doc/source
doc/modules

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# Editor junk
tags
[._]*.s[a-v][a-z]
[._]*.sw[a-p]
[._]s[a-v][a-z]
[._]sw[a-p]
*~
\#*\#
.\#*
.ropeproject
.idea/
.spyderproject
.spyproject
.vscode/
# Mac .DS_Store
.DS_Store

# jupyter notebook checkpoints
.ipynb_checkpoints

# codecov files
*.gcno
*.gcda
*.gcov

*/*/_build
*/_build
6 changes: 3 additions & 3 deletions bfit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
# ---
r"""Package for fitting densities to a linear combination of Gaussians."""

from bfit.density import *
from bfit.fit import *
from bfit.greedy import *
from bfit.grid import *
from bfit.model import *
from bfit.density import *
from bfit.measure import *
from bfit.greedy import *
from bfit.model import *
3 changes: 1 addition & 2 deletions bfit/_slater.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

import numpy as np


__all__ = ["load_slater_wfn"]


Expand Down Expand Up @@ -127,7 +126,7 @@ def _get_number_of_electrons_per_orbital(configuration):
for x in orbitals:
if x in electron_config_list:
index = electron_config_list.index(x)
orbital = (electron_config_list[index: index + 2])
orbital = electron_config_list[index : index + 2]

if orbital[1] == "D" or orbital[1] == "F":
num_electrons = re.search(orbital + r"\((.*?)\)", electron_config_list).group(1)
Expand Down
2 changes: 1 addition & 1 deletion bfit/density.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
# ---
r"""Slater Atomic Density Module."""

from bfit._slater import load_slater_wfn
import numpy as np
from scipy.special import factorial

from bfit._slater import load_slater_wfn

__all__ = ["SlaterAtoms"]

Expand Down
6 changes: 3 additions & 3 deletions bfit/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
# ---
r"""Fitting Algorithms."""

from timeit import default_timer as timer
import warnings
from timeit import default_timer as timer

from bfit.measure import KLDivergence, Measure, SquaredDifference
import numpy as np
from scipy.optimize import minimize, NonlinearConstraint
from scipy.optimize import NonlinearConstraint, minimize

from bfit.measure import KLDivergence, Measure, SquaredDifference

__all__ = ["KLDivergenceFPI", "ScipyFit"]

Expand Down
9 changes: 6 additions & 3 deletions bfit/greedy.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@

from abc import ABCMeta, abstractmethod

from bfit.fit import _BaseFit, KLDivergenceFPI, ScipyFit
from bfit.measure import SquaredDifference
from bfit.model import AtomicGaussianDensity
import numpy as np
from scipy.optimize import nnls

from bfit.fit import KLDivergenceFPI, ScipyFit, _BaseFit
from bfit.measure import SquaredDifference
from bfit.model import AtomicGaussianDensity

__all__ = ["GreedyLeastSquares", "GreedyKLFPI"]


Expand Down Expand Up @@ -801,6 +802,7 @@ def optimize_using_nnls(true_dens, cofactor_matrix):
row_nnls_coefficients = nnls(cofactor_matrix, b_vector)
return row_nnls_coefficients[0]

# pylint: disable=arguments-differ
def get_optimization_routine(self, params, local=False):
r"""Optimize least-squares using nnls and scipy.optimize from ScipyFit."""
# First solves the optimal coefficients (while exponents are fixed) using NNLS.
Expand Down Expand Up @@ -946,6 +948,7 @@ def get_best_one_function_solution(self):
exps = 3. * self.integral_dens / (2. * 4. * np.pi * denom)
return np.array([self.integral_dens, exps])

# pylint: disable=arguments-differ
def get_optimization_routine(self, params, local=False):
r"""Optimize KL using KL-FPI method."""
coeffs, exps = params[:len(params)//2], params[len(params)//2:]
Expand Down
1 change: 0 additions & 1 deletion bfit/measure.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

import numpy as np


__all__ = ["SquaredDifference", "KLDivergence", "TsallisDivergence"]


Expand Down
7 changes: 4 additions & 3 deletions bfit/test/test_density.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@
# ---
r"""Test bfit.density module."""

from bfit.density import SlaterAtoms
from bfit.grid import ClenshawRadialGrid
import numpy as np
from numpy.testing import assert_almost_equal, assert_equal, assert_raises
import scipy
from numpy.testing import assert_almost_equal, assert_equal, assert_raises

from bfit.density import SlaterAtoms
from bfit.grid import ClenshawRadialGrid


def slater(e, n, r, derivative=False):
Expand Down
5 changes: 3 additions & 2 deletions bfit/test/test_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@
# ---
r"""Test bfit.fit module."""

import numpy as np
from numpy.testing import assert_almost_equal, assert_equal, assert_raises

from bfit.fit import KLDivergenceFPI, ScipyFit
from bfit.grid import CubicGrid, UniformRadialGrid
from bfit.measure import KLDivergence, SquaredDifference
from bfit.model import AtomicGaussianDensity, MolecularGaussianDensity
import numpy as np
from numpy.testing import assert_almost_equal, assert_equal, assert_raises


def test_lagrange_multiplier():
Expand Down
13 changes: 9 additions & 4 deletions bfit/test/test_greedy.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@
# ---
r"""Test file for 'bfit.greedy'."""

import numpy as np
import numpy.testing as npt

from bfit.greedy import (
get_next_choices, get_two_next_choices, GreedyKLFPI,
GreedyLeastSquares, pick_two_lose_one, remove_redundancies
GreedyKLFPI,
GreedyLeastSquares,
get_next_choices,
get_two_next_choices,
pick_two_lose_one,
remove_redundancies,
)
from bfit.grid import UniformRadialGrid
import numpy as np
import numpy.testing as npt


def test_check_redundancies():
Expand Down
3 changes: 2 additions & 1 deletion bfit/test/test_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
# ---
r"""Test bfit.grid module."""

from bfit.grid import _BaseRadialGrid, ClenshawRadialGrid, CubicGrid, UniformRadialGrid
import numpy as np
from numpy.testing import assert_almost_equal, assert_raises

from bfit.grid import ClenshawRadialGrid, CubicGrid, UniformRadialGrid, _BaseRadialGrid


def test_raises_base():
r"""Test _BaseRadialGrid raises errors."""
Expand Down
7 changes: 4 additions & 3 deletions bfit/test/test_measure.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
# ---
r"""Test bfit.measure module."""

from bfit.measure import KLDivergence, SquaredDifference, TsallisDivergence
import numpy as np
from numpy.testing import assert_almost_equal, assert_raises

from bfit.measure import KLDivergence, SquaredDifference, TsallisDivergence


def test_raises_kl():
r"""Test raise error when using Kullback-Leibler."""
Expand Down Expand Up @@ -193,8 +194,8 @@ def test_evaluating_tsallis_derivative_against_finite_difference():
_, actual_deriv = measure.evaluate(dens, model, deriv=True)
measure_pt_plus_1 = measure.evaluate(dens, model + eps, deriv=False)
measure_pt_plus_2 = measure.evaluate(dens, model + 2.0 * eps, deriv=False)
desired = (measure_pt_minus_2 / 12.0 - (2.0 / 3.0) * measure_pt_minus_1)
desired += ((2.0 / 3.0) * measure_pt_plus_1 - measure_pt_plus_2 / 12.0)
desired = measure_pt_minus_2 / 12.0 - (2.0 / 3.0) * measure_pt_minus_1
desired += (2.0 / 3.0) * measure_pt_plus_1 - measure_pt_plus_2 / 12.0
assert_almost_equal(actual_deriv, desired / eps, decimal=1)


Expand Down
5 changes: 3 additions & 2 deletions bfit/test/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@
# ---
r"""Test bfit.model module."""

from bfit.grid import CubicGrid, UniformRadialGrid
from bfit.model import AtomicGaussianDensity, MolecularGaussianDensity
import numpy as np
from numpy.testing import assert_almost_equal, assert_equal, assert_raises

from bfit.grid import CubicGrid, UniformRadialGrid
from bfit.model import AtomicGaussianDensity, MolecularGaussianDensity


def test_raises_gaussian_model():
r"""Test raises error of all Gaussian model classes."""
Expand Down
3 changes: 2 additions & 1 deletion bfit/test/test_slater.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
# ---
r"""Test bfit._slater module."""

from bfit._slater import load_slater_wfn
import numpy as np

from bfit._slater import load_slater_wfn


def test_parsing_slater_density_be():
r"""Test correct parsing of beryllium Slater file."""
Expand Down
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#
import os
import sys

sys.path.insert(0, os.path.abspath('../'))


Expand Down
Loading

0 comments on commit 2cca563

Please sign in to comment.