Skip to content

BUG:Compilation of interior surface integrals on hexahedral meshes is failing #4653

@miguelcoolchips

Description

@miguelcoolchips

Describe the bug
Compilation of interior surface integrals on hexahedral meshes is failing. It only fails for a certain combination of interior integrals

Steps to Reproduce
Steps to reproduce the behavior:

import firedrake as fd
from firedrake import inner, grad, dot, jump, avg, dS

N = 2
mesh = fd.UnitCubeMesh(N, N, N, hexahedral=True)
discretization_degree = 1

V = fd.VectorFunctionSpace(mesh, "DQ", discretization_degree) # Does not work

n = fd.FacetNormal(mesh)
u = fd.Function(V)
v = fd.TestFunction(V)
u_n = fd.Function(V)



un = 0.5 * (dot(u, n) + abs(dot(u, n)))
flux = jump(un * u)
facet_term = inner(flux, jump(v)) * dS
F_u_u_one = facet_term
F_u_u_two = (
    -  inner(avg(dot(grad(u), n)), jump(v)) * dS
    -  inner(jump(u), avg(dot(grad(v), n))) * dS
)

un_n = 0.5 * (dot(u_n, n) + abs(dot(u_n, n)))
flux = jump(un_n * u)
facet_term = inner(flux, jump(v)) * dS
F_u_u_third = facet_term



J = fd.derivative(F_u_u_one, u) 
fd.assemble(J)# works
print("Success")
J = fd.derivative(F_u_u_two, u) 
fd.assemble(J)
print("Success")
J = fd.derivative(F_u_u_two + F_u_u_third, u) 
fd.assemble(J)
print("Success")
J = fd.derivative(F_u_u_one + F_u_u_two, u)  # does not work
fd.assemble(J)
print("Never reach this")

Expected behavior
Normal compilation

Error message

ernel.py", line 438, in compile_global_kernel
    code = _generate_code_from_global_kernel(kernel, comm)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "petsc4py/PETSc/Log.pyx", line 250, in petsc4py.PETSc.Log.EventDecorator.decorator.wrapped_func
  File "petsc4py/PETSc/Log.pyx", line 251, in petsc4py.PETSc.Log.EventDecorator.decorator.wrapped_func
  File "/Users/miguel/repos/firedrake-pip-install-venv/lib/python3.11/site-packages/pyop2/caching.py", line 558, in wrapper
    value = func(*args, **kwargs)
            ^^^^^^^^^^^^^^^^^^^^^
  File "petsc4py/PETSc/Log.pyx", line 250, in petsc4py.PETSc.Log.EventDecorator.decorator.wrapped_func
  File "petsc4py/PETSc/Log.pyx", line 251, in petsc4py.PETSc.Log.EventDecorator.decorator.wrapped_func
  File "/Users/miguel/repos/firedrake-pip-install-venv/lib/python3.11/site-packages/pyop2/caching.py", line 555, in wrapper
    value = func(*args, **kwargs) if comm.rank == 0 else None
            ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/miguel/repos/firedrake-pip-install-venv/lib/python3.11/site-packages/pyop2/global_kernel.py", line 410, in _generate_code_from_global_kernel
    code = lp.generate_code_v2(wrapper)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/miguel/repos/firedrake-pip-install-venv/lib/python3.11/site-packages/loopy/codegen/__init__.py", line 589, in generate_code_v2
    t_unit = linearize(t_unit)
             ^^^^^^^^^^^^^^^^^
  File "/Users/miguel/repos/firedrake-pip-install-venv/lib/python3.11/site-packages/loopy/schedule/__init__.py", line 2466, in linearize
    pre_schedule_checks(t_unit)
  File "/Users/miguel/repos/firedrake-pip-install-venv/lib/python3.11/site-packages/loopy/check.py", line 1313, in pre_schedule_checks
    check_has_schedulable_iname_nesting(t_unit)
  File "/Users/miguel/repos/firedrake-pip-install-venv/lib/python3.11/site-packages/loopy/translation_unit.py", line 765, in _collective_check
    check(clbl.subkernel, *args, **kwargs)
  File "/Users/miguel/repos/firedrake-pip-install-venv/lib/python3.11/site-packages/loopy/check.py", line 984, in check_has_schedulable_iname_nesting
    raise LoopyError("Kernel does not have a schedulable iname nesting. "
loopy.diagnostic.LoopyError: Kernel does not have a schedulable iname nesting. In order for there to exist a feasible loop nesting, you may need to duplicate an iname. To do so, call loopy.duplicate_iname. Use loopy.get_iname_duplication_options to get hints about which iname to duplicate. Here are some options:
* Duplicate k1_23 within instructions (id:insn_657 or id:insn_658 or id:insn_659 or id:insn_660)
* Duplicate k1_23 within instructions (id:insn_661 or id:insn_662 or id:insn_663 or id:insn_664 or id:insn_665 or id:insn_666 or id:insn_667 or id:insn_668 or id:insn_669 or id:insn_670 or id:insn_671 or id:insn_672 or id:insn_673 or id:insn_674 or id:insn_675 or id:insn_676 or id:insn_677 or id:insn_678 or id:insn_679 or id:insn_680 or id:insn_681 or id:insn_682 or id:insn_683 or id:insn_684 or id:insn_685 or id:insn_686 or id:insn_687 or id:insn_688 or id:insn_689 or id:insn_690 or id:insn_691 or id:insn_692 or id:insn_693 or id:insn_694 or id:insn_695 or id:insn_696)
* Duplicate k1_14 within instructions (id:insn_469 or id:insn_470 or id:insn_471 or id:insn_472 or id:insn_473 or id:insn_474 or id:insn_475 or id:insn_476)
* 

Environment:

  • OS: Mac OS [eg: Linux, MacOS, WSL (Windows Subsystem for Linux)] add this as a label too!
  • Python version: Python 3.11.8 [eg: 3.9.7]
  • Output of pip list
pip list

Package Version Editable project location


alabaster 1.0.0
annotated-types 0.7.0
appdirs 1.4.4
argparse-dataclass 2.0.0
asttokens 3.0.0
attrs 25.3.0
babel 2.17.0
black 24.8.0
cachetools 6.1.0
cattrs 25.2.0
certifi 2025.6.15
cfgv 3.4.0
cgen 2025.1
charset-normalizer 3.4.2
checkpoint_schedules 1.0.4
cht_solver 0.1.0 /Users/miguel/work/3d-cht-solver
click 8.2.1
codepy 2025.1
colorama 0.4.6
conda-inject 1.3.2
ConfigArgParse 1.7.1
connection_pool 0.0.3
constantdict 2025.2
contourpy 1.3.2
coverage 7.9.1
cycler 0.12.1
Cython 3.1.3
decorator 4.4.2
defusedxml 0.7.1
distlib 0.3.9
docutils 0.21.2
dpath 2.2.0
execnet 2.1.1
executing 2.2.0
fastjsonschema 2.21.2
fenics-ufl 2025.1.0
filelock 3.18.0
firedrake 2025.4.2
firedrake-fiat 2025.4.0
flake8 7.1.1
flake8-builtins 1.5.2
flake8-docstrings 1.6.0
flexcache 0.3
flexparser 0.4
fonttools 4.58.4
genpy 2022.1
gitdb 4.0.12
GitPython 3.1.41
glaciercore 0.10.1.dev16 /Users/miguel/work/glaciercore
gmsh 4.11.1
h5py 3.14.0
humanfriendly 10.0
identify 2.6.12
idna 3.10
ImageHash 4.3.1
imageio 2.37.0
imagesize 1.4.1
immutabledict 4.2.1
immutables 0.21
iniconfig 2.1.0
ipython 9.3.0
ipython_pygments_lexers 1.1.1
islpy 2025.2.5
isort 5.10.1
jedi 0.19.2
Jinja2 3.1.6
jsonschema 4.25.1
jsonschema-specifications 2025.9.1
jupyter_core 5.8.1
kiwisolver 1.4.8
lazy_loader 0.4
libsupermesh 2025.3.0
libtmux 0.46.2
loopy 2025.1
Mako 1.3.10
markdown-it-py 3.0.0
MarkupSafe 3.0.2
matplotlib 3.10.0
matplotlib-inline 0.1.7
mccabe 0.7.0
mdurl 0.1.2
memory-profiler 0.61.0
meshio 5.3.5
mistune 3.1.3
mpi-pytest 2025.6.0
mpi4py 4.0.3
mpmath 1.3.0
mypy 1.17.1
mypy_extensions 1.1.0
nbformat 5.10.4
networkx 3.5
nodeenv 1.9.1
numexpr 2.11.0
numpy 2.2.3
opencv-contrib-python 4.11.0.86
packaging 25.0
parso 0.8.4
pathspec 0.12.1
petsc4py 3.23.4
pexpect 4.9.0
pillow 11.2.1
Pint 0.25
pip 24.0
pkgconfig 1.5.5
platformdirs 4.3.8
pluggy 1.6.0
polars 1.31.0
pre_commit 4.2.0
progress 1.6
prompt_toolkit 3.0.51
psutil 7.0.0
ptyprocess 0.7.0
pudb 2025.1
PuLP 3.3.0
pure_eval 0.2.3
py 1.11.0
py-spy 0.4.0
pyadjoint-ad 2025.4.1
pycodestyle 2.12.1
pycparser 2.22
pydantic 2.11.7
pydantic_core 2.33.2
pydocstyle 6.3.0
pyflakes 3.2.0
Pygments 2.19.2
pyinstrument 5.0.3
pymbolic 2024.2.2
pyparsing 3.2.3
pyproject-toml 0.1.0
pytest 8.3.4
pytest-cov 6.2.1
pytest-forked 1.6.0
pytest-mpi 0.1
pytest-proceed 0.1.5
pytest-pudb 0.7.0
pytest-split 0.10.0
pytest-timeout 2.3.1
pytest-xdist 3.7.0
python-dateutil 2.9.0.post0
pytools 2024.1.16
PyWavelets 1.8.0
PyYAML 6.0.2
rdp 0.8
recursivenodes 0.2.0
referencing 0.36.2
requests 2.32.4
reretry 0.11.8
rich 14.1.0
rpds-py 0.27.1
rtree 1.4.0
ruff 0.12.1
scikit-image 0.25.1
scipy 1.15.3
setuptools 80.9.0
setuptools-scm 8.3.1
shapely 2.1.1
siphash24 1.7
six 1.17.0
slepc 3.23.1
slepc4py 3.23.2
smart_open 7.3.1
smmap 5.0.2
snakemake 9.11.7
snakemake-interface-common 1.22.0
snakemake-interface-executor-plugins 9.3.9
snakemake-interface-logger-plugins 2.0.0
snakemake-interface-report-plugins 1.2.0
snakemake-interface-scheduler-plugins 2.0.1
snakemake-interface-storage-plugins 4.2.3
snowballstemmer 3.0.1
Sphinx 8.0.2
sphinx-autodoc-typehints 2.5.0
sphinx-click 6.0.0
sphinx_mdinclude 0.6.2
sphinx-rtd-theme 3.0.1
sphinxcontrib-applehelp 2.0.0
sphinxcontrib-devhelp 2.0.0
sphinxcontrib-htmlhelp 2.1.0
sphinxcontrib-jquery 4.1
sphinxcontrib-jsmath 1.0.1
sphinxcontrib-qthelp 2.0.0
sphinxcontrib-serializinghtml 2.0.0
SQLAlchemy 2.0.41
sqlmodel 0.0.22
stack-data 0.6.3
symengine 0.14.1
sympy 1.14.0
tabulate 0.9.0
throttler 1.2.2
tifffile 2025.6.11
tmux-mpi 1.0
toml 0.10.2
traitlets 5.14.3
types-Pillow 10.2.0.20240822
typing_extensions 4.14.0
typing-inspection 0.4.1
urllib3 2.5.0
urwid 3.0.2
urwid_readline 0.15.1
virtualenv 20.31.2
vtk 9.4.1
wcwidth 0.2.13
wheel 0.45.1
wrapt 1.17.3
yamllint 1.37.0
yte 1.9.0
zebraflow 0.1.0 /Users/miguel/work/zebraflow

- Any relevant environment variables or modifications [eg: PYOP2_DEBUG=1]

Additional Info
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions