Skip to content

Commit

Permalink
Cleaning up and fix the flake8 complains (#40)
Browse files Browse the repository at this point in the history
* Cleaning up and fix the flake8 complains

* Add iosrt configurations

* Add `application-import-names`

* Fix the import order errors from flake8
  • Loading branch information
FanwangM authored Nov 6, 2024
1 parent 2cca563 commit dd78a46
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 43 deletions.
2 changes: 1 addition & 1 deletion bfit/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from timeit import default_timer as timer

import numpy as np
from scipy.optimize import NonlinearConstraint, minimize
from scipy.optimize import minimize, NonlinearConstraint

from bfit.measure import KLDivergence, Measure, SquaredDifference

Expand Down
2 changes: 1 addition & 1 deletion bfit/greedy.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import numpy as np
from scipy.optimize import nnls

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

Expand Down
4 changes: 2 additions & 2 deletions bfit/test/test_greedy.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
import numpy.testing as npt

from bfit.greedy import (
GreedyKLFPI,
GreedyLeastSquares,
get_next_choices,
get_two_next_choices,
GreedyKLFPI,
GreedyLeastSquares,
pick_two_lose_one,
remove_redundancies,
)
Expand Down
2 changes: 1 addition & 1 deletion bfit/test/test_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import numpy as np
from numpy.testing import assert_almost_equal, assert_raises

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


def test_raises_base():
Expand Down
24 changes: 12 additions & 12 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.napoleon',
'sphinx.ext.autodoc',
'sphinx.ext.todo',
'sphinx.ext.mathjax',
'sphinx.ext.viewcode',
'sphinx.ext.githubpages',
'numpydoc',
"sphinx.ext.napoleon",
"sphinx.ext.autodoc",
"sphinx.ext.todo",
"sphinx.ext.mathjax",
"sphinx.ext.viewcode",
"sphinx.ext.githubpages",
"numpydoc",
# 'sphinx.ext.autosummary',
'sphinx.ext.doctest',
"sphinx.ext.doctest",
# for adding “copy to clipboard” buttons to all text/code boxes
'sphinx_copybutton',
'autoapi.extension',
'nbsphinx',
#'sphinxcontrib.bibtex'
"sphinx_copybutton",
"autoapi.extension",
"nbsphinx",
# 'sphinxcontrib.bibtex',
]

# Add any paths that contain templates here, relative to this directory.
Expand Down
31 changes: 21 additions & 10 deletions examples/atomdb_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,29 @@
import numpy as np
from atomdb import load

from bfit.density import SlaterAtoms
from bfit.fit import KLDivergenceFPI, ScipyFit
from bfit.fit import KLDivergenceFPI
from bfit.grid import ClenshawRadialGrid
from bfit.measure import KLDivergence
from bfit.model import AtomicGaussianDensity
from bfit.parse_ugbs import get_ugbs_exponents

# change the path to the location of the AtomDB data as needed
DATAPATH = ("/home/ali-tehrani/SoftwareProjects/AtomDBdata",)

results_final = {}
atoms = ["H", "C", "N", "O", "F", "P", "S", "Cl"]
atomic_numbs = [1, 6, 7, 8, 9, 15, 16, 17] #[1 + i for i in range(0, len(atoms))]
atomic_numbs = [1, 6, 7, 8, 9, 15, 16, 17] # [1 + i for i in range(0, len(atoms))]
mult = [2, 3, 4, 3, 2, 4, 3, 2]
for k, element in enumerate(atoms):
print("Start Atom %s" % element)

# Construct a integration grid
atomic_numb = atomic_numbs[k]
grid = ClenshawRadialGrid(
atomic_numb, num_core_pts=10000, num_diffuse_pts=899, include_origin=True#, extra_pts=[50,75,100],
atomic_numb,
num_core_pts=10000,
num_diffuse_pts=899,
include_origin=True,
# extra_pts=[50,75,100],
)

# Initial Guess constructed from UGBS
Expand All @@ -41,15 +46,19 @@
e_0 = np.array(exps_s + exps_p) * 2.0

# Construct Atomic Density and Fitting Object
#density = SlaterAtoms(element=element).atomic_density(grid.points)
# density = SlaterAtoms(element=element).atomic_density(grid.points)
# Use AtomDB to calculate the density
atom = load(elem=element, charge=0, mult=mult[k], dataset="hci", datapath="/home/ali-tehrani/SoftwareProjects/AtomDBdata")
atom = load(
elem=element,
charge=0,
mult=mult[k],
dataset="hci",
datapath=DATAPATH,
)

dens = atom.dens_func()
density = dens(grid.points)

import matplotlib.pyplot as plt

# plt.plot(grid.points, density, "bo-")
# plt.show()
print(density[-1], grid.points[-1], grid.points[0:3])
Expand All @@ -69,7 +78,9 @@
# measure = KLDivergence(mask_value=1e-18)
# fit_KL_slsqp = ScipyFit(grid, density, model, measure=measure, method="SLSQP", spherical=True)
# # Run the SLSQP optimization algorithm
# results = fit_KL_slsqp.run(coeffs, e_0, maxiter=10000, disp=True, with_constraint=True, tol=1e-14)
# results = fit_KL_slsqp.run(
# coeffs, e_0, maxiter=10000, disp=True, with_constraint=True, tol=1e-14
# )

print("KL-FPI INFO")
print("-----------")
Expand Down
2 changes: 1 addition & 1 deletion examples/table/table_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import numpy as np

from bfit.density import SlaterAtoms
from bfit.fit import KLDivergenceFPI, ScipyFit
from bfit.fit import ScipyFit
from bfit.grid import ClenshawRadialGrid
from bfit.measure import KLDivergence
from bfit.model import AtomicGaussianDensity
Expand Down
10 changes: 0 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,6 @@ line-length = 100
# )
# '''

[tool.isort]
profile = "black"
known_first_party = ["bfit"]
# If you need to exclude files from having their imports sorted
#extend_skip_glob = [
# "bfit/somefile.py",
# "bfit/somedir/*",
#]

# https://beta.ruff.rs/docs
[tool.ruff]
line-length = 100
Expand Down Expand Up @@ -329,4 +320,3 @@ disable=[
"no-else-return",
"too-many-statements",
]

14 changes: 9 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ commands =
ignore_errors = true

[testenv:linters]
ignore_errors = true
# allow for linters to fail
# ignore_outcome = true
deps =
numpy
scipy
Expand All @@ -39,15 +42,13 @@ deps =
# black
bandit
commands =
flake8 bfit/ bfit/test
python -m flake8 --config=tox.ini bfit/ bfit/test
pylint bfit --rcfile=pyproject.toml --disable=similarities
# black -l 100 --check ./
# black -l 100 --diff ./
# Use bandit configuration file
bandit -r bfit -c .bandit.yml

ignore_errors = true

[testenv:coverage-report]
deps = coverage>=4.2
skip_install = true
Expand Down Expand Up @@ -93,8 +94,10 @@ exclude =
.eggs,

max-line-length = 100
import-order-style = google
ignore =
; import-order-style = google
import-order-style = smarkets
application-import-names = bfit
extend-ignore =
# E121 : continuation line under-indented for hanging indent
E121,
# E123 : closing bracket does not match indentation of opening bracket’s line
Expand Down Expand Up @@ -191,3 +194,4 @@ source =
bfit
.tox/*/lib/python*/site-packages/bfit
.tox/pypy*/site-packages/bfit

0 comments on commit dd78a46

Please sign in to comment.