Skip to content

Commit

Permalink
Remove aiida tools dependency (#54)
Browse files Browse the repository at this point in the history
* Remove dependency on `aiida-tools`, vendoring the code instead
* Update pre-commit hooks:
  * Switch to `black` for formatting
  * Add `isort`
  * Move `mypy` to run in main environment

Add some type hints and a sprinkle of `# type: ignore` to make the updated mypy version happy.
  • Loading branch information
greschd committed Jul 7, 2022
1 parent 4c7bc76 commit 9abbef4
Show file tree
Hide file tree
Showing 44 changed files with 885 additions and 807 deletions.
38 changes: 20 additions & 18 deletions .github/system_tests/test_daemon.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
"""Tests to run with a running daemon."""
import operator
import subprocess
import sys
import operator
import time
import numpy as np

from aiida import orm
from aiida.engine.daemon.client import get_daemon_client
from aiida.engine import launch
from aiida.common import exceptions
from aiida.engine import launch
from aiida.engine.daemon.client import get_daemon_client
import numpy as np

from aiida_optimize.engines import Bisection
from aiida_optimize import OptimizationWorkChain
from aiida_optimize.engines import Bisection
import sample_processes

TIMEOUTSECS = 4 * 60 # 4 minutes
Expand All @@ -24,12 +24,14 @@ def print_daemon_log():

print(f"Output of 'cat {daemon_log}':")
try:
print(subprocess.check_output(
['cat', f'{daemon_log}'],
stderr=subprocess.STDOUT,
))
print(
subprocess.check_output(
["cat", f"{daemon_log}"],
stderr=subprocess.STDOUT,
)
)
except subprocess.CalledProcessError as exception:
print(f'Note: the command failed, message: {exception}')
print(f"Note: the command failed, message: {exception}")


def wait_for(proc, time_elapsed=5):
Expand All @@ -46,8 +48,8 @@ def check_optimization(
x_exact,
f_exact,
evaluate=None,
input_getter=operator.attrgetter('x'),
output_port_names=None
input_getter=operator.attrgetter("x"),
output_port_names=None,
): # pylint: disable=too-many-arguments
"""submit launch and check optimization"""
func_workchain = getattr(sample_processes, func_workchain_name)
Expand All @@ -63,7 +65,7 @@ def check_optimization(

wait_for(result_node)

assert 'optimal_process_uuid' in result_node.outputs
assert "optimal_process_uuid" in result_node.outputs
assert np.isclose(result_node.outputs.optimal_process_output.value, f_exact, atol=ftol)

calc = orm.load_node(result_node.outputs.optimal_process_uuid.value)
Expand Down Expand Up @@ -99,14 +101,14 @@ def launch_all():
engine=Bisection,
engine_kwargs=dict(
lower=-1.1,
upper=1.,
upper=1.0,
tol=tol,
),
func_workchain_name='Echo',
func_workchain_name="Echo",
xtol=tol,
ftol=tol,
x_exact=0.,
f_exact=0.,
x_exact=0.0,
f_exact=0.0,
)


Expand All @@ -119,5 +121,5 @@ def main():
sys.exit(0)


if __name__ == '__main__':
if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
dist
.vscode
.mypy_cache
build
25 changes: 15 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
repos:

- repo: https://github.com/pre-commit/mirrors-yapf
rev: v0.30.0
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: yapf
language: system

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.780
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: mypy
exclude: '^(doc/)|(examples/)'
- id: isort

- repo: https://github.com/PyCQA/pylint
rev: pylint-2.5.0
rev: v2.14.4
hooks:
- id: pylint
language: system
Expand All @@ -33,3 +30,11 @@ repos:
aiida_optimize/__init__.py
)$
pass_filenames: false

- id: mypy
name: mypy
entry: mypy
language: python
types: [python]
require_serial: true
files: '^(aiida_optimize/)'
38 changes: 1 addition & 37 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ confidence=
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use"--disable=all --enable=classes
# --disable=W"
disable=too-few-public-methods,too-many-public-methods,bad-continuation,wrong-import-position,line-too-long,locally-disabled,wildcard-import,locally-enabled,too-many-instance-attributes,fixme,len-as-condition,useless-object-inheritance,wrong-import-order
disable=too-few-public-methods,too-many-public-methods,bad-continuation,wrong-import-position,line-too-long,wildcard-import,too-many-instance-attributes,fixme,len-as-condition,useless-object-inheritance,wrong-import-order,duplicate-code

# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
Expand Down Expand Up @@ -92,46 +92,28 @@ max-nested-blocks=5

[BASIC]

# Naming hint for argument names
argument-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$

# Regular expression matching correct argument names
argument-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$

# Naming hint for attribute names
attr-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$

# Regular expression matching correct attribute names
attr-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$

# Bad variable names which should always be refused, separated by a comma
bad-names=foo,bar,baz,toto,tutu,tata

# Naming hint for class attribute names
class-attribute-name-hint=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$

# Regular expression matching correct class attribute names
class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$

# Naming hint for class names
class-name-hint=[A-Z_][a-zA-Z0-9]+$

# Regular expression matching correct class names
class-rgx=[A-Z_][a-zA-Z0-9]+$

# Naming hint for constant names
const-name-hint=(([A-Z_][A-Z0-9_]*)|(__.*__))$

# Regular expression matching correct constant names
const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$

# Minimum line length for functions/classes that require docstrings, shorter
# ones are exempt.
docstring-min-length=5

# Naming hint for function names
function-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$

# Regular expression matching correct function names
function-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$

Expand All @@ -141,21 +123,12 @@ good-names=i,j,k,ex,Run,_, _INPUT_FILE_NAME, _OUTPUT_FILE_NAME,t,x,y,z,f,Paramet
# Include a hint for the correct naming format with invalid-name
include-naming-hint=no

# Naming hint for inline iteration names
inlinevar-name-hint=[A-Za-z_][A-Za-z0-9_]*$

# Regular expression matching correct inline iteration names
inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$

# Naming hint for method names
method-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$

# Regular expression matching correct method names
method-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*)|(setUp)|(tearDown))$

# Naming hint for module names
module-name-hint=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$

# Regular expression matching correct module names
module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$

Expand All @@ -171,9 +144,6 @@ no-docstring-rgx=^[_,setUp,tearDown]
# to this list to register other decorators that produce valid properties.
property-classes=abc.abstractproperty

# Naming hint for variable names
variable-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$

# Regular expression matching correct variable names
variable-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$

Expand All @@ -199,12 +169,6 @@ max-line-length=140
# Maximum number of lines in a module
max-module-lines=1000

# List of optional constructs for which whitespace checking is disabled. `dict-
# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}.
# `trailing-comma` allows a space between comma and closing bracket: (a, ).
# `empty-line` allows space-only lines.
no-space-check=trailing-comma,dict-separator

# Allow the body of a class to be on the same line as the declaration if body
# contains single statement.
single-line-class-stmt=no
Expand Down
8 changes: 3 additions & 5 deletions aiida_optimize/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
engines and wrappers for .
"""

__version__ = "1.0.0"
__version__ = "1.0.1"

from . import engines, helpers, process_inputs, wrappers
from ._optimization_workchain import OptimizationWorkChain
from . import helpers
from . import engines
from . import wrappers

__all__ = ["OptimizationWorkChain", "helpers", "engines", "wrappers"]
__all__ = ["OptimizationWorkChain", "helpers", "engines", "wrappers", "process_inputs"]

0 comments on commit 9abbef4

Please sign in to comment.