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

replace 'jit_paramters' with 'jit_option', and 'form_compiler_parameters' with 'form_compiler_options' #2310

Merged
merged 7 commits into from Aug 31, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions .circleci/config.yml
Expand Up @@ -9,7 +9,7 @@ install-python-components: &install-python-components
cmake --install build-dir
pip3 install ./basix/python
pip3 install git+https://github.com/FEniCS/ufl.git
pip3 install git+https://github.com/FEniCS/ffcx.git
pip3 install git+https://github.com/FEniCS/ffcx.git@sarah/replace-parameters-options

flake8-python-code: &flake8-python-code
name: Flake8 checks on Python code
Expand Down Expand Up @@ -72,10 +72,10 @@ demos-python-mpi: &demos-python-mpi
python3 -m pytest -n=2 -v -m mpi test.py --num-proc=3

set-jit-defaults: &set-jit-defaults
name: Set default DOLFINx JIT parameters
name: Set default DOLFINx JIT options
command: |
mkdir -p ~/.config/dolfinx
echo '{ "cffi_extra_compile_args" : ["-g0", "-O0" ] }' > ~/.config/dolfinx/dolfinx_jit_parameters.json
echo '{ "cffi_extra_compile_args" : ["-g0", "-O0" ] }' > ~/.config/dolfinx/dolfinx_jit_options.json

unit-tests-python: &unit-tests-python
name: Run unit tests (Python, serial)
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ccpp.yml
Expand Up @@ -56,7 +56,7 @@ jobs:
run: |
python3 -m pip install git+https://github.com/FEniCS/ufl.git
python3 -m pip install git+https://github.com/FEniCS/basix.git
python3 -m pip install git+https://github.com/FEniCS/ffcx.git
python3 -m pip install git+https://github.com/FEniCS/ffcx.git@sarah/replace-parameters-options
- name: Install FEniCS Python components
if: github.event_name == 'workflow_dispatch'
run: |
Expand Down Expand Up @@ -142,10 +142,10 @@ jobs:
cd python/doc
make html

- name: Set default DOLFINx JIT parameters
- name: Set default DOLFINx JIT options
run: |
mkdir -p ~/.config/dolfinx
echo '{ "cffi_extra_compile_args": ["-g0", "-O0" ] }' > ~/.config/dolfinx/dolfinx_jit_parameters.json
echo '{ "cffi_extra_compile_args": ["-g0", "-O0" ] }' > ~/.config/dolfinx/dolfinx_jit_options.json

- name: Run demos (Python, serial)
run: python3 -m pytest -n=2 -m serial --durations=10 python/demo/test.py
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/docker.yml
Expand Up @@ -35,7 +35,7 @@ on:

ffcx_ref:
description: "ffcx git ref to checkout"
default: "main"
default: "sarah/replace-parameters-options"
type: string

jobs:
Expand Down Expand Up @@ -250,12 +250,12 @@ jobs:
repository: "FEniCS/ffcx"
path: "ffcx"
ref: ${{ steps.refs.outputs.FFCX_REF }}
- name: Set default FFCx parameters
- name: Set default FFCx options
run: |
echo '{ }' > dolfinx/docker/ffcx_parameters.json
- name: Set default DOLFINx JIT parameters
echo '{ }' > dolfinx/docker/ffcx_options.json
- name: Set default DOLFINx JIT options
run: |
echo '{ "cffi_extra_compile_args" : ["-O2"] } ' > dolfinx/docker/dolfinx_jit_parameters.json
echo '{ "cffi_extra_compile_args" : ["-O2"] } ' > dolfinx/docker/dolfinx_jit_options.json
- name: Build dolfinx/dolfinx-onbuild
run: |
docker buildx build --file dolfinx/docker/Dockerfile ${DOCKER_BUILD_ARGS} \
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/intel.yml
Expand Up @@ -47,6 +47,7 @@ jobs:
with:
path: ./ffcx
repository: FEniCS/ffcx
ref: sarah/replace-parameters-options

- name: Install FFCx C interface
run: |
Expand Down Expand Up @@ -93,10 +94,10 @@ jobs:
run: |
. /opt/intel/oneapi/setvars.sh
python3 -m pip -v install python/
- name: Set default DOLFINx JIT parameters
- name: Set default DOLFINx JIT options
run: |
mkdir -p ~/.config/dolfinx
echo '{ "cffi_extra_compile_args": ["-g0", "-O0" ] }' > ~/.config/dolfinx/dolfinx_jit_parameters.json
echo '{ "cffi_extra_compile_args": ["-g0", "-O0" ] }' > ~/.config/dolfinx/dolfinx_jit_options.json
- name: Run DOLFINx demos (Python, serial)
run: |
. /opt/intel/oneapi/setvars.sh
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/redhat.yml
Expand Up @@ -17,7 +17,7 @@ jobs:
run: |
python3 -m pip install git+https://github.com/FEniCS/ufl.git
python3 -m pip install git+https://github.com/FEniCS/basix.git
python3 -m pip install git+https://github.com/FEniCS/ffcx.git
python3 -m pip install git+https://github.com/FEniCS/ffcx.git@sarah/replace-parameters-options

- name: Configure C++
run: cmake -G Ninja -DCMAKE_BUILD_TYPE=Developer -B build -S cpp/
Expand Down Expand Up @@ -50,10 +50,10 @@ jobs:
- name: Build Python interface
run: python3 -m pip -v install --global-option build --global-option --debug python/

- name: Set default DOLFINx JIT parameters
- name: Set default DOLFINx JIT options
run: |
mkdir -p ~/.config/dolfinx
echo '{ "cffi_extra_compile_args": ["-g0", "-O0" ] }' > ~/.config/dolfinx/dolfinx_jit_parameters.json
echo '{ "cffi_extra_compile_args": ["-g0", "-O0" ] }' > ~/.config/dolfinx/dolfinx_jit_options.json

- name: Run demos (Python, serial)
run: python3 -m pytest -n=2 -m serial --durations=10 python/demo/test.py
Expand Down
6 changes: 3 additions & 3 deletions docker/Dockerfile
Expand Up @@ -36,7 +36,7 @@
# You can build an optimised version of the complete FEniCS environment for
# your platform using the commands:
#
# echo '{ "cffi_extra_compile_args" : ["-O2", "-march=native" ] }' > dolfinx/docker/dolfinx_jit_parameters.json
# echo '{ "cffi_extra_compile_args" : ["-O2", "-march=native" ] }' > dolfinx/docker/dolfinx_jit_options.json
# docker build --target dolfinx --file dolfinx/docker/Dockerfile --build-arg PETSC_SLEPC_OPTFLAGS="-O2 -march=native" --build-arg DOLFINX_CMAKE_CXX_FLAGS="-march=native" .
#
# You can build an optimised version of the FEniCS development environment
Expand Down Expand Up @@ -393,8 +393,8 @@ ONBUILD ADD dolfinx/ /src/dolfinx/

# These files are empty by default, i.e. they do nothing.
# The user can set them at build time if they wish.
ONBUILD ADD dolfinx/docker/dolfinx_jit_parameters.json /root/.config/dolfinx/dolfinx_jit_parameters.json
ONBUILD ADD dolfinx/docker/ffcx_parameters.json /root/.config/ffcx/ffcx_parameters.json
ONBUILD ADD dolfinx/docker/dolfinx_jit_options.json /root/.config/dolfinx/dolfinx_jit_options.json
ONBUILD ADD dolfinx/docker/ffcx_options.json /root/.config/ffcx/ffcx_options.json

# The following ARGS are used in the DOLFINx layer.
# They are safe defaults.
Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions python/demo/demo_static-condensation.py
Expand Up @@ -97,11 +97,11 @@ def sigma_u(u):
# JIT compile individual blocks tabulation kernels
nptype = "complex128" if np.issubdtype(PETSc.ScalarType, np.complexfloating) else "float64"
ffcxtype = "double _Complex" if np.issubdtype(PETSc.ScalarType, np.complexfloating) else "double"
ufcx_form00, _, _ = ffcx_jit(msh.comm, a00, form_compiler_params={"scalar_type": ffcxtype})
ufcx_form00, _, _ = ffcx_jit(msh.comm, a00, form_compiler_options={"scalar_type": ffcxtype})
kernel00 = getattr(ufcx_form00.integrals(0)[0], f"tabulate_tensor_{nptype}")
ufcx_form01, _, _ = ffcx_jit(msh.comm, a01, form_compiler_params={"scalar_type": ffcxtype})
ufcx_form01, _, _ = ffcx_jit(msh.comm, a01, form_compiler_options={"scalar_type": ffcxtype})
kernel01 = getattr(ufcx_form01.integrals(0)[0], f"tabulate_tensor_{nptype}")
ufcx_form10, _, _ = ffcx_jit(msh.comm, a10, form_compiler_params={"scalar_type": ffcxtype})
ufcx_form10, _, _ = ffcx_jit(msh.comm, a10, form_compiler_options={"scalar_type": ffcxtype})
kernel10 = getattr(ufcx_form10.integrals(0)[0], f"tabulate_tensor_{nptype}")

ffi = cffi.FFI()
Expand Down
16 changes: 8 additions & 8 deletions python/dolfinx/fem/forms.py
Expand Up @@ -87,14 +87,14 @@ def integral_types(self):


def form(form: typing.Union[ufl.Form, typing.Iterable[ufl.Form]], dtype: np.dtype = PETSc.ScalarType,
form_compiler_params: dict = {}, jit_params: dict = {}):
form_compiler_options: dict = {}, jit_options: dict = {}):
"""Create a DOLFINx Form or an array of Forms

Args:
form: A UFL form or list(s) of UFL forms
dtype: Scalar type to use for the compiled form
form_compiler_params: See :func:`ffcx_jit <dolfinx.jit.ffcx_jit>`
jit_params:See :func:`ffcx_jit <dolfinx.jit.ffcx_jit>`
form_compiler_options: See :func:`ffcx_jit <dolfinx.jit.ffcx_jit>`
jit_options:See :func:`ffcx_jit <dolfinx.jit.ffcx_jit>`

Returns:
Compiled finite element Form
Expand All @@ -110,13 +110,13 @@ def form(form: typing.Union[ufl.Form, typing.Iterable[ufl.Form]], dtype: np.dtyp
"""
if dtype == np.float32:
ftype = _cpp.fem.Form_float32
form_compiler_params["scalar_type"] = "float"
form_compiler_options["scalar_type"] = "float"
elif dtype == np.float64:
ftype = _cpp.fem.Form_float64
form_compiler_params["scalar_type"] = "double"
form_compiler_options["scalar_type"] = "double"
elif dtype == np.complex128:
ftype = _cpp.fem.Form_complex128
form_compiler_params["scalar_type"] = "double _Complex"
form_compiler_options["scalar_type"] = "double _Complex"
else:
raise NotImplementedError(f"Type {dtype} not supported.")

Expand All @@ -133,8 +133,8 @@ def _form(form):
raise RuntimeError("Expecting to find a Mesh in the form.")

ufcx_form, module, code = jit.ffcx_jit(mesh.comm, form,
form_compiler_params=form_compiler_params,
jit_params=jit_params)
form_compiler_options=form_compiler_options,
jit_options=jit_options)

# For each argument in form extract its function space
V = [arg.ufl_function_space()._cpp_object for arg in form.arguments()]
Expand Down
22 changes: 11 additions & 11 deletions python/dolfinx/fem/function.py
Expand Up @@ -69,7 +69,7 @@ def dtype(self) -> np.dtype:

class Expression:
def __init__(self, ufl_expression: ufl.core.expr.Expr, X: np.ndarray,
form_compiler_params: dict = {}, jit_params: dict = {},
form_compiler_options: dict = {}, jit_options: dict = {},
dtype=PETSc.ScalarType):
"""Create DOLFINx Expression.

Expand All @@ -86,10 +86,10 @@ def __init__(self, ufl_expression: ufl.core.expr.Expr, X: np.ndarray,
ufl_expression: Pure UFL expression
X: Array of points of shape `(num_points, tdim)` on the
reference element.
form_compiler_params: Parameters used in FFCx compilation of
form_compiler_options: Options used in FFCx compilation of
this Expression. Run ``ffcx --help`` in the commandline
to see all available options.
jit_params: Parameters controlling JIT compilation of C code.
jit_options: Options controlling JIT compilation of C code.

Notes:
This wrapper is responsible for the FFCx compilation of the
Expand All @@ -106,17 +106,17 @@ def __init__(self, ufl_expression: ufl.core.expr.Expr, X: np.ndarray,

# Compile UFL expression with JIT
if dtype == np.float32:
form_compiler_params["scalar_type"] = "float"
form_compiler_options["scalar_type"] = "float"
if dtype == np.float64:
form_compiler_params["scalar_type"] = "double"
form_compiler_options["scalar_type"] = "double"
elif dtype == np.complex128:
form_compiler_params["scalar_type"] = "double _Complex"
form_compiler_options["scalar_type"] = "double _Complex"
else:
raise RuntimeError(f"Unsupported scalar type {dtype} for Expression.")

self._ufcx_expression, module, self._code = jit.ffcx_jit(mesh.comm, (ufl_expression, _X),
form_compiler_params=form_compiler_params,
jit_params=jit_params)
form_compiler_options=form_compiler_options,
jit_options=jit_options)
self._ufl_expression = ufl_expression

# Prepare coefficients data. For every coefficient in form take
Expand Down Expand Up @@ -431,7 +431,7 @@ class FunctionSpace(ufl.FunctionSpace):
def __init__(self, mesh: typing.Union[None, Mesh],
element: typing.Union[ufl.FiniteElementBase, ElementMetaData, typing.Tuple[str, int]],
cppV: typing.Optional[_cpp.fem.FunctionSpace] = None,
form_compiler_params: dict[str, typing.Any] = {}, jit_params: dict[str, typing.Any] = {}):
form_compiler_options: dict[str, typing.Any] = {}, jit_options: dict[str, typing.Any] = {}):
"""Create a finite element function space."""

# Create function space from a UFL element and existing cpp
Expand All @@ -455,8 +455,8 @@ def __init__(self, mesh: typing.Union[None, Mesh],

# Compile dofmap and element and create DOLFIN objects
(self._ufcx_element, self._ufcx_dofmap), module, code = jit.ffcx_jit(
mesh.comm, self.ufl_element(), form_compiler_params=form_compiler_params,
jit_params=jit_params)
mesh.comm, self.ufl_element(), form_compiler_options=form_compiler_options,
jit_options=jit_options)

ffi = module.ffi
cpp_element = _cpp.fem.FiniteElement(ffi.cast("uintptr_t", ffi.addressof(self._ufcx_element)))
Expand Down
34 changes: 17 additions & 17 deletions python/dolfinx/fem/petsc.py
Expand Up @@ -533,35 +533,35 @@ class LinearProblem:
"""

def __init__(self, a: ufl.Form, L: ufl.Form, bcs: typing.List[DirichletBCMetaClass] = [],
u: _Function = None, petsc_options={}, form_compiler_params={}, jit_params={}):
u: _Function = None, petsc_options={}, form_compiler_options={}, jit_options={}):
"""Initialize solver for a linear variational problem.

Args:
a: A bilinear UFL form, the left hand side of the variational problem.
L: A linear UFL form, the right hand side of the variational problem.
bcs: A list of Dirichlet boundary conditions.
u: The solution function. It will be created if not provided.
petsc_options: Parameters that is passed to the linear
petsc_options: Options that are passed to the linear
algebra backend PETSc. For available choices for the
'petsc_options' kwarg, see the `PETSc documentation
<https://petsc4py.readthedocs.io/en/stable/manual/ksp/>`_.
form_compiler_params: Parameters used in FFCx compilation of
form_compiler_options: Options used in FFCx compilation of
this form. Run ``ffcx --help`` at the commandline to see
all available options.
jit_params: Parameters used in CFFI JIT compilation of C
jit_options: Options used in CFFI JIT compilation of C
code generated by FFCx. See `python/dolfinx/jit.py` for
all available parameters. Takes priority over all other
parameter values.
all available options. Takes priority over all other
option values.

Example::

problem = LinearProblem(a, L, [bc0, bc1], petsc_options={"ksp_type": "preonly", "pc_type": "lu"})

"""
self._a = _create_form(a, form_compiler_params=form_compiler_params, jit_params=jit_params)
self._a = _create_form(a, form_compiler_options=form_compiler_options, jit_options=jit_options)
self._A = create_matrix(self._a)

self._L = _create_form(L, form_compiler_params=form_compiler_params, jit_params=jit_params)
self._L = _create_form(L, form_compiler_options=form_compiler_options, jit_options=jit_options)
self._b = create_vector(self._L)

if u is None:
Expand Down Expand Up @@ -654,38 +654,38 @@ class NonlinearProblem:
"""

def __init__(self, F: ufl.form.Form, u: _Function, bcs: typing.List[DirichletBCMetaClass] = [],
J: ufl.form.Form = None, form_compiler_params={}, jit_params={}):
J: ufl.form.Form = None, form_compiler_options={}, jit_options={}):
"""Initialize solver for solving a non-linear problem using Newton's method, :math:`dF/du(u) du = -F(u)`.

Args:
F: The PDE residual F(u, v)
u: The unknown
bcs: List of Dirichlet boundary conditions
J: UFL representation of the Jacobian (Optional)
form_compiler_params: Parameters used in FFCx
form_compiler_options: Options used in FFCx
compilation of this form. Run ``ffcx --help`` at the
commandline to see all available options.
jit_params: Parameters used in CFFI JIT compilation of C
jit_options: Options used in CFFI JIT compilation of C
code generated by FFCx. See ``python/dolfinx/jit.py``
for all available parameters. Takes priority over all
other parameter values.
for all available options. Takes priority over all
other option values.

Example::

problem = LinearProblem(F, u, [bc0, bc1])

"""
self._L = _create_form(F, form_compiler_params=form_compiler_params,
jit_params=jit_params)
self._L = _create_form(F, form_compiler_options=form_compiler_options,
jit_options=jit_options)

# Create the Jacobian matrix, dF/du
if J is None:
V = u.function_space
du = ufl.TrialFunction(V)
J = ufl.derivative(F, u, du)

self._a = _create_form(J, form_compiler_params=form_compiler_params,
jit_params=jit_params)
self._a = _create_form(J, form_compiler_options=form_compiler_options,
jit_options=jit_options)
self.bcs = bcs

@property
Expand Down