Skip to content
Open
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
19 changes: 3 additions & 16 deletions .ci/azure/style.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
jobs:
- job:
displayName: Run style checks with Black
displayName: Run style checks with ruff
pool:
vmImage: ubuntu-latest
steps:
Expand All @@ -9,18 +9,5 @@ jobs:
versionSpec: "3.11"
- bash: .ci/install_style.sh
displayName: "Install dependencies to run the checks"
- script: black --check .
displayName: "Run black"

- job:
displayName: Run (permissive) style checks with flake8
pool:
vmImage: ubuntu-latest
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: "3.11"
- bash: .ci/install_style.sh
displayName: "Install dependencies to run the checks"
- script: flake8
displayName: "Run flake8"
- script: ruff check .
displayName: "Run ruff"
11 changes: 11 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Ruff
on: [ push, pull_request ]
jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: astral-sh/ruff-action@v3
with:
version: "0.14.0"
checksum: "28fe06f700caf99eee235f90e6e349f48b7f9a4b0d42e3ee5b3686f9259649a3"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,5 @@ discretize/version.py
.idea/

docs/sg_execution_times.rst

.vscode/
26 changes: 9 additions & 17 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
repos:
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.3.0
hooks:
- id: black
language_version: python3.11
- repo: https://github.com/pycqa/flake8
rev: 7.0.0
hooks:
- id: flake8
language_version: python3.11
additional_dependencies:
- flake8-bugbear==23.12.2
- flake8-builtins==2.2.0
- flake8-mutable==1.2.0
- flake8-rst-docstrings==0.3.0
- flake8-docstrings==1.7.0
- flake8-pyproject==1.2.3
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.14.0
hooks:
# Run the linter.
- id: ruff-check
args: [ --fix ]
# Run the formatter.
- id: ruff-format
8 changes: 4 additions & 4 deletions discretize/base/base_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -2796,7 +2796,7 @@ def get_face_inner_product_surface_deriv(
elif invert_model:
dMdprop = A * sdiag(-1.0 / model**2)
elif invert_matrix:
dMdprop = sdiag(-MI.diagonal() ** 2) * A
dMdprop = sdiag(-(MI.diagonal() ** 2)) * A

elif tensorType == 1: # isotropic, variable in space
if not invert_matrix and not invert_model:
Expand All @@ -2806,7 +2806,7 @@ def get_face_inner_product_surface_deriv(
elif invert_model:
dMdprop = A * sdiag(-1.0 / model**2)
elif invert_matrix:
dMdprop = sdiag(-MI.diagonal() ** 2) * A
dMdprop = sdiag(-(MI.diagonal() ** 2)) * A

if dMdprop is not None:

Expand Down Expand Up @@ -2901,7 +2901,7 @@ def get_edge_inner_product_line_deriv(
elif invert_model:
dMdprop = L * sdiag(-1.0 / model**2)
elif invert_matrix:
dMdprop = sdiag(-MI.diagonal() ** 2) * L
dMdprop = sdiag(-(MI.diagonal() ** 2)) * L

elif tensorType == 1: # isotropic, variable in space
if not invert_matrix and not invert_model:
Expand All @@ -2911,7 +2911,7 @@ def get_edge_inner_product_line_deriv(
elif invert_model:
dMdprop = L * sdiag(-1.0 / model**2)
elif invert_matrix:
dMdprop = sdiag(-MI.diagonal() ** 2) * L
dMdprop = sdiag(-(MI.diagonal() ** 2)) * L

if dMdprop is not None:

Expand Down
5 changes: 3 additions & 2 deletions discretize/base/base_regular_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -955,8 +955,9 @@ def switchKernal(xx):
if dimName in out_type:
if self.dim <= dim:
raise ValueError(
"Dimensions of mesh not great enough for "
"{}_{}".format(x_type, dimName)
"Dimensions of mesh not great enough for {}_{}".format(
x_type, dimName
)
)
if xx.size != np.sum(nn):
raise ValueError("Vector is not the right size.")
Expand Down
6 changes: 3 additions & 3 deletions discretize/base/base_tensor_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ def _fastInnerProductDeriv(
elif invert_model:
dMdprop = n_elements * Av.T * V * sdiag(-1.0 / model**2)
elif invert_matrix:
dMdprop = n_elements * (sdiag(-MI.diagonal() ** 2) * Av.T * V)
dMdprop = n_elements * (sdiag(-(MI.diagonal() ** 2)) * Av.T * V)

elif tensorType == 1: # isotropic, variable in space
Av = getattr(self, "ave" + projection_type + "2CC")
Expand All @@ -938,7 +938,7 @@ def _fastInnerProductDeriv(
elif invert_model:
dMdprop = n_elements * Av.T * V * sdiag(-1.0 / model**2)
elif invert_matrix:
dMdprop = n_elements * (sdiag(-MI.diagonal() ** 2) * Av.T * V)
dMdprop = n_elements * (sdiag(-(MI.diagonal() ** 2)) * Av.T * V)

elif tensorType == 2: # anisotropic
Av = getattr(self, "ave" + projection_type + "2CCV")
Expand Down Expand Up @@ -967,7 +967,7 @@ def _fastInnerProductDeriv(
elif invert_model:
dMdprop = Av.T * P * V * sdiag(-1.0 / model**2)
elif invert_matrix:
dMdprop = sdiag(-MI.diagonal() ** 2) * Av.T * P * V
dMdprop = sdiag(-(MI.diagonal() ** 2)) * Av.T * P * V

if dMdprop is not None:

Expand Down
4 changes: 1 addition & 3 deletions discretize/mixins/mesh_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,7 @@ def _readModelUBC_2D(mesh, file_name):
if not len(model) == mesh.nC:
raise Exception(
"""Something is not right, expected size is {:d}
but unwrap vector is size {:d}""".format(
mesh.nC, len(model)
)
but unwrap vector is size {:d}""".format(mesh.nC, len(model))
)

return model.reshape(mesh.vnC, order="F")[:, ::-1].reshape(-1, order="F")
Expand Down
4 changes: 2 additions & 2 deletions discretize/operators/differential_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2318,7 +2318,7 @@ def get_BC_projections(self, BC, discretization="CC"):
"""
if discretization != "CC":
raise NotImplementedError(
"Boundary conditions only implemented" "for CC discretization."
"Boundary conditions only implemented for CC discretization."
)

if isinstance(BC, str):
Expand Down Expand Up @@ -2411,7 +2411,7 @@ def get_BC_projections_simple(self, discretization="CC"):
"""Create weak form boundary condition projection matrices for mixed boundary condition."""
if discretization != "CC":
raise NotImplementedError(
"Boundary conditions only implemented" "for CC discretization."
"Boundary conditions only implemented for CC discretization."
)

def projBC(n):
Expand Down
22 changes: 17 additions & 5 deletions discretize/operators/inner_products.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ def get_edge_inner_product_surface_deriv( # NOQA D102
elif invert_model:
dMdprop = n_elements * Av.T * A * sdiag(-1.0 / model**2)
elif invert_matrix:
dMdprop = n_elements * (sdiag(-MI.diagonal() ** 2) * Av.T * A)
dMdprop = n_elements * (sdiag(-(MI.diagonal() ** 2)) * Av.T * A)

elif tensorType == 1: # isotropic, variable in space
if not invert_matrix and not invert_model:
Expand All @@ -391,7 +391,7 @@ def get_edge_inner_product_surface_deriv( # NOQA D102
elif invert_model:
dMdprop = n_elements * Av.T * A * sdiag(-1.0 / model**2)
elif invert_matrix:
dMdprop = n_elements * (sdiag(-MI.diagonal() ** 2) * Av.T * A)
dMdprop = n_elements * (sdiag(-(MI.diagonal() ** 2)) * Av.T * A)

if dMdprop is not None:

Expand Down Expand Up @@ -819,17 +819,29 @@ def Pxxx(xEdge, yEdge, zEdge):
posX = (
[0, 0]
if xEdge == "eX0"
else [1, 0] if xEdge == "eX1" else [0, 1] if xEdge == "eX2" else [1, 1]
else [1, 0]
if xEdge == "eX1"
else [0, 1]
if xEdge == "eX2"
else [1, 1]
)
posY = (
[0, 0]
if yEdge == "eY0"
else [1, 0] if yEdge == "eY1" else [0, 1] if yEdge == "eY2" else [1, 1]
else [1, 0]
if yEdge == "eY1"
else [0, 1]
if yEdge == "eY2"
else [1, 1]
)
posZ = (
[0, 0]
if zEdge == "eZ0"
else [1, 0] if zEdge == "eZ1" else [0, 1] if zEdge == "eZ2" else [1, 1]
else [1, 0]
if zEdge == "eZ1"
else [0, 1]
if zEdge == "eZ2"
else [1, 1]
)

ind1 = sub2ind(M.vnEx, np.c_[ii, jj + posX[0], kk + posX[1]])
Expand Down
2 changes: 1 addition & 1 deletion discretize/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ def random(size, iscomplex):

print(
f"Adjoint test {'PASSED' if passed else 'FAILED'} :: "
f"{abs(rhs-lhs):.3e} < {atol+rtol*abs(lhs):.3e} :: "
f"{abs(rhs - lhs):.3e} < {atol + rtol * abs(lhs):.3e} :: "
f"|rhs-lhs| < atol + rtol|lhs|"
)

Expand Down
2 changes: 1 addition & 1 deletion discretize/utils/mesh_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ def refine_tree_xyz(

else:
raise NotImplementedError(
"Only method= 'radial', 'surface'" " or 'box' have been implemented"
"Only method= 'radial', 'surface' or 'box' have been implemented"
)

return mesh
Expand Down
7 changes: 3 additions & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@

import os
import sys
from pathlib import Path
from datetime import datetime
from packaging.version import parse
import discretize
import shutil
from importlib.metadata import version
import math
import pyvista

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
Expand Down Expand Up @@ -218,8 +219,6 @@ def linkcode_resolve(domain, info):
plot_include_source = True
plot_formats = [("png", 100), "pdf"]

import math

phi = (math.sqrt(5) + 1) / 2

plot_rcparams = {
Expand Down Expand Up @@ -457,7 +456,7 @@ def linkcode_resolve(domain, info):
]

# -- pyvista configuration ---------------------------------------------------
import pyvista


# Manage errors
pyvista.set_error_output_file("errors.txt")
Expand Down
3 changes: 1 addition & 2 deletions examples/plot_slicer_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ def beautify(title, fig=None):

mesh.plot_3d_slicer(Lpout, 370000, 6002500, -2500, transparent=[[-0.02, 0.1]])
beautify(
"mesh.plot_3d_slicer("
"\nLpout, 370000, 6002500, -2500, transparent=[[-0.02, 0.1]])"
"mesh.plot_3d_slicer(\nLpout, 370000, 6002500, -2500, transparent=[[-0.02, 0.1]])"
)
plt.show()

Expand Down
86 changes: 14 additions & 72 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,7 @@ test = [
]
# when changing these, make sure to keep it consistent with .pre-commit-config.
style = [
"black==24.3.0",
"flake8==7.0.0",
"flake8-bugbear==23.12.2",
"flake8-builtins==2.2.0",
"flake8-mutable==1.2.0",
"flake8-rst-docstrings==0.3.0",
"flake8-docstrings==1.7.0",
"flake8-pyproject==1.2.3",
"ruff==0.14.0",
]
build = [
"meson-python>=0.14.0",
Expand Down Expand Up @@ -150,74 +143,23 @@ exclude_also = [
# Don't complain about abstract methods, they aren't run:
"@(abc\\.)?abstractmethod",
]
[tool.ruff]
required-version = '0.14.0'
target-version = 'py311'
#extend-exclude = [
# 'docs/examples/*',
# 'docs/tutorials/*',
#]

[tool.black]
required-version = '24.3.0'
target-version = ['py38', 'py39', 'py310', 'py311']

[tool.flake8]
[tool.ruff.lint]
extend-ignore = [
# Too many leading '#' for block comment
'E266',
# Line too long (82 > 79 characters)
'E501',
# Do not use variables named 'I', 'O', or 'l'
'E741',
# Line break before binary operator (conflicts with black)
'W503',
# Ignore spaces before a colon (Black handles it)
'E203',
# Ignore spaces around an operator (Black handles it)
'E225',
# Ignore rst warnings for start and end, due to *args and **kwargs being invalid rst, but good for numpydoc
'RST210',
'RST213',
# ignore undocced __init__
'D107',
]
exclude = [
'.git',
'.eggs',
'__pycache__',
'.ipynb_checkpoints',
'docs/examples/*',
'docs/tutorials/*',
'docs/*',
'discretize/_extensions/*.py',
'.ci/*'
]
per-file-ignores = [
# disable unused-imports errors on __init__.py
# Automodule used for __init__ scripts' description
'__init__.py: F401, D204, D205, D400',
# do not check for assigned lambdas in tests
# do not check for missing docstrings in tests
'tests/*: E731, D',
'tutorials/*: D',
'examples/*: D',
]
exclude-from-doctest = [
# Only check discretize for docstring style
'tests',
'tutorials',
'examples',
]

rst-roles = [
'class',
'func',
'mod',
'meth',
'attr',
'ref',
'data',
# Python programming language:
'py:func','py:mod','py:attr','py:meth',
]
[tool.ruff.lint.extend-per-file-ignores]
"tests/*" = ["E731"] # Ignore assigning lambdas in tests
"__init__.py" = ["F401"] # Ignore unused import in __init__.py

rst-directives = [
# These are sorted alphabetically - but that does not matter
'autosummary',
'currentmodule',
'deprecated',
]
[tool.ruff.lint.pydocstyle]
convention = "numpy"
Loading