Skip to content

Commit

Permalink
ruff format
Browse files Browse the repository at this point in the history
  • Loading branch information
mscroggs committed Nov 12, 2024
1 parent 21ddbbc commit cdb1f1c
Show file tree
Hide file tree
Showing 94 changed files with 1,137 additions and 2,985 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,12 @@ jobs:
- run: python3 -m pip install .[style]
name: Install Bempp with optional style dependencies
- run: |
python3 -m flake8 bempp_cl
python3 -m flake8 test
python3 -m flake8 examples
python3 -m ruff check bempp_cl
python3 -m ruff check test
python3 -m ruff check examples
python3 -m ruff format --check bempp_cl
python3 -m ruff format --check test
python3 -m ruff format --check examples
name: Run flake8 checks
- run: python3 -m pydocstyle bempp_cl/api
name: Run pydocstyle checks
Expand Down
12 changes: 0 additions & 12 deletions MANIFEST.in

This file was deleted.

1 change: 1 addition & 0 deletions bempp_cl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
Documentation can be found at https://bempp.com/documentation/index.html
"""

from .version import __version__
23 changes: 5 additions & 18 deletions bempp_cl/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,10 @@ def enable_console_logging(level="info"):
console_handler.setLevel(LOG_LEVEL[level])
if pool.is_worker():
console_handler.setFormatter(
_logging.Formatter(
f"%(name)s:PROC{pool._MY_ID}:%(levelname)s: %(message)s", "%H:%M:%S"
)
_logging.Formatter(f"%(name)s:PROC{pool._MY_ID}:%(levelname)s: %(message)s", "%H:%M:%S")
)
else:
console_handler.setFormatter(
_logging.Formatter(
"%(name)s:HOST:%(levelname)s: %(message)s", "%H:%M:%S"
)
)
console_handler.setFormatter(_logging.Formatter("%(name)s:HOST:%(levelname)s: %(message)s", "%H:%M:%S"))
LOGGER.addHandler(console_handler)
CONSOLE_LOGGING_HANDLER = console_handler
return CONSOLE_LOGGING_HANDLER
Expand Down Expand Up @@ -195,9 +189,7 @@ def __exit__(self, *args):

LOGGER = _init_logger()

BEMPP_PATH = _os.path.abspath(
_os.path.join(_os.path.dirname(_os.path.realpath(__file__)), "..")
)
BEMPP_PATH = _os.path.abspath(_os.path.join(_os.path.dirname(_os.path.realpath(__file__)), ".."))

# pylint: disable=W0702
# try:
Expand All @@ -222,10 +214,7 @@ def _gmsh_path():
else:
gmp = which("gmsh")
if gmp is None:
print(
"Could not find Gmsh."
+ "Interactive plotting and shapes module not available."
)
print("Could not find Gmsh." + "Interactive plotting and shapes module not available.")
return gmp


Expand Down Expand Up @@ -290,9 +279,7 @@ def _get_version():
DEFAULT_DEVICE_INTERFACE = "numba"

if DEFAULT_DEVICE_INTERFACE == "numba":
log(
"Numba backend activated. For full performance the OpenCL backend with an OpenCL CPU driver is required."
)
log("Numba backend activated. For full performance the OpenCL backend with an OpenCL CPU driver is required.")

DEFAULT_PRECISION = "double"
VECTORIZATION_MODE = "auto"
Expand Down
28 changes: 7 additions & 21 deletions bempp_cl/api/assembly/assembler.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
"""Various assemblers to discretize boundary operators."""


def _create_assembler(
domain, dual_to_range, identifier, parameters, device_interface=None
):
def _create_assembler(domain, dual_to_range, identifier, parameters, device_interface=None):
"""Create assembler based on string."""
from bempp_cl.core.singular_assembler import SingularAssembler
from bempp_cl.core.dense_assembler import DenseAssembler
Expand Down Expand Up @@ -31,9 +29,7 @@ def _create_assembler(
return SparseAssembler(domain, dual_to_range, parameters)
if identifier == "fmm":
if not check_for_fmm():
raise ValueError(
"No compatible FMM library found. Please install Exafmm from github.com/exafmm/exafmm-t."
)
raise ValueError("No compatible FMM library found. Please install Exafmm from github.com/exafmm/exafmm-t.")
return FmmAssembler(domain, dual_to_range, parameters)
else:
raise ValueError("Unknown assembler type.")
Expand Down Expand Up @@ -160,18 +156,14 @@ def evaluate(self, x):

if not self._is_complex:
if np.iscomplexobj(x):
return self._implementation.evaluate(
np.real(x)
) + 1j * self._implementation.evaluate(np.imag(x))
return self._implementation.evaluate(np.real(x)) + 1j * self._implementation.evaluate(np.imag(x))
else:
return self._implementation.evaluate(x)
else:
return self._implementation.evaluate(x)


def select_potential_implementation(
space, points, operator_descriptor, device_interface, assembler, parameters
):
def select_potential_implementation(space, points, operator_descriptor, device_interface, assembler, parameters):
"""Select a potential operator implementation."""
import bempp_cl.api

Expand All @@ -182,19 +174,13 @@ def select_potential_implementation(
if assembler == "dense":
from bempp_cl.core.dense_potential_assembler import DensePotentialAssembler

return DensePotentialAssembler(
space, operator_descriptor, points, device_interface, parameters
)
return DensePotentialAssembler(space, operator_descriptor, points, device_interface, parameters)
elif assembler == "fmm":
from bempp_cl.api.fmm.fmm_assembler import FmmPotentialAssembler

if not bempp_cl.api.check_for_fmm():
raise ValueError(
"No compatible FMM library found. Please install Exafmm from github.com/exafmm/exafmm-t."
)
raise ValueError("No compatible FMM library found. Please install Exafmm from github.com/exafmm/exafmm-t.")

return FmmPotentialAssembler(
space, operator_descriptor, points, device_interface, parameters
)
return FmmPotentialAssembler(space, operator_descriptor, points, device_interface, parameters)
else:
raise ValueError(f"Unknown potential assembler: {assembler}")
68 changes: 18 additions & 50 deletions bempp_cl/api/assembly/blocked_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def strong_form(self):
from bempp_cl.api.utils.helpers import get_inverse_mass_matrix

if self._range_map is None:

nrows = len(self.range_spaces)

_range_ops = _np.empty((nrows, nrows), dtype="O")
Expand Down Expand Up @@ -121,17 +120,13 @@ def __mul__(self, other):
)
for item in list_input:
if not isinstance(item, GridFunction):
raise ValueError(
"All items in the input list must be grid functions."
)
raise ValueError("All items in the input list must be grid functions.")
weak_op = self.weak_form()
x_in = coefficients_from_grid_functions_list(list_input)
res = weak_op * x_in

# Now assemble the output grid functions back together.
output_list = grid_function_list_from_projections(
res, self.range_spaces, self.dual_to_range_spaces
)
output_list = grid_function_list_from_projections(res, self.range_spaces, self.dual_to_range_spaces)
return output_list

else:
Expand Down Expand Up @@ -186,24 +181,17 @@ def __setitem__(self, key, operator):

if self.range_spaces[row] is not None:
if operator.range != self.range_spaces[row]:
raise ValueError(
"Range space not compatible with "
+ "self.range_spaces[{0}]".format(row)
)
raise ValueError("Range space not compatible with " + "self.range_spaces[{0}]".format(row))

if self.dual_to_range_spaces[row] is not None:
if operator.dual_to_range != self.dual_to_range_spaces[row]:
raise ValueError(
"Dual to range space not compatible with "
+ "self.dual_to_range_spaces[{0}]".format(row)
"Dual to range space not compatible with " + "self.dual_to_range_spaces[{0}]".format(row)
)

if self.domain_spaces[col] is not None:
if operator.domain != self.domain_spaces[col]:
raise ValueError(
"Domain space not compatible with "
+ "self.domain_spaces[{0}]".format(col)
)
raise ValueError("Domain space not compatible with " + "self.domain_spaces[{0}]".format(col))

self._range_spaces[row] = operator.range
self._dual_to_range_spaces[row] = operator.dual_to_range
Expand Down Expand Up @@ -295,9 +283,7 @@ def make_blocked(operator):
elif isinstance(elem, BlockedOperatorBase):
current_row.append(elem)
else:
raise ValueError(
"Cannot process element of type: {0}".format(type(elem))
)
raise ValueError("Cannot process element of type: {0}".format(type(elem)))
self._ops.append(current_row)

all_domain_spaces = []
Expand Down Expand Up @@ -415,7 +401,6 @@ def __init__(self, op1, op2):
super().__init__()

def _assemble(self):

return self._op1.weak_form() + self._op2.weak_form()

@property
Expand Down Expand Up @@ -448,7 +433,6 @@ def __init__(self, op1, op2):
super().__init__()

def _assemble(self):

return self._op1.weak_form() * self._op2.strong_form()

@property
Expand Down Expand Up @@ -602,19 +586,13 @@ def __init__(self, ops):
continue
if self._rows[i] != -1:
if ops[i, j].shape[0] != self._rows[i]:
raise ValueError(
"Block row {0} has incompatible ".format(i)
+ " operator sizes."
)
raise ValueError("Block row {0} has incompatible ".format(i) + " operator sizes.")
else:
self._rows[i] = ops[i, j].shape[0]

if self._cols[j] != -1:
if ops[i, j].shape[1] != self._cols[j]:
raise ValueError(
"Block column {0} has incompatible".format(j)
+ "operator sizes."
)
raise ValueError("Block column {0} has incompatible".format(j) + "operator sizes.")
else:
self._cols[j] = ops[i, j].shape[1]
self._operators[i, j] = ops[i, j]
Expand All @@ -625,9 +603,7 @@ def __init__(self, ops):
for i in range(rows):
for j in range(cols):
if self._operators[i, j] is None:
self._operators[i, j] = ZeroDiscreteBoundaryOperator(
self._rows[i], self._cols[j]
)
self._operators[i, j] = ZeroDiscreteBoundaryOperator(self._rows[i], self._cols[j])

shape = (_np.sum(self._rows), _np.sum(self._cols))

Expand Down Expand Up @@ -666,9 +642,9 @@ def _matvec(self, x):
local_x = x[col_dim : col_dim + self._cols[j]]
op_is_complex = _np.iscomplexobj(self._operators[i, j].dtype.type(1))
if _np.iscomplexobj(x) and not op_is_complex:
local_res += self._operators[i, j].dot(
_np.real(local_x)
) + 1j * self._operators[i, j].dot(_np.imag(local_x))
local_res += self._operators[i, j].dot(_np.real(local_x)) + 1j * self._operators[i, j].dot(
_np.imag(local_x)
)
else:
local_res += self._operators[i, j].dot(local_x)
col_dim += self._cols[j]
Expand All @@ -683,9 +659,7 @@ def _matmat(self, x):
raise ValueError("Not all rows or columns contain operators.")

row_dim = 0
res = _np.zeros(
(self.shape[0], x.shape[1]), dtype=combined_type(self.dtype, x.dtype)
)
res = _np.zeros((self.shape[0], x.shape[1]), dtype=combined_type(self.dtype, x.dtype))

for i in range(self._ndims[0]):
col_dim = 0
Expand All @@ -694,9 +668,9 @@ def _matmat(self, x):
local_x = x[col_dim : col_dim + self._cols[j], :]
op_is_complex = _np.iscomplexobj(self._operators[i, j].dtype.type(1))
if _np.iscomplexobj(x) and not op_is_complex:
local_res[:] += self._operators[i, j].dot(
_np.real(local_x)
) + 1j * self._operators[i, j].dot(_np.imag(local_x))
local_res[:] += self._operators[i, j].dot(_np.real(local_x)) + 1j * self._operators[i, j].dot(
_np.imag(local_x)
)
else:
local_res[:] += self._operators[i, j].dot(local_x)
col_dim += self._cols[j]
Expand Down Expand Up @@ -810,9 +784,7 @@ def grid_function_list_from_coefficients(coefficients, spaces):
res_list = []
for space in spaces:
dof_count = space.global_dof_count
res_list.append(
GridFunction(space, coefficients=coefficients[pos : pos + dof_count])
)
res_list.append(GridFunction(space, coefficients=coefficients[pos : pos + dof_count]))
pos += dof_count
return res_list

Expand Down Expand Up @@ -842,10 +814,6 @@ def grid_function_list_from_projections(projections, spaces, dual_spaces=None):
raise ValueError("spaces must have the same length as dual_spaces")
for space, dual in zip(spaces, dual_spaces):
dof_count = space.global_dof_count
res_list.append(
GridFunction(
space, projections=projections[pos : pos + dof_count], dual_space=dual
)
)
res_list.append(GridFunction(space, projections=projections[pos : pos + dof_count], dual_space=dual))
pos += dof_count
return res_list
Loading

0 comments on commit cdb1f1c

Please sign in to comment.