Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to using black for code formatting #171

Merged
merged 1 commit into from
May 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ disable=no-self-use, # disabled as it is too verbose
unnecessary-pass, # allow for methods with just "pass", for clarity
no-else-return, # relax "elif" after a clause with a return
docstring-first-line-empty, # relax docstring style
import-outside-toplevel
import-outside-toplevel,
bad-continuation, bad-whitespace # differences of opinion with black



Expand Down Expand Up @@ -215,7 +216,7 @@ max-nested-blocks=5
[FORMAT]

# Maximum number of characters on a single line.
max-line-length=100
max-line-length=105

# Regexp for a line that is allowed to be longer than the limit.
ignore-long-lines=^\s*(# )?<?https?://\S+>?$
Expand Down
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ please ensure that:
make style
```
from the root of the Nature repository clone for lint and style conformance checks.

If your code fails the local style checks (specifically the black
code formatting check) you can use `make black` to automatically
fix update the code formatting.

For unit testing please see [Testing](#testing) section below.

Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ mypy:
mypy qiskit_nature test tools

style:
pycodestyle qiskit_nature test tools
black --check --exclude="gauopen" qiskit_nature test tools

black:
black --exclude="gauopen" qiskit_nature test tools

test:
python -m unittest discover -v test
Expand Down
4 changes: 2 additions & 2 deletions qiskit_nature/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@
from .exceptions import QiskitNatureError

__all__ = [
'__version__',
'QiskitNatureError',
"__version__",
"QiskitNatureError",
]
47 changes: 29 additions & 18 deletions qiskit_nature/algorithms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,25 +103,36 @@

"""

from .excited_states_solvers import (ExcitedStatesEigensolver, ExcitedStatesSolver, QEOM,
EigensolverFactory, NumPyEigensolverFactory)
from .ground_state_solvers import (AdaptVQE, GroundStateEigensolver, GroundStateSolver,
MinimumEigensolverFactory, NumPyMinimumEigensolverFactory,
VQEUCCFactory, VQEUVCCFactory)
from .excited_states_solvers import (
ExcitedStatesEigensolver,
ExcitedStatesSolver,
QEOM,
EigensolverFactory,
NumPyEigensolverFactory,
)
from .ground_state_solvers import (
AdaptVQE,
GroundStateEigensolver,
GroundStateSolver,
MinimumEigensolverFactory,
NumPyMinimumEigensolverFactory,
VQEUCCFactory,
VQEUVCCFactory,
)
from .pes_samplers import BOPESSampler

__all__ = [
'ExcitedStatesEigensolver',
'ExcitedStatesSolver',
'QEOM',
'EigensolverFactory',
'NumPyEigensolverFactory',
'AdaptVQE',
'GroundStateEigensolver',
'GroundStateSolver',
'MinimumEigensolverFactory',
'NumPyMinimumEigensolverFactory',
'VQEUCCFactory',
'VQEUVCCFactory',
'BOPESSampler',
"ExcitedStatesEigensolver",
"ExcitedStatesSolver",
"QEOM",
"EigensolverFactory",
"NumPyEigensolverFactory",
"AdaptVQE",
"GroundStateEigensolver",
"GroundStateSolver",
"MinimumEigensolverFactory",
"NumPyMinimumEigensolverFactory",
"VQEUCCFactory",
"VQEUVCCFactory",
"BOPESSampler",
]
13 changes: 7 additions & 6 deletions qiskit_nature/algorithms/excited_states_solvers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@
from .eigensolver_factories import EigensolverFactory, NumPyEigensolverFactory
from .excited_states_eigensolver import ExcitedStatesEigensolver

__all__ = ['ExcitedStatesSolver',
'ExcitedStatesEigensolver',
'EigensolverFactory',
'NumPyEigensolverFactory',
'QEOM'
]
__all__ = [
"ExcitedStatesSolver",
"ExcitedStatesEigensolver",
"EigensolverFactory",
"NumPyEigensolverFactory",
"QEOM",
]
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,4 @@
from .eigensolver_factory import EigensolverFactory
from .numpy_eigensolver_factory import NumPyEigensolverFactory

__all__ = ['EigensolverFactory',
'NumPyEigensolverFactory'
]
__all__ = ["EigensolverFactory", "NumPyEigensolverFactory"]
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@
class NumPyEigensolverFactory(EigensolverFactory):
"""A factory to construct a NumPyEigensolver."""

def __init__(self,
filter_criterion: Callable[[Union[List, np.ndarray], float, Optional[List[float]]],
bool] = None,
k: int = 100,
use_default_filter_criterion: bool = False) -> None:
def __init__(
self,
filter_criterion: Callable[
[Union[List, np.ndarray], float, Optional[List[float]]], bool
] = None,
k: int = 100,
use_default_filter_criterion: bool = False,
) -> None:
"""
Args:
filter_criterion: callable that allows to filter eigenvalues/eigenstates. The minimum
Expand All @@ -48,36 +51,39 @@ def __init__(self,
self._use_default_filter_criterion = use_default_filter_criterion

@property
def filter_criterion(self) -> Callable[[Union[List, np.ndarray], float,
Optional[List[float]]], bool]:
""" returns filter criterion """
def filter_criterion(
self,
) -> Callable[[Union[List, np.ndarray], float, Optional[List[float]]], bool]:
"""returns filter criterion"""
return self._filter_criterion

@filter_criterion.setter
def filter_criterion(self, value: Callable[[Union[List, np.ndarray], float,
Optional[List[float]]], bool]) -> None:
""" sets filter criterion """
def filter_criterion(
self,
value: Callable[[Union[List, np.ndarray], float, Optional[List[float]]], bool],
) -> None:
"""sets filter criterion"""
self._filter_criterion = value

@property
def k(self) -> int:
""" returns k (number of eigenvalues requested) """
"""returns k (number of eigenvalues requested)"""
return self._k

@k.setter
def k(self, k: int) -> None:
""" set k (number of eigenvalues requested) """
validate_min('k', k, 1)
"""set k (number of eigenvalues requested)"""
validate_min("k", k, 1)
self._k = k

@property
def use_default_filter_criterion(self) -> bool:
""" returns whether to use the default filter criterion """
"""returns whether to use the default filter criterion"""
return self._use_default_filter_criterion

@use_default_filter_criterion.setter
def use_default_filter_criterion(self, value: bool) -> None:
""" sets whether to use the default filter criterion """
"""sets whether to use the default filter criterion"""
self._use_default_filter_criterion = value

def get_solver(self, problem: BaseProblem) -> Eigensolver:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@
class ExcitedStatesEigensolver(ExcitedStatesSolver):
"""The calculation of excited states via an Eigensolver algorithm"""

def __init__(self, qubit_converter: QubitConverter,
solver: Union[Eigensolver, EigensolverFactory]) -> None:
def __init__(
self,
qubit_converter: QubitConverter,
solver: Union[Eigensolver, EigensolverFactory],
) -> None:
"""

Args:
Expand All @@ -55,9 +58,11 @@ def solver(self, solver: Union[Eigensolver, EigensolverFactory]) -> None:
"""Sets the minimum eigensolver or factory."""
self._solver = solver

def solve(self, problem: BaseProblem,
aux_operators: Optional[List[Union[SecondQuantizedOp, PauliSumOp]]] = None,
) -> EigenstateResult:
def solve(
self,
problem: BaseProblem,
aux_operators: Optional[List[Union[SecondQuantizedOp, PauliSumOp]]] = None,
) -> EigenstateResult:
"""Compute Ground and Excited States properties.

Args:
Expand All @@ -80,7 +85,7 @@ def solve(self, problem: BaseProblem,
main_operator = self._qubit_converter.convert(
second_q_ops[0],
num_particles=problem.num_particles,
sector_locator=problem.symmetry_sector_locator
sector_locator=problem.symmetry_sector_locator,
)
aux_ops = self._qubit_converter.convert_match(second_q_ops[1:])

Expand All @@ -107,6 +112,8 @@ def solve(self, problem: BaseProblem,
eigenstate_result.raw_result = raw_es_result
eigenstate_result.eigenenergies = raw_es_result.eigenvalues
eigenstate_result.eigenstates = raw_es_result.eigenstates
eigenstate_result.aux_operator_eigenvalues = raw_es_result.aux_operator_eigenvalues
eigenstate_result.aux_operator_eigenvalues = (
raw_es_result.aux_operator_eigenvalues
)
result = problem.interpret(eigenstate_result)
return result
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ class ExcitedStatesSolver(ABC):
"""The excited states calculation interface"""

@abstractmethod
def solve(self, problem: BaseProblem,
aux_operators: Optional[List[Union[SecondQuantizedOp, PauliSumOp]]] = None,
) -> EigenstateResult:
def solve(
self,
problem: BaseProblem,
aux_operators: Optional[List[Union[SecondQuantizedOp, PauliSumOp]]] = None,
) -> EigenstateResult:
r"""Compute the excited states energies of the molecule that was supplied via the driver.

Args:
Expand Down
Loading