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

Ruff format mk2 #3044

Merged
merged 9 commits into from
Feb 7, 2024
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
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ install-python-components: &install-python-components
pip3 install git+https://github.com/FEniCS/ffcx.git

ruff-isort-python-code: &ruff-isort-python-code
name: ruff and isort checks on Python code
name: ruff checks on Python code
command: |
cd python/
ruff check .
isort --check .
ruff format --check .

configure-cpp: &configure-cpp
name: Configure (C++)
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/ccpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ jobs:
python3 -m pip install git+https://github.com/FEniCS/basix.git@${{ github.event.inputs.basix_ref }}
python3 -m pip install git+https://github.com/FEniCS/ffcx.git@${{ github.event.inputs.ffcx_ref }}

- name: ruff and isort C++ .py file checks
- name: ruff C++ .py file checks
run: |
cd cpp/
ruff check .
python3 -m isort --check .
- name: ruff and isort Python interface checks
ruff format --check .
- name: ruff Python interface checks
run: |
cd python/
ruff check .
python3 -m isort --check .
ruff format --check .
- name: mypy checks
run: |
cd python/
Expand Down
21 changes: 6 additions & 15 deletions cpp/cmake/scripts/generate-cmakefiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import os
import warnings

cmakelists_noufl_str = \
"""# This file was generated by running
cmakelists_noufl_str = """# This file was generated by running
#
# python cmake/scripts/generate-cmakefiles.py from dolfinx/cpp
#
Expand Down Expand Up @@ -51,8 +50,7 @@
"""


cmakelists_nocomplex_str = \
"""# This file was generated by running
cmakelists_nocomplex_str = """# This file was generated by running
#
# python cmake/scripts/generate-cmakefiles from dolfinx/cpp
#
Expand Down Expand Up @@ -117,8 +115,7 @@
endif()
"""

cmakelists_str = \
"""# This file was generated by running
cmakelists_str = """# This file was generated by running
#
# python cmake/scripts/generate-cmakefiles from dolfinx/cpp
#
Expand Down Expand Up @@ -205,7 +202,6 @@ def generate_cmake_files(subdirectory, generated_files):
executable_prefix = executable_prefixes[subdirectory]
main_file_name = main_file_names[subdirectory]
for root, dirs, files in os.walk(cwd + "/" + subdirectory):

cpp_files = set()
ufl_files = set()
ufl_c_files = set()
Expand All @@ -224,9 +220,7 @@ def generate_cmake_files(subdirectory, generated_files):
continue

if "main.cpp" in os.listdir(program_dir):
name_forms = dict(
project_name=executable_prefix + program_name, src_files="NOT_SET"
)
name_forms = dict(project_name=executable_prefix + program_name, src_files="NOT_SET")
for f in os.listdir(program_dir):
filename, extension = os.path.splitext(f)
if extension == ".cpp":
Expand All @@ -242,8 +236,7 @@ def generate_cmake_files(subdirectory, generated_files):
continue

if len(ufl_files) > 1:
raise RuntimeError(
"CMake generation supports exactly one UFL file")
raise RuntimeError("CMake generation supports exactly one UFL file")

# Name of demo and cpp source files
# print("**, ", main_file_name, cpp_files)
Expand All @@ -260,9 +253,7 @@ def generate_cmake_files(subdirectory, generated_files):
if program_name not in executable_names:
executable_names.add(program_name)
else:
warnings.warn(
"Duplicate executable names found when generating CMakeLists.txt files."
)
warnings.warn("Duplicate executable names found when generating CMakeLists.txt files.")

# Write file
filename = os.path.join(program_dir, "CMakeLists.txt")
Expand Down
30 changes: 23 additions & 7 deletions cpp/demo/biharmonic/biharmonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,23 @@
# the variational problem in UFL terms in a separate form file
# :download:`biharmonic.py`. We begin by defining the finite element::
from basix.ufl import element
from ufl import (CellDiameter, Coefficient, Constant, FacetNormal,
FunctionSpace, Mesh, TestFunction, TrialFunction, avg, div,
dS, dx, grad, inner, jump)
from ufl import (
CellDiameter,
Coefficient,
Constant,
FacetNormal,
FunctionSpace,
Mesh,
TestFunction,
TrialFunction,
avg,
div,
dS,
dx,
grad,
inner,
jump,
)

e = element("Lagrange", "triangle", 2)

Expand Down Expand Up @@ -41,18 +55,20 @@
# Normal component, mesh size and right-hand side
n = FacetNormal(mesh)
h = CellDiameter(mesh)
h_avg = (h('+') + h('-')) / 2
h_avg = (h("+") + h("-")) / 2
alpha = Constant(mesh)

# Finally, we define the bilinear and linear forms according to the
# variational formulation of the equations. Integrals over
# internal facets are indicated by ``*dS``. ::

# Bilinear form
a = inner(div(grad(u)), div(grad(v))) * dx \
- inner(avg(div(grad(u))), jump(grad(v), n)) * dS \
- inner(jump(grad(u), n), avg(div(grad(v)))) * dS \
a = (
inner(div(grad(u)), div(grad(v))) * dx
- inner(avg(div(grad(u))), jump(grad(v), n)) * dS
- inner(jump(grad(u), n), avg(div(grad(v)))) * dS
+ alpha / h_avg * inner(jump(grad(u), n), jump(grad(v), n)) * dS
)

# Linear form
L = inner(f, v) * dx
33 changes: 23 additions & 10 deletions cpp/demo/hyperelasticity/hyperelasticity.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,31 @@
# dimensions, so first we need the appropriate finite element space and
# trial and test functions on this space::
from basix.ufl import element
from ufl import (Coefficient, FunctionSpace, Identity, Mesh, TestFunction,
TrialFunction, derivative, det, diff, dx, grad, ln, tr,
variable)
from ufl import (
Coefficient,
FunctionSpace,
Identity,
Mesh,
TestFunction,
TrialFunction,
derivative,
det,
diff,
dx,
grad,
ln,
tr,
variable,
)

# Function spaces
e = element("Lagrange", "tetrahedron", 1, shape=(3,))
mesh = Mesh(e)
V = FunctionSpace(mesh, e)

# Trial and test functions
du = TrialFunction(V) # Incremental displacement
v = TestFunction(V) # Test function
du = TrialFunction(V) # Incremental displacement
v = TestFunction(V) # Test function

# Note that ``element`` with `shape=(3,)` creates a finite element space
# of vector fields.
Expand All @@ -29,17 +42,17 @@
# traction ``T`` and the displacement solution itself ``u``::

# Functions
u = Coefficient(V) # Displacement from previous iteration
u = Coefficient(V) # Displacement from previous iteration
# B = Coefficient(element) # Body force per unit volume
# T = Coefficient(element) # Traction force on the boundary

# Now, we can define the kinematic quantities involved in the model::

# Kinematics
d = len(u)
I = Identity(d) # Identity tensor # noqa: E741
F = variable(I + grad(u)) # Deformation gradient
C = F.T * F # Right Cauchy-Green tensor
I = Identity(d) # Identity tensor # noqa: E741
F = variable(I + grad(u)) # Deformation gradient
C = F.T * F # Right Cauchy-Green tensor

# Invariants of deformation tensors
Ic = tr(C)
Expand All @@ -60,7 +73,7 @@
# ``derivative``::

# Stored strain energy density (compressible neo-Hookean model)
psi = (mu / 2) * (Ic - 3) - mu * ln(J) + (lmbda / 2) * (ln(J))**2
psi = (mu / 2) * (Ic - 3) - mu * ln(J) + (lmbda / 2) * (ln(J)) ** 2

# Total potential energy
Pi = psi * dx # - inner(B, u) * dx - inner(T, u) * ds
Expand Down
14 changes: 12 additions & 2 deletions cpp/demo/poisson/poisson.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,18 @@
# the variational problem in UFL terms in a separate form file
# :download:`poisson.py`. We begin by defining the finite element::
from basix.ufl import element
from ufl import (Coefficient, Constant, FunctionSpace, Mesh, TestFunction,
TrialFunction, ds, dx, grad, inner)
from ufl import (
Coefficient,
Constant,
FunctionSpace,
Mesh,
TestFunction,
TrialFunction,
ds,
dx,
grad,
inner,
)

e = element("Lagrange", "triangle", 1)

Expand Down
14 changes: 12 additions & 2 deletions cpp/demo/poisson_matrix_free/poisson.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
# UFL input for the Matrix-free Poisson Demo
# ==================================
from basix.ufl import element
from ufl import (Coefficient, Constant, FunctionSpace, Mesh, TestFunction,
TrialFunction, action, dx, grad, inner)
from ufl import (
Coefficient,
Constant,
FunctionSpace,
Mesh,
TestFunction,
TrialFunction,
action,
dx,
grad,
inner,
)

coord_element = element("Lagrange", "triangle", 1, shape=(2,))
mesh = Mesh(coord_element)
Expand Down
23 changes: 12 additions & 11 deletions cpp/doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,26 @@

# -- Project information -----------------------------------------------------

project = 'DOLFINx'
copyright = '2022, FEniCS Project'
author = 'FEniCS Project'
project = "DOLFINx"
copyright = "2022, FEniCS Project"
author = "FEniCS Project"

# The full version, including alpha/beta/rc tags
release = '0.3.1'
release = "0.3.1"
jhale marked this conversation as resolved.
Show resolved Hide resolved


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinx.ext.mathjax',
'breathe',
]
extensions = [
"sphinx.ext.mathjax",
"breathe",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand All @@ -61,10 +62,10 @@

breathe_projects = {"DOLFINx": "../xml/"}
breathe_default_project = "DOLFINx"
breathe_implementation_filename_extensions = ['.c', '.cc', '.cpp']
breathe_implementation_filename_extensions = [".c", ".cc", ".cpp"]

# Tell sphinx what the primary language being documented is.
primary_domain = 'cpp'
primary_domain = "cpp"

# Tell sphinx what the pygments highlight language should be.
highlight_language = 'cpp'
highlight_language = "cpp"
13 changes: 11 additions & 2 deletions cpp/test/poisson.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
from basix.ufl import element
from ufl import (Coefficient, Constant, FunctionSpace, Mesh, TestFunction,
TrialFunction, dx, grad, inner)
from ufl import (
Coefficient,
Constant,
FunctionSpace,
Mesh,
TestFunction,
TrialFunction,
dx,
grad,
inner,
)

e = element("Lagrange", "tetrahedron", 2)
coord_element = element("Lagrange", "tetrahedron", 1, shape=(3,))
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.test-env
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ RUN if [ "$MPI" = "mpich" ]; then \
# documentation or run tests.
RUN pip3 install --no-cache-dir --upgrade setuptools pip && \
pip3 install --no-cache-dir cffi mpi4py numba numpy==${NUMPY_VERSION} scikit-build-core[pyproject] && \
pip3 install --no-cache-dir breathe clang-format cmakelang flake8 isort jupytext matplotlib mypy myst-parser nanobind==${NANOBIND_VERSION} pytest pytest-xdist ruff scipy sphinx sphinx_rtd_theme types-setuptools
pip3 install --no-cache-dir breathe clang-format cmakelang jupytext matplotlib mypy myst-parser nanobind==${NANOBIND_VERSION} pytest pytest-xdist ruff scipy sphinx sphinx_rtd_theme types-setuptools

# Install KaHIP
RUN wget -nc --quiet https://github.com/kahip/kahip/archive/v${KAHIP_VERSION}.tar.gz && \
Expand Down
11 changes: 7 additions & 4 deletions python/demo/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@


def pytest_addoption(parser):
parser.addoption("--mpiexec", action="store", default="mpirun",
help="Name of program to run MPI, e.g. mpiexec")
parser.addoption("--num-proc", action="store", default=1,
help="Number of MPI processes to use")
parser.addoption(
"--mpiexec",
action="store",
default="mpirun",
help="Name of program to run MPI, e.g. mpiexec",
)
parser.addoption("--num-proc", action="store", default=1, help="Number of MPI processes to use")


@pytest.fixture
Expand Down
Loading
Loading