Skip to content

Commit

Permalink
pre-commit fix
Browse files Browse the repository at this point in the history
  • Loading branch information
unkcpz committed Mar 12, 2022
1 parent 0bf6853 commit 4a2c400
Show file tree
Hide file tree
Showing 21 changed files with 580 additions and 510 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
# Run basic tests for this app on the latest aiidalab-docker image.

name: continuous-integration

on: [push, pull_request]

jobs:

pre-commit:
# Adapted from: https://github.com/CasperWA/voila-optimade-client

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: 3.8

- name: Install dependencies
run: |
python -m pip install pre-commit==2.11.1
- name: Run pre-commit
run: pre-commit run --all-files || ( git status --short ; git diff ; exit 1 )
23 changes: 23 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
name: Release

on:
push:
tags:
- v*
branches:
- release/*

jobs:

publish:

runs-on: ubuntu-latest

steps:

- uses: softprops/action-gh-release@v0.1.14
name: Create release
if: startsWith(github.ref, 'refs/tags/v')
with:
generate_release_notes: true
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
build

.vscode
pseduos_json_demo/*
pseduos_json_demo/*
63 changes: 43 additions & 20 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,45 @@
# Install pre-commit hooks via:
# pre-commit install

# yapf = yet another python formatter
---
repos:
- repo: https://github.com/pre-commit/mirrors-yapf
rev: v0.30.0
hooks:
- id: yapf
name: yapf
args: ["-i"]

- repo: https://github.com/PyCQA/pylint
rev: pylint-2.6.0
hooks:
- id: pylint
language: system
exclude: &exclude_files >
(?x)^(
start.py|
tests/.*(?<!\.py)$
)$
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
- id: check-json
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
rev: 0.1.0
hooks:
- id: yamlfmt

- repo: https://github.com/psf/black
rev: 22.1.0
hooks:
- id: black
language_version: python3 # Should be a command that runs python3.6+

- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
hooks:
- id: flake8
args: [--count, --show-source, --statistics]
additional_dependencies:
- flake8-bugbear==21.3.1

- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
args: [--profile, black, --filter-files]

- repo: https://github.com/asottile/setup-cfg-fmt
rev: v1.20.0
hooks:
- id: setup-cfg-fmt

- repo: https://github.com/sirosen/check-jsonschema
rev: 0.14.0
hooks:
- id: check-github-workflows
23 changes: 0 additions & 23 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ MIT

## Contact

📧 email: jusong.yu@epfl.ch
📧 email: jusong.yu@epfl.ch
7 changes: 0 additions & 7 deletions __init__.py

This file was deleted.

132 changes: 76 additions & 56 deletions aiidalab_sssp/plot.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,55 @@
import numpy as np
import matplotlib.pyplot as plt
import numpy as np


def delta_measure_hist(pseudos: dict, measure_type):

px = 1/plt.rcParams['figure.dpi'] # pixel in inches
fig, ax = plt.subplots(1, 1, figsize=(1024*px, 360*px))
cmap = plt.get_cmap('tab20')
px = 1 / plt.rcParams["figure.dpi"] # pixel in inches
fig, ax = plt.subplots(1, 1, figsize=(1024 * px, 360 * px))
cmap = plt.get_cmap("tab20")
NUM_COLOR = 20
structures = ['X', 'XO', 'X2O', 'XO3', 'X2O', 'X2O3', 'X2O5']
structures = ["X", "XO", "X2O", "XO3", "X2O", "X2O3", "X2O5"]
num_structures = len(structures)

# element
try:
v0 = list(pseudos.values())[0]
element = v0['pseudo_info']['element']
except:
element = v0["pseudo_info"]["element"]
except Exception:
element = None

if measure_type == 'delta':
keyname = 'delta'
ylabel = 'Δ -factor'
elif measure_type == 'nv_delta':
keyname = 'rel_errors_vec_length'
ylabel = 'νΔ -factor'
if measure_type == "delta":
keyname = "delta"
ylabel = "Δ -factor"
elif measure_type == "nv_delta":
keyname = "rel_errors_vec_length"
ylabel = "νΔ -factor"

for i, (label, output) in enumerate(pseudos.items()):
N = len(structures)
idx = np.arange(N) # the x locations for the groups
width = 0.1 # the width of the bars
idx = np.arange(N) # the x locations for the groups
width = 0.1 # the width of the bars

y_delta = []
for structure in structures:
try:
res = output['delta_factor']['output_delta_analyze'][f'output_{structure}']
res = output["delta_factor"]["output_delta_analyze"][
f"output_{structure}"
]
y_delta.append(res[keyname])
except:
except Exception:
y_delta.append(-1)

_, pp_family, pp_z, pp_type, pp_version = label.split('/')
out_label = f'{pp_z}/{pp_type}({pp_family}-{pp_version})'
_, pp_family, pp_z, pp_type, pp_version = label.split("/")
out_label = f"{pp_z}/{pp_type}({pp_family}-{pp_version})"

ax.bar(idx+width*i, y_delta, width, color=cmap(i/NUM_COLOR), label=out_label)
ax.bar(
idx + width * i, y_delta, width, color=cmap(i / NUM_COLOR), label=out_label
)
ax.legend()
ax.set_title(f'X={element}')
ax.axhline(y=1.0, linestyle='--', color='gray')
ax.set_title(f"X={element}")

ax.axhline(y=1.0, linestyle="--", color="gray")
ax.set_ylabel(ylabel)
ax.set_ylim([0, 10])
ax.set_yticks(np.arange(10))
Expand All @@ -53,64 +58,79 @@ def delta_measure_hist(pseudos: dict, measure_type):

return fig


def convergence(pseudos: dict, wf_name, measure_name, ylabel, threshold=None):

px = 1/plt.rcParams['figure.dpi']
fig, (ax1, ax2) = plt.subplots(1, 2, gridspec_kw={'width_ratios': [2, 1]}, figsize=(1024*px, 360*px))
cmap = plt.get_cmap('tab20')

px = 1 / plt.rcParams["figure.dpi"]
fig, (ax1, ax2) = plt.subplots(
1, 2, gridspec_kw={"width_ratios": [2, 1]}, figsize=(1024 * px, 360 * px)
)
cmap = plt.get_cmap("tab20")
NUM_COLOR = 20


for i, (label, output) in enumerate(pseudos.items()):
# Calculate the avg delta measure value
structures = ['X', 'XO', 'X2O', 'XO3', 'X2O', 'X2O3', 'X2O5']
structures = ["X", "XO", "X2O", "XO3", "X2O", "X2O3", "X2O5"]
lst = []
for structure in structures:
try:
res = output['delta_factor']['output_delta_analyze'][f'output_{structure}']
lst.append(res['rel_errors_vec_length'])
except:
res = output["delta_factor"]["output_delta_analyze"][
f"output_{structure}"
]
lst.append(res["rel_errors_vec_length"])
except Exception:
pass

avg_delta = sum(lst) / len(lst)


try:
res = output[wf_name]
x_wfc = res['output_parameters_wfc_test']['ecutwfc']
y_wfc = res['output_parameters_wfc_test'][measure_name]

x_rho = res['output_parameters_rho_test']['ecutrho']
y_rho = res['output_parameters_rho_test'][measure_name]

wfc_cutoff = res['final_output_parameters']['wfc_cutoff']

_, pp_family, pp_z, pp_type, pp_version = label.split('/')
out_label = f'{pp_z}/{pp_type}(νΔ={avg_delta:.2f})({pp_family}-{pp_version})'

ax1.plot(x_wfc, y_wfc, marker='o', color=cmap(i/NUM_COLOR), label=out_label)
ax2.plot(x_rho, y_rho, marker='o', color=cmap(i/NUM_COLOR), label=f'cutoff wfc = {wfc_cutoff} Ry')
except:
x_wfc = res["output_parameters_wfc_test"]["ecutwfc"]
y_wfc = res["output_parameters_wfc_test"][measure_name]

x_rho = res["output_parameters_rho_test"]["ecutrho"]
y_rho = res["output_parameters_rho_test"][measure_name]

wfc_cutoff = res["final_output_parameters"]["wfc_cutoff"]

_, pp_family, pp_z, pp_type, pp_version = label.split("/")
out_label = (
f"{pp_z}/{pp_type}(νΔ={avg_delta:.2f})({pp_family}-{pp_version})"
)

ax1.plot(
x_wfc, y_wfc, marker="o", color=cmap(i / NUM_COLOR), label=out_label
)
ax2.plot(
x_rho,
y_rho,
marker="o",
color=cmap(i / NUM_COLOR),
label=f"cutoff wfc = {wfc_cutoff} Ry",
)
except Exception:
pass

ax1.set_ylabel(ylabel)
ax1.set_xlabel('Wavefuntion cutoff (Ry)')
ax1.set_title('Fixed rho cutoff at 200 * dual (dual=4 for NC and dual=8 for non-NC)')
ax1.set_xlabel("Wavefuntion cutoff (Ry)")
ax1.set_title(
"Fixed rho cutoff at 200 * dual (dual=4 for NC and dual=8 for non-NC)"
)

# ax2.legend(loc='upper left', bbox_to_anchor=(1, 1.0))
ax1.legend()

ax2.set_xlabel('Charge density cudoff (Ry)')
ax2.set_title('Convergence test at fixed wavefunction cutoff')
ax2.set_xlabel("Charge density cudoff (Ry)")
ax2.set_title("Convergence test at fixed wavefunction cutoff")
ax2.legend()

if threshold:
ax1.axhline(y=threshold, color='r', linestyle='--')
ax2.axhline(y=threshold, color='r', linestyle='--')
ax1.axhline(y=threshold, color="r", linestyle="--")
ax2.axhline(y=threshold, color="r", linestyle="--")

ax1.set_ylim(-0.5 * threshold, 10*threshold)
ax2.set_ylim(-0.5 * threshold, 10*threshold)
ax1.set_ylim(-0.5 * threshold, 10 * threshold)
ax2.set_ylim(-0.5 * threshold, 10 * threshold)

plt.tight_layout()

return fig
return fig
7 changes: 4 additions & 3 deletions aiidalab_sssp/setup_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from pathlib import Path
from shutil import which
from subprocess import CalledProcessError, run
from threading import Thread, Event
from threading import Event, Thread
from time import time
import ipywidgets as ipw

import ipywidgets as ipw
import traitlets
from aiida.common.exceptions import NotExistent
from aiida.orm import load_code
Expand Down Expand Up @@ -295,6 +295,7 @@ def _trigger_reinstall(self, _=None):
FN_DO_NOT_SETUP.unlink()
self.refresh()


class ProgressBar(ipw.HBox):
class AnimationRate(float):
pass
Expand Down Expand Up @@ -371,4 +372,4 @@ def _observe_value(self, change):
self._animation_rate = change["new"]
else:
self._animation_rate = 0
self._progress_bar.value = change["new"]
self._progress_bar.value = change["new"]
Loading

0 comments on commit 4a2c400

Please sign in to comment.