Skip to content

Commit

Permalink
Merge pull request #639 from zerothi/black
Browse files Browse the repository at this point in the history
Black linting
  • Loading branch information
zerothi authored Nov 3, 2023
2 parents 5a63302 + d79400d commit 07359d8
Show file tree
Hide file tree
Showing 388 changed files with 22,924 additions and 14,755 deletions.
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Add here the commits that should be ignored
# when issuing blames
0ff17210003a85b08f683307e9a73555142c8707
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/005_bug.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ about: Let us know if something went wrong

**Describe the bug**

**Reproducable code**
**Code to reproduce problem**
```python
<insert code here>
```
Expand Down
10 changes: 5 additions & 5 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!-- Feel free to remove check-list items aren't relevant to your change -->

- [ ] Closes #xxxx
- [ ] Tests added
- [ ] Ranned `isort .` at top--level
- [ ] Documentation for functionality, `docs/`
- [ ] Changes documented, `CHANGELOG.md`
- [ ] Closes #x
- [ ] Added tests for new/changed functions?
- [ ] Ran `isort .` and `black .` at top-level
- [ ] Documentation for functionality in `docs/`
- [ ] Changes documented in `CHANGELOG.md`
21 changes: 21 additions & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Lint

on:
push:
paths:
- '**.py'
- '**.ipynb'
pull_request:
paths:
- '**.py'
- '**.ipynb'

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: psf/black@stable
with:
jupyter: true
- uses: isort/isort-action@master
17 changes: 10 additions & 7 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ env:


on:
pull_request:
# all pull-requests on to main
branches: [main]
workflow_run:
workflows: [Lint]
types: [completed]
schedule:
# only once every 4 days
# We can always force run this.
Expand All @@ -32,8 +32,11 @@ on:
jobs:

# Define a few jobs that can be runned
check_schedule:
if: ${{ github.event_name == 'schedule' }} && ${{ github.actor != 'dependabot[bot]' }}
check_if_runnable:
if: |
github.event_name == 'schedule'
&& github.actor != 'dependabot[bot]'
&& github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -42,8 +45,8 @@ jobs:
- run: test -n $(git rev-list --after="1 week" --max-count=1 ${{ github.sha }})

test_runs:
needs: [check_schedule]
if: ${{ always() && (contains(needs.*.result, 'success') || contains(needs.*.result, 'skipped')) }}
needs: [check_if_runnable]
if: ${{ contains(needs.*.result, 'success') || contains(needs.*.result, 'skipped') }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ we hit release version 1.0.0.
- fixed cases where `Geometry.close` would not catch all neighbours, #633

### Changed
- sisl now enforces the black style
- `Lattice` now holds the boundary conditions (not `Grid`), see #626
- Some siles exposed certain properties containing basic information
about the content, say number of atoms/orbitals etc.
Expand Down
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ you should add this change to your `.git/config`, or in your global `.gitconfig`
[filter "strip-notebook-output"]
clean = "jupyter nbconvert --ClearOutputPreprocessor.enabled=True --to=notebook --stdin --stdout --log-level=ERROR"

We also enforce the black style, please run black before committing.

## First-time contributors
Add a comment on the issue and wait for the issue to be assigned before you start working on it. This helps to avoid multiple people working on similar issues.

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[![Install sisl using PyPI](https://badge.fury.io/py/sisl.svg)](https://pypi.org/project/sisl)
[![Install sisl using conda](https://anaconda.org/conda-forge/sisl/badges/version.svg)](https://anaconda.org/conda-forge/sisl)
[![License: MPL 2.0](https://img.shields.io/badge/License-MPL%202.0-brightgreen.svg)](https://www.mozilla.org/en-US/MPL/2.0/)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![DOI for citation](https://zenodo.org/badge/doi/10.5281/zenodo.597181.svg)](https://doi.org/10.5281/zenodo.597181)
<!--- [![Documentation on RTD](https://readthedocs.org/projects/docs/badge/?version=latest)](http://sisl.readthedocs.io/en/latest/) -->
[![Join discussion on Discord](https://img.shields.io/discord/742636379871379577.svg?label=&logo=discord&logoColor=ffffff&color=green&labelColor=red)](https://discord.gg/5XnFXFdkv2)
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/bloch.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@

stat = pstats.Stats(pr)
# We sort against total-time
stat.sort_stats('tottime')
stat.sort_stats("tottime")
# Only print the first 20% of the routines.
stat.print_stats('sisl', 0.2)
stat.print_stats("sisl", 0.2)
7 changes: 5 additions & 2 deletions benchmarks/bz_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@
par = bz.apply.renew(eta=True)

E = np.linspace(-2, 2, 200)


def wrap_DOS(es):
return es.DOS(E)
dos = par.ndarray.eigenstate(wrap=wrap_DOS)
#dos = par.average.eigenstate(wrap=wrap_DOS)


dos = par.ndarray.eigenstate(wrap=wrap_DOS)
# dos = par.average.eigenstate(wrap=wrap_DOS)
29 changes: 21 additions & 8 deletions benchmarks/bz_replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,16 @@
nks = [50 for _ in range(nlvls)]

if ndim == 1:

def get_nk(nk):
return [nk, 1, 1]

ns = [2 for _ in range(nlvls)]
else:

def get_nk(nk):
return [nk, nk, 1]

if nlvls > 2:
ns = [50 for _ in range(nlvls)]
else:
Expand All @@ -55,11 +59,12 @@ def get_nk(nk):
def yield_kpoint(bz, n):
yield from np.unique(np.random.randint(len(bz), size=n))[::-1]


# Replacement function


def add_levels(bz, nks, ns, fast=False, as_index=False, debug=False):
""" Add different levels according to the length of `ns` """
"""Add different levels according to the length of `ns`"""
global nlvls

lvl = nlvls - len(nks)
Expand All @@ -72,6 +77,7 @@ def add_levels(bz, nks, ns, fast=False, as_index=False, debug=False):
bz = bz.copy()

from io import StringIO

s = StringIO()

def print_s(force=True):
Expand All @@ -84,12 +90,12 @@ def print_s(force=True):

# reset s
s = StringIO()

if debug:
print(f"lvl = {lvl}", file=s)
print_s()

if len(nks) > 0:

# calculate the size of the current BZ
dsize = bz._size / bz._diag

Expand All @@ -115,7 +121,9 @@ def print_s(force=True):
# create the single monkhorst pack we will use for replacements
if fast:
new_bz = sisl.MonkhorstPack(bz.parent, nk, size=dsize, trs=False)
new, reps = add_levels(new_bz, nks[:-1], ns[:-1], fast, as_index, debug=debug)
new, reps = add_levels(
new_bz, nks[:-1], ns[:-1], fast, as_index, debug=debug
)

if as_index:
bz.replace(iks, new, displacement=True, as_index=True)
Expand All @@ -137,8 +145,12 @@ def print_s(force=True):

# Recursively add a new level
# create the single monkhorst pack we will use for replacements
new_bz = sisl.MonkhorstPack(bz.parent, nk, size=dsize, trs=False, displacement=k)
new, reps = add_levels(new_bz, nks[:-1], ns[:-1], fast, as_index, debug=debug)
new_bz = sisl.MonkhorstPack(
bz.parent, nk, size=dsize, trs=False, displacement=k
)
new, reps = add_levels(
new_bz, nks[:-1], ns[:-1], fast, as_index, debug=debug
)

# calculate number of replaced k-points
if debug:
Expand All @@ -152,6 +164,7 @@ def print_s(force=True):

if False:
import matplotlib.pyplot as plt

plt.figure()
plt.scatter(bz.k[:, 0], bz.k[:, 1])
plt.title(f"{lvl} and {ik}")
Expand All @@ -166,7 +179,7 @@ def print_s(force=True):
rep_nk = len(new) - (len(bz) - bz_nk)
print("replaced k-points ", rep_nk, file=s)
print_s()
#print(len(bz)*4 * 8 / 1024**3)
# print(len(bz)*4 * 8 / 1024**3)

del new

Expand Down Expand Up @@ -200,6 +213,6 @@ def print_s(force=True):

stat = pstats.Stats(pr)
# We sort against total-time
stat.sort_stats('tottime')
stat.sort_stats("tottime")
# Only print the first 20% of the routines.
stat.print_stats('sisl', 0.2)
stat.print_stats("sisl", 0.2)
6 changes: 3 additions & 3 deletions benchmarks/graphene.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@
gr = sisl.geom.graphene(orthogonal=True).tile(N, 0).tile(N, 1)
H = sisl.Hamiltonian(gr)
pr.enable()
H.construct([(0.1, 1.44), (0., -2.7)], eta=True)
H.construct([(0.1, 1.44), (0.0, -2.7)], eta=True)
H.finalize()
pr.disable()
pr.dump_stats(f"{sys.argv[0]}.profile")


stat = pstats.Stats(pr)
# We sort against total-time
stat.sort_stats('tottime')
stat.sort_stats("tottime")
# Only print the first 20% of the routines.
stat.print_stats('sisl', 0.2)
stat.print_stats("sisl", 0.2)
4 changes: 2 additions & 2 deletions benchmarks/graphene_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@

stat = pstats.Stats(pr)
# We sort against total-time
stat.sort_stats('tottime')
stat.sort_stats("tottime")
# Only print the first 20% of the routines.
stat.print_stats('sisl', 0.2)
stat.print_stats("sisl", 0.2)
6 changes: 3 additions & 3 deletions benchmarks/graphene_repeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

gr = sisl.geom.graphene(orthogonal=True)
H = sisl.Hamiltonian(gr)
H.construct([(0.1, 1.44), (0., -2.7)])
H.construct([(0.1, 1.44), (0.0, -2.7)])
pr.enable()
H.repeat(N, 0).repeat(N, 1)
H.finalize()
Expand All @@ -46,6 +46,6 @@

stat = pstats.Stats(pr)
# We sort against total-time
stat.sort_stats('tottime')
stat.sort_stats("tottime")
# Only print the first 20% of the routines.
stat.print_stats('sisl', 0.2)
stat.print_stats("sisl", 0.2)
6 changes: 3 additions & 3 deletions benchmarks/graphene_tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

gr = sisl.geom.graphene(orthogonal=True)
H = sisl.Hamiltonian(gr)
H.construct([(0.1, 1.44), (0., -2.7)])
H.construct([(0.1, 1.44), (0.0, -2.7)])
pr.enable()
H = H.tile(N, 0).tile(N, 1)
H.finalize()
Expand All @@ -46,6 +46,6 @@

stat = pstats.Stats(pr)
# We sort against total-time
stat.sort_stats('tottime')
stat.sort_stats("tottime")
# Only print the first 20% of the routines.
stat.print_stats('sisl', 0.2)
stat.print_stats("sisl", 0.2)
16 changes: 8 additions & 8 deletions benchmarks/graphene_within.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@

import sisl

method = 'cube'
if 'cube' in sys.argv:
method = 'cube'
sys.argv.remove('cube')
elif 'sphere' in sys.argv:
method = 'sphere'
sys.argv.remove('sphere')
method = "cube"
if "cube" in sys.argv:
method = "cube"
sys.argv.remove("cube")
elif "sphere" in sys.argv:
method = "sphere"
sys.argv.remove("sphere")

if len(sys.argv) > 1:
N = int(sys.argv[1])
Expand All @@ -37,5 +37,5 @@

gr = sisl.geom.graphene(orthogonal=True).tile(N, 0).tile(N, 1)
H = sisl.Hamiltonian(gr)
H.construct([(0.1, 1.44), (0., -2.7)], method=method, eta=True)
H.construct([(0.1, 1.44), (0.0, -2.7)], method=method, eta=True)
H.finalize()
Loading

0 comments on commit 07359d8

Please sign in to comment.