conda-forge / fenics-feedstock

A conda-smithy repository for fenics.
BSD 3-Clause "New" or "Revised" License
13 stars 12 forks source link

Can't run in readthedocs #204

Closed RemDelaporteMathurin closed 5 months ago

RemDelaporteMathurin commented 5 months ago

Hi @minrk we have a jupyterbook project where we install fenics with conda.

Two days ago it worked fine and today we started noticing errors in the read the docs build.

It seems to be a JIT problem:

------------------- Start compiler output ------------------------
/usr/bin/ld: cannot find /lib64/libpthread.so.0: No such file or directory
/usr/bin/ld: cannot find /usr/lib64/libpthread_nonshared.a: No such file or directory
collect2: error: ld returned 1 exit status
-------------------  End compiler output  ------------------------
Compilation failed! Sources, command, and errors have been written to: /home/docs/checkouts/readthedocs.org/user_builds/festim-vv-report/checkouts/35/report/validation/plasma-driven-permeation/jitfailure-dolfin_expression_a3e880d7e745db7ff656246e44892686

I see there have been changes recently to this repo, could this be related?

Thanks!

Full error message:

---------------------------------------------------------------------------
DijitsoError                              Traceback (most recent call last)
File ~/checkouts/readthedocs.org/user_builds/festim-vv-report/conda/35/lib/python3.11/site-packages/dolfin/jit/jit.py:165, in compile_class(cpp_data, mpi_comm)
    164 try:
--> 165     module, signature = dijitso_jit(cpp_data, module_name, params,
    166                                     generate=cpp_data['jit_generate'],
    167                                     mpi_comm=mpi_comm)
    168     submodule = dijitso.extract_factory_function(module, "create_" + module_name)()

File ~/checkouts/readthedocs.org/user_builds/festim-vv-report/conda/35/lib/python3.11/site-packages/dolfin/jit/jit.py:47, in mpi_jit_decorator.<locals>.mpi_jit(*args, **kwargs)
     46 if MPI.size(mpi_comm) == 1:
---> 47     return local_jit(*args, **kwargs)
     49 # Default status (0 == ok, 1 == fail)

File ~/checkouts/readthedocs.org/user_builds/festim-vv-report/conda/35/lib/python3.11/site-packages/dolfin/jit/jit.py:103, in dijitso_jit(*args, **kwargs)
    101 @mpi_jit_decorator
    102 def dijitso_jit(*args, **kwargs):
--> 103     return dijitso.jit(*args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/festim-vv-report/conda/35/lib/python3.11/site-packages/dijitso/jit.py:216, in jit(jitable, name, params, generate, send, receive, wait)
    214 if err_info:
    215     # TODO: Parse output to find error(s) for better error messages
--> 216     raise DijitsoError("Dijitso JIT compilation failed, see '%s' for details"
    217                        % err_info['fail_dir'], err_info)
    219 # Return built library and its signature

DijitsoError: Dijitso JIT compilation failed, see '/home/docs/checkouts/readthedocs.org/user_builds/festim-vv-report/checkouts/35/report/validation/plasma-driven-permeation/jitfailure-dolfin_expression_a3e880d7e745db7ff656246e44892686' for details

During handling of the above exception, another exception occurred:

RuntimeError                              Traceback (most recent call last)
Cell In[3], line 39
     19 my_model.boundary_conditions = [
     20     F.RecombinationFlux(
     21         Kr_0=1.0e-27 * (1.0 - 0.9999 * sp.exp(-6.0e-5 * F.t)),
   (...)
     26     F.RecombinationFlux(Kr_0=2.0e-31, E_Kr=0, surfaces=[2], order=2),
     27 ]
     29 flux = sp.Piecewise(
     30     (4.9e19, F.t < 5820),
     31     (0, F.t < 9060),
   (...)
     36     (0, True),
     37 )
     38 my_model.sources = [
---> 39     F.ImplantationFlux(flux=flux, imp_depth=12e-9, width=2.4e-9, volume=1)
     40 ]
     42 my_model.T = F.Temperature(500)  # ignored here
     44 left_flux = F.SurfaceFlux(surface=1, field="solute")

File ~/checkouts/readthedocs.org/user_builds/festim-vv-report/conda/35/lib/python3.11/site-packages/festim/sources/source_implantation_flux.py:42, in ImplantationFlux.__init__(self, flux, imp_depth, width, volume)
     36 distribution = (
     37     1
     38     / (self.width * (2 * np.pi) ** 0.5)
     39     * sp.exp(-0.5 * ((x - self.imp_depth) / self.width) ** 2)
     40 )
     41 value = self.flux * distribution
---> 42 super().__init__(value, volume, field="0")

File ~/checkouts/readthedocs.org/user_builds/festim-vv-report/conda/35/lib/python3.11/site-packages/festim/sources/source.py:31, in Source.__init__(self, value, volume, field)
     29     self.value = Constant(value)
     30 elif isinstance(value, sp.Expr):
---> 31     self.value = Expression(sp.printing.ccode(value), t=0, degree=2)
     32 elif isinstance(value, (Expression, UserExpression, Function)):
     33     self.value = value

File ~/checkouts/readthedocs.org/user_builds/festim-vv-report/conda/35/lib/python3.11/site-packages/dolfin/function/expression.py:400, in Expression.__init__(self, cpp_code, *args, **kwargs)
    397         if not isinstance(k, str):
    398             raise KeyError("User parameter key must be a string")
--> 400     self._cpp_object = jit.compile_expression(cpp_code, params)
    401     self._parameters = ExpressionParameters(self._cpp_object, params)
    403 if element and degree:

File ~/checkouts/readthedocs.org/user_builds/festim-vv-report/conda/35/lib/python3.11/site-packages/dolfin/function/jit.py:158, in compile_expression(statements, properties)
    154 mpi_comm = properties.pop("mpi_comm", MPI.comm_world)
    155 cpp_data = {'statements': statements, 'properties': properties,
    156             'name': 'expression', 'jit_generate': jit_generate}
--> 158 expression = compile_class(cpp_data, mpi_comm=mpi_comm)
    159 return expression

File ~/checkouts/readthedocs.org/user_builds/festim-vv-report/conda/35/lib/python3.11/site-packages/dolfin/jit/jit.py:170, in compile_class(cpp_data, mpi_comm)
    168     submodule = dijitso.extract_factory_function(module, "create_" + module_name)()
    169 except Exception:
--> 170     raise RuntimeError("Unable to compile C++ code with dijitso")
    172 if name == 'expression':
    173     python_object = cpp.function.make_dolfin_expression(submodule)

RuntimeError: Unable to compile C++ code with dijitso
RemDelaporteMathurin commented 5 months ago

I found this post that seems related

minrk commented 5 months ago

Almost certainly related to the updates since I saw the same error during the update process. I'm not sure why you are seeing it when it was fixed in the test env, though. The build was fixed with patches to the pkgconfig files to make sure sysroot is in the library search path.

Can you tell if the conda env is fully activated in your build environment? (LDFLAGS, CFLAGS, etc. will be set)

RemDelaporteMathurin commented 5 months ago

Can you tell if the conda env is fully activated in your build environment? (LDFLAGS, CFLAGS, etc. will be set)

I'm not sure I know how to do this. Is there a way to do it/see it in RTD?

I forgot to mention that everything works fine locally

RemDelaporteMathurin commented 5 months ago

@minrk I tried to run echo commands but didn't seem to work.

[rtd-command-info] start-time: 2024-06-24T17:58:29.212405Z, end-time: 2024-06-24T17:58:29.722207Z, duration: 0, exit-code: 0
jupyter-book config sphinx report/
Wrote conf.py to /home/docs/checkouts/readthedocs.org/user_builds/festim-vv-report/checkouts/35/report

[rtd-command-info] start-time: 2024-06-24T17:58:29.749937Z, end-time: 2024-06-24T17:58:29.811225Z, duration: 0, exit-code: 0
echo $LDFLAGS

[rtd-command-info] start-time: 2024-06-24T17:58:29.836619Z, end-time: 2024-06-24T17:58:29.898664Z, duration: 0, exit-code: 0
echo $CFLAGS

[rtd-command-info] start-time: 2024-06-24T17:58:30.251163Z, end-time: 2024-06-24T17:58:30.316216Z, duration: 0, exit-code: 0
cat report/conf.py
minrk commented 5 months ago

If echo doesn't work, you could get and print the env in your notebooks that are currently erroring via os.environ

RemDelaporteMathurin commented 5 months ago

this is the output of print(os.environ)

environ({'READTHEDOCS_CANONICAL_URL': 'https://festim-vv-report--35.org.readthedocs.build/en/35/', 'HOSTNAME': 'build-24797483-project-1052576-festim-vv-report', 'READTHEDOCS_GIT_CLONE_URL': 'https://github.com/festim-dev/V-V-report', 'HOME': '/home/docs', 'NO_COLOR': '1', 'READTHEDOCS': 'True', 'CONDA_ENVS_PATH': '/home/docs/checkouts/readthedocs.org/user_builds/festim-vv-report/conda', 'READTHEDOCS_PROJECT': 'festim-vv-report', 'READTHEDOCS_OUTPUT': '/home/docs/checkouts/readthedocs.org/user_builds/festim-vv-report/checkouts/35/_readthedocs/', 'PATH': '/home/docs/checkouts/readthedocs.org/user_builds/festim-vv-report/conda/35/bin:/home/docs/.asdf/shims:/home/docs/.asdf/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', 'READTHEDOCS_VERSION_TYPE': 'external', 'LANG': 'C.UTF-8', 'READTHEDOCS_LANGUAGE': 'en', 'DEBIAN_FRONTEND': 'noninteractive', 'READTHEDOCS_GIT_COMMIT_HASH': '5e2a695677157167b9dd4292e08b3169d770bf5b', 'READTHEDOCS_VERSION_NAME': '35', 'CONDA_DEFAULT_ENV': '35', 'READTHEDOCS_VERSION': '35', 'PWD': '/home/docs/checkouts/readthedocs.org/user_builds/festim-vv-report/checkouts/35/report', 'READTHEDOCS_GIT_IDENTIFIER': '5e2a695677157167b9dd4292e08b3169d770bf5b', 'DOCUTILSCONFIG': '/home/docs/checkouts/readthedocs.org/user_builds/festim-vv-report/checkouts/35/report/docutils.conf', 'JPY_PARENT_PID': '2897', 'PYDEVD_USE_FRAME_EVAL': 'NO', 'TERM': 'xterm-color', 'CLICOLOR': '1', 'FORCE_COLOR': '1', 'CLICOLOR_FORCE': '1', 'PAGER': 'cat', 'GIT_PAGER': 'cat', 'MPLBACKEND': 'module://matplotlib_inline.backend_inline'})
minrk commented 5 months ago

Yeah, that means the activation script isn't running (I.e. conda activate envname).

The easiest workaround is probably to set LDFLAGS yourself, if properly activating the env is not an option, but I bet I can try to get whatever the missing one(s) in the default flags.

minrk commented 5 months ago

Does it work if you add the package gxx to the environment? My guess is that a system compiler is used, which won't work, but the gxx package is absent, which provides the default c++ executable.

minrk commented 5 months ago

I'm pretty confident #205 will fix this which means you should be able to fix it by adding gxx to your environment.

I can reproduce the problem in quay.io/condaforge/miniforge3 with:

mamba create -n dolfin fenics-dolfin mpich matplotlib-base
apt-get -y update; apt-get -y install g++ # install system compiler
# add env to PATH without activating it
export PATH=/opt/conda/envs/dolfin/bin:$PATH
python3 demo_poisson.py
# fails with 
/usr/bin/ld: cannot find /lib64/libpthread.so.0
/usr/bin/ld: cannot find /usr/lib64/libpthread_nonshared.a
collect2: error: ld returned 1 exit status

mamba install -n dolfin gxx
python3 demo_poisson.py  # succeeds

This doesn't come up for properly activated environments because the activation scripts set $CXX, so the default c++ executable is not used.

RemDelaporteMathurin commented 5 months ago

Yes I confirm this fixed it! https://festim-vv-report--35.org.readthedocs.build/en/35/verification/mms/simple.html

minrk commented 5 months ago

Great! I'm not sure what changed that caused this to start failing, but good to know it's fixed. The next build will include the missing dependency on gxx.