Skip to content

Commit

Permalink
Merge branch 'main' into dokken/cmake_version_range
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgensd committed Sep 14, 2022
2 parents caf62a9 + 763c6be commit caa6883
Show file tree
Hide file tree
Showing 31 changed files with 61 additions and 36 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/pythonapp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ jobs:
run: |
python -m mypy ffcx/
- name: isort checks (non-blocking)
continue-on-error: true
run: |
python3 -m isort --check .
- name: Check documentation style
run: |
python -m pydocstyle .
Expand Down
5 changes: 5 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[settings]
src_paths = ffcx,test,demo
known_first_party = basix,ufl
known_third_party = numpy,pytest
sections=FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
1 change: 1 addition & 0 deletions demo/test_demos.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import sys

import pytest

demo_dir = os.path.dirname(os.path.realpath(__file__))
Expand Down
1 change: 1 addition & 0 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# import sys
# sys.path.insert(0, os.path.abspath('.'))
import datetime

import ffcx

# -- Project information -----------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions ffcx/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

import numpy
import numpy.typing
import ufl
import basix.ufl_wrapper

import basix.ufl_wrapper
import ufl
from ffcx.element_interface import convert_element

logger = logging.getLogger("ffcx")
Expand Down
1 change: 1 addition & 0 deletions ffcx/codegeneration/C/cnodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import numbers

import numpy

from ffcx.codegeneration.C.format_lines import Indented, format_indented_lines
from ffcx.codegeneration.C.format_value import (format_float, format_int,
format_value)
Expand Down
2 changes: 1 addition & 1 deletion ffcx/codegeneration/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
import hashlib
import os

# Version of FFCx header files
__author__ = "FEniCS Project"
Expand Down
2 changes: 1 addition & 1 deletion ffcx/codegeneration/access.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import warnings

import ufl
from ffcx.element_interface import create_element, convert_element
from basix.ufl_wrapper import BlockedElement
from ffcx.element_interface import convert_element, create_element

logger = logging.getLogger("ffcx")

Expand Down
4 changes: 3 additions & 1 deletion ffcx/codegeneration/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
"""Collection of FFCx specific pieces for the code generation phase."""

import types

import ffcx.codegeneration.C.cnodes
from ffcx.codegeneration.access import FFCXBackendAccess
from ffcx.codegeneration.C.ufl_to_cnodes import UFL2CNodesTranslatorCpp
Expand All @@ -18,7 +20,7 @@ class FFCXBackend(object):
def __init__(self, ir, options):

# This is the seam where cnodes/C is chosen for the FFCx backend
self.language = ffcx.codegeneration.C.cnodes
self.language: types.ModuleType = ffcx.codegeneration.C.cnodes
scalar_type = options["scalar_type"]
self.ufl_to_language = UFL2CNodesTranslatorCpp(self.language, scalar_type)

Expand Down
1 change: 0 additions & 1 deletion ffcx/codegeneration/dofmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import ffcx.codegeneration.dofmap_template as ufcx_dofmap


logger = logging.getLogger("ffcx")


Expand Down
20 changes: 10 additions & 10 deletions ffcx/codegeneration/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,12 @@ def generate(self):
L = self.backend.language

parts = []
scalar_type = self.backend.access.options["scalar_type"]
value_type = scalar_to_value_type(scalar_type)

parts += self.generate_element_tables()
parts += self.generate_element_tables(value_type)
# Generate the tables of geometry data that are needed
parts += self.generate_geometry_tables()
parts += self.generate_geometry_tables(value_type)
parts += self.generate_piecewise_partition()

all_preparts = []
Expand All @@ -169,15 +171,15 @@ def generate(self):

return L.StatementList(parts)

def generate_geometry_tables(self):
def generate_geometry_tables(self, float_type: str):
"""Generate static tables of geometry data."""
L = self.backend.language

# Currently we only support circumradius
ufl_geometry = {
ufl.geometry.ReferenceCellVolume: "reference_cell_volume"
ufl.geometry.ReferenceCellVolume: "reference_cell_volume",
}
cells = {t: set() for t in ufl_geometry.keys()}
cells: Dict[Any, Set[Any]] = {t: set() for t in ufl_geometry.keys()}

for integrand in self.ir.integrand.values():
for attr in integrand["factorization"].nodes.values():
Expand All @@ -190,11 +192,11 @@ def generate_geometry_tables(self):
parts = []
for i, cell_list in cells.items():
for c in cell_list:
parts.append(geometry.write_table(L, ufl_geometry[i], c))
parts.append(geometry.write_table(L, ufl_geometry[i], c, float_type))

return parts

def generate_element_tables(self):
def generate_element_tables(self, float_type: str):
"""Generate tables of FE basis evaluated at specified points."""
L = self.backend.language
parts = []
Expand All @@ -204,12 +206,10 @@ def generate_element_tables(self):
padlen = self.ir.options["padlen"]
table_names = sorted(tables)

scalar_type = self.backend.access.options["scalar_type"]

for name in table_names:
table = tables[name]
decl = L.ArrayDecl(
f"static const {scalar_type}", name, table.shape, table, padlen=padlen)
f"static const {float_type}", name, table.shape, table, padlen=padlen)
parts += [decl]

# Add leading comment if there are any tables
Expand Down
2 changes: 1 addition & 1 deletion ffcx/codegeneration/finite_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

import logging

import ffcx.codegeneration.finite_element_template as ufcx_finite_element
import ffcx.codegeneration.basix_custom_element_template as ufcx_basix_custom_finite_element
import ffcx.codegeneration.finite_element_template as ufcx_finite_element
import ufl

logger = logging.getLogger("ffcx")
Expand Down
3 changes: 2 additions & 1 deletion ffcx/codegeneration/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
#
# SPDX-License-Identifier: LGPL-3.0-or-later

import basix
import numpy

import basix


def write_table(L, tablename, cellname, type: str):
if tablename == "facet_edge_vertices":
Expand Down
6 changes: 3 additions & 3 deletions ffcx/codegeneration/integrals.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import collections
import logging
from typing import List, Tuple
from typing import Any, Dict, List, Set, Tuple

import ufl
from ffcx.codegeneration import geometry
Expand Down Expand Up @@ -253,7 +253,7 @@ def generate_quadrature_tables(self, value_type: str) -> List[str]:
parts = L.commented_code_list(parts, "Quadrature rules")
return parts

def generate_geometry_tables(self, float_type):
def generate_geometry_tables(self, float_type: str):
"""Generate static tables of geometry data."""
L = self.backend.language

Expand All @@ -267,7 +267,7 @@ def generate_geometry_tables(self, float_type):
ufl.geometry.ReferenceNormal: "reference_facet_normals",
ufl.geometry.FacetOrientation: "facet_orientation"
}
cells = {t: set() for t in ufl_geometry.keys()}
cells: Dict[Any, Set[Any]] = {t: set() for t in ufl_geometry.keys()}

for integrand in self.ir.integrand.values():
for attr in integrand["factorization"].nodes.values():
Expand Down
1 change: 1 addition & 0 deletions ffcx/codegeneration/jit.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from pathlib import Path

import cffi

import ffcx
import ffcx.naming

Expand Down
8 changes: 4 additions & 4 deletions ffcx/element_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
from __future__ import annotations

import typing

import warnings
from functools import lru_cache

import basix
import numpy
import ufl

import basix
import basix.ufl_wrapper
from functools import lru_cache
import ufl


def convert_element(element: ufl.finiteelement.FiniteElementBase) -> basix.ufl_wrapper._BasixElementBase:
Expand Down
1 change: 1 addition & 0 deletions ffcx/ir/analysis/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import logging

import numpy

import ufl
from ffcx.ir.analysis.modified_terminals import is_modified_terminal
from ffcx.ir.analysis.reconstruct import reconstruct
Expand Down
1 change: 1 addition & 0 deletions ffcx/ir/analysis/modified_terminals.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
Grad, Indexed, Jacobian, ReferenceGrad,
ReferenceValue, Restricted, SpatialCoordinate)
from ufl.permutation import build_component_numbering

from ...element_interface import convert_element

logger = logging.getLogger("ffcx")
Expand Down
1 change: 1 addition & 0 deletions ffcx/ir/elementtables.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import typing

import numpy

import ufl
import ufl.utils.derivativetuples
from ffcx.element_interface import basix_index, convert_element
Expand Down
1 change: 1 addition & 0 deletions ffcx/ir/integral.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import typing

import numpy

import ufl
from ffcx.ir.analysis.factorization import compute_argument_factorization
from ffcx.ir.analysis.graph import build_scalar_graph
Expand Down
3 changes: 2 additions & 1 deletion ffcx/ir/representation.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
import typing
import warnings

import basix
import numpy

import basix
import ufl
from ffcx import naming
from ffcx.analysis import UFLData
Expand Down
1 change: 1 addition & 0 deletions ffcx/ir/representationutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import logging

import numpy

import ufl
from ffcx.element_interface import (create_quadrature, map_facet_points,
reference_cell_vertices)
Expand Down
1 change: 0 additions & 1 deletion ffcx/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import string

import ufl

from ffcx import __version__ as FFCX_VERSION
from ffcx import compiler, formatting
from ffcx.options import FFCX_DEFAULT_OPTIONS, get_options
Expand Down
3 changes: 2 additions & 1 deletion ffcx/naming.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@

import numpy
import numpy.typing
import ufl

import ffcx
import ufl

from .element_interface import convert_element


Expand Down
2 changes: 1 addition & 1 deletion ffcx/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import os
import os.path
import pprint
from typing import Optional, Dict, Any
from pathlib import Path
from typing import Any, Dict, Optional

logger = logging.getLogger("ffcx")

Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ test = pytest >= 6.0; sympy
ci =
coverage
coveralls
isort
pytest-cov
pytest-xdist
mypy
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

try:
import pip

from packaging import version
if version.parse(pip.__version__) < version.parse("21.3"):
# Issue with older version of pip https://github.com/pypa/pip/issues/7953
Expand Down
3 changes: 2 additions & 1 deletion test/test_add_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
#
# SPDX-License-Identifier: LGPL-3.0-or-later

import ffcx.codegeneration.jit
import numpy as np
import pytest

import ffcx.codegeneration.jit
import ufl
from ffcx.naming import cdtype_to_numpy, scalar_to_value_type

Expand Down
2 changes: 1 addition & 1 deletion test/test_flops.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
# SPDX-License-Identifier: LGPL-3.0-or-later


from ffcx.codegeneration.flop_count import count_flops
import ufl
from ffcx.codegeneration.flop_count import count_flops


def create_form(degree):
Expand Down
5 changes: 3 additions & 2 deletions test/test_jit_expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
#
# SPDX-License-Identifier: LGPL-3.0-or-later

import basix
import cffi
import ffcx.codegeneration.jit
import numpy as np

import basix
import ffcx.codegeneration.jit
import ufl
from ffcx.naming import cdtype_to_numpy, scalar_to_value_type

Expand Down
5 changes: 3 additions & 2 deletions test/test_jit_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
#
# SPDX-License-Identifier: LGPL-3.0-or-later

import ffcx.codegeneration.jit
import numpy as np
import pytest
import sympy
from sympy.abc import x, y, z

import ffcx.codegeneration.jit
import ufl
from ffcx.naming import cdtype_to_numpy, scalar_to_value_type
from sympy.abc import x, y, z


@pytest.mark.parametrize("mode,expected_result", [
Expand Down

0 comments on commit caa6883

Please sign in to comment.