conda-forge / casadi-feedstock

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

ipopt with spral linear solver fails with casadi Python bindings as OMP_ variables are not forwarded to libgomp opened with RTLD_DEEPBIND #93

Closed traversaro closed 11 months ago

traversaro commented 11 months ago

Solution to issue cannot be found in the documentation.

Issue

On Linux:

mamba create -n casadi casadi
mamba activate casadi
wget https://gist.githubusercontent.com/traversaro/87df0563bb5e599e76599b00bf142eec/raw/04742605106b721fa13a390eef3280a31919c29d/ipopt_nl_spral.py
# see https://github.com/ralna/spral/tree/v2023.09.07#usage-at-a-glance
export OMP_CANCELLATION=TRUE
export OMP_PROC_BIND=TRUE
python ipopt_nl_spral.py

this fails with:

(casadi) traversaro@IITICUBLAP257:~/isaacws/isaac-wp1-5$ python ipopt_nl.py

******************************************************************************
This program contains Ipopt, a library for large-scale nonlinear optimization.
 Ipopt is released as open source code under the Eclipse Public License (EPL).
         For more information visit https://github.com/coin-or/Ipopt
******************************************************************************

This is Ipopt version 3.14.12, running with linear solver spral.

Number of nonzeros in equality constraint Jacobian...:        0
Number of nonzeros in inequality constraint Jacobian.:        2
Number of nonzeros in Lagrangian Hessian.............:        2

In SpralSolverInterface::Factorization: Unhandled error. info.flag = -53.
Maybe one forgot to set environment variable OMP_CANCELLATION to TRUE.
Set spral_print_level=0 to see more details.
Total number of variables............................:        2
                     variables with only lower bounds:        0
                variables with lower and upper bounds:        0
                     variables with only upper bounds:        0
Total number of equality constraints.................:        0
Total number of inequality constraints...............:        1
        inequality constraints with only lower bounds:        1
   inequality constraints with lower and upper bounds:        0
        inequality constraints with only upper bounds:        0

iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
   0  0.0000000e+00 1.00e+01 1.00e+00  -1.0 0.00e+00    -  0.00e+00 0.00e+00   0
In SpralSolverInterface::Factorization: Unhandled error. info.flag = -53.
Maybe one forgot to set environment variable OMP_CANCELLATION to TRUE.
Set spral_print_level=0 to see more details.
WARNING: Problem in step computation; switching to emergency mode.
   1r 0.0000000e+00 1.00e+01 9.99e+02   1.0 0.00e+00    -  0.00e+00 0.00e+00R  1
In SpralSolverInterface::Factorization: Unhandled error. info.flag = -53.
Maybe one forgot to set environment variable OMP_CANCELLATION to TRUE.
Set spral_print_level=0 to see more details.
WARNING: Problem in step computation; switching to emergency mode.
Cannot call restoration phase at point that is almost feasible for the restoration NLP (violation 0.000000e+00).
Abort in line search due to no other fall back.
Step computation in the restoration phase failed.

Number of Iterations....: 1

                                   (scaled)                 (unscaled)
Objective...............:   0.0000000000000000e+00    0.0000000000000000e+00
Dual infeasibility......:   1.0000000000000000e+00    1.0000000000000000e+00
Constraint violation....:   9.9999999899999992e+00    9.9999999899999992e+00
Variable bound violation:   0.0000000000000000e+00    0.0000000000000000e+00
Complementarity.........:   1.0000000000000000e-02    1.0000000000000000e-02
Overall NLP error.......:   9.9999999899999992e+00    9.9999999899999992e+00

Number of objective function evaluations             = 2
Number of objective gradient evaluations             = 2
Number of equality constraint evaluations            = 0
Number of inequality constraint evaluations          = 2
Number of equality constraint Jacobian evaluations   = 0
Number of inequality constraint Jacobian evaluations = 2
Number of Lagrangian Hessian evaluations             = 2
Total seconds in IPOPT                               = 0.030

EXIT: Restoration Failed!
      solver  :   t_proc      (avg)   t_wall      (avg)    n_eval
       nlp_f  |   6.00us (  3.00us)   5.96us (  2.98us)         2
       nlp_g  |   4.00us (  2.00us)   4.55us (  2.27us)         2
  nlp_grad_f  |  12.00us (  4.00us)  10.62us (  3.54us)         3
  nlp_hess_l  |   1.00us (  1.00us)   1.08us (  1.08us)         1
   nlp_jac_g  |   2.00us (666.67ns)   2.60us (866.67ns)         3
       total  |  26.06ms ( 26.06ms)  30.68ms ( 30.68ms)         1
-----
Traceback (most recent call last):
  File "/home/traversaro/isaacws/isaac-wp1-5/ipopt_nl.py", line 26, in <module>
    assert np.allclose(sol["f"], 50)
AssertionError

This is due to P1 described in https://github.com/conda-forge/ctng-compilers-feedstock/issues/114#issuecomment-1719077104 .

Installed packages

mamb(isaacenv) traversaro@IITICUBLAP257:~/isaacws/isaac-wp1-5$ mamba list
# packages in environment at /home/traversaro/micromamba/envs/isaacenv:
#
# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                 conda_forge    conda-forge
_openmp_mutex             4.5                       2_gnu    conda-forge
ace                       7.1.1                h59595ed_0    conda-forge
adam-robotics             0.0.7              pyh6074d0b_0    conda-forge
alsa-lib                  1.2.9                hd590300_0    conda-forge
ampl-mp                   3.1.0             h2cc385e_1006    conda-forge
aom                       3.5.0                h27087fc_0    conda-forge
assimp                    5.2.5                hf40c2ba_0    conda-forge
asttokens                 2.4.0              pyhd8ed1ab_0    conda-forge
atk-1.0                   2.38.0               hd4edc92_1    conda-forge
attr                      2.5.1                h166bdaf_1    conda-forge
aws-c-auth                0.7.3                he2921ad_3    conda-forge
aws-c-cal                 0.6.2                hc309b26_1    conda-forge
aws-c-common              0.9.0                hd590300_0    conda-forge
aws-c-compression         0.2.17               h4d4d85c_2    conda-forge
aws-c-event-stream        0.3.2                h2e3709c_0    conda-forge
aws-c-http                0.7.12               hc865f51_1    conda-forge
aws-c-io                  0.13.32              h1a03231_3    conda-forge
aws-c-mqtt                0.9.5                h3a0376c_1    conda-forge
aws-c-s3                  0.3.17               h1678ad6_0    conda-forge
aws-c-sdkutils            0.1.12               h4d4d85c_1    conda-forge
aws-checksums             0.1.17               h4d4d85c_1    conda-forge
aws-crt-cpp               0.23.1               hffbee3f_1    conda-forge
aws-sdk-cpp               1.10.57             h8bde0db_22    conda-forge
backcall                  0.2.0              pyh9f0ad1d_0    conda-forge
backports                 1.0                pyhd8ed1ab_3    conda-forge
backports.functools_lru_cache 1.6.5              pyhd8ed1ab_0    conda-forge
binutils                  2.40                 hdd6e379_0    conda-forge
binutils_impl_linux-64    2.40                 hf600244_0    conda-forge
binutils_linux-64         2.40                 hbdbef99_2    conda-forge
black                     23.9.1          py310hff52083_0    conda-forge
blockfactory              0.8.3               h59595ed_96    robotology
blosc                     1.21.5               h0f2a231_0    conda-forge
boost-cpp                 1.78.0               h6582d0a_3    conda-forge
bottle                    0.12.23            pyhd8ed1ab_0    conda-forge
brotli                    1.1.0                hd590300_0    conda-forge
brotli-bin                1.1.0                hd590300_0    conda-forge
bullet-cpp                3.24                 h769672d_0    conda-forge
bzip2                     1.0.8                h7f98852_4    conda-forge
c-ares                    1.19.1               hd590300_0    conda-forge
c-compiler                1.6.0                hd590300_0    conda-forge
ca-certificates           2023.7.22            hbcca054_0    conda-forge
cairo                     1.16.0            hbbf8b49_1016    conda-forge
casadi                    3.6.3           py310h528c296_0    conda-forge
casadi-matlab-bindings    3.6.3.0             h59595ed_96    robotology
certifi                   2023.7.22          pyhd8ed1ab_0    conda-forge
cfitsio                   4.3.0                hbdc6101_0    conda-forge
click                     8.1.7           unix_pyh707e725_0    conda-forge
cmake                     3.27.6               hcfe8598_0    conda-forge
colorama                  0.4.6              pyhd8ed1ab_0    conda-forge
coloredlogs               15.0.1             pyhd8ed1ab_3    conda-forge
compilers                 1.6.0                ha770c72_0    conda-forge
console_bridge            1.0.2                h924138e_1    conda-forge
contourpy                 1.1.1           py310hd41b1e2_0    conda-forge
cppzmq                    4.10.0               h7e20d1c_0    conda-forge
cxx-compiler              1.6.0                h00ab1b0_0    conda-forge
cycler                    0.11.0             pyhd8ed1ab_0    conda-forge
cython                    0.29.36         py310hc6cd4ac_1    conda-forge
dartsim                   6.13.0               h57047b8_2    conda-forge
dav1d                     1.2.1                hd590300_0    conda-forge
dbus                      1.13.6               h5008d03_3    conda-forge
decorator                 5.1.1              pyhd8ed1ab_0    conda-forge
eigen                     3.4.0                h00ab1b0_0    conda-forge
exceptiongroup            1.1.3              pyhd8ed1ab_0    conda-forge
executing                 1.2.0              pyhd8ed1ab_0    conda-forge
expat                     2.5.0                hcb278e6_1    conda-forge
fcl                       0.7.0                hdebe893_2    conda-forge
ffmpeg                    6.0.0           gpl_h14e97fc_104    conda-forge
flann                     1.9.1             h941a29b_1013    conda-forge
fmt                       10.1.1               h00ab1b0_0    conda-forge
font-ttf-dejavu-sans-mono 2.37                 hab24e00_0    conda-forge
font-ttf-inconsolata      3.000                h77eed37_0    conda-forge
font-ttf-source-code-pro  2.038                h77eed37_0    conda-forge
font-ttf-ubuntu           0.83                 hab24e00_0    conda-forge
fontconfig                2.14.2               h14ed4e7_0    conda-forge
fonts-conda-ecosystem     1                             0    conda-forge
fonts-conda-forge         1                             0    conda-forge
fonttools                 4.42.1          py310h2372a71_0    conda-forge
fortran-compiler          1.6.0                heb67821_0    conda-forge
freeglut                  3.2.2                hac7e632_2    conda-forge
freeimage                 3.18.0              h0da0bed_16    conda-forge
freetype                  2.12.1               h267a509_2    conda-forge
freexl                    1.0.6                h166bdaf_1    conda-forge
fribidi                   1.0.10               h36c2ea0_0    conda-forge
gazebo                    11.13.0              hebecd67_4    conda-forge
gcc                       12.3.0               h8d2909c_2    conda-forge
gcc_impl_linux-64         12.3.0               he2b93b0_2    conda-forge
gcc_linux-64              12.3.0               h76fc315_2    conda-forge
gdbm                      1.18                 h0a1914f_2    conda-forge
gdk-pixbuf                2.42.10              h6b639ba_2    conda-forge
geos                      3.12.0               h59595ed_0    conda-forge
geotiff                   1.7.1               h22adcc9_11    conda-forge
gettext                   0.21.1               h27087fc_0    conda-forge
gfortran                  12.3.0               h499e0f7_2    conda-forge
gfortran_impl_linux-64    12.3.0               hfcedea8_2    conda-forge
gfortran_linux-64         12.3.0               h7fe76b4_2    conda-forge
giflib                    5.2.1                h0b41bf4_3    conda-forge
glfw                      3.3.8                hd590300_1    conda-forge
glib                      2.78.0               hfc55251_0    conda-forge
glib-tools                2.78.0               hfc55251_0    conda-forge
gmp                       6.2.1                h58526e2_0    conda-forge
gnutls                    3.7.8                hf3e180e_0    conda-forge
graphite2                 1.3.13            h58526e2_1001    conda-forge
graphviz                  8.1.0                h28d9a01_0    conda-forge
gsl                       2.7                  he838d99_0    conda-forge
gst-plugins-base          1.22.5               hf7dbed1_0    conda-forge
gstreamer                 1.22.5               h98fc4e7_0    conda-forge
gtk2                      2.24.33              h90689f9_2    conda-forge
gts                       0.7.6                h977cf35_4    conda-forge
gxx                       12.3.0               h8d2909c_2    conda-forge
gxx_impl_linux-64         12.3.0               he2b93b0_2    conda-forge
gxx_linux-64              12.3.0               h8a814eb_2    conda-forge
harfbuzz                  7.3.0                hdb3a94d_0    conda-forge
hdf4                      4.2.15               h501b40f_6    conda-forge
hdf5                      1.14.1          nompi_h4f84152_100    conda-forge
humanfriendly             10.0            py310hff52083_4    conda-forge
icu                       72.1                 hcb278e6_0    conda-forge
icub-firmware-shared      1.35.0              h59595ed_96    robotology
icub-main                 2.2.1           py310h33d6d23_96    robotology
icub-models               2.3.0           py310hc6cd4ac_0    conda-forge
idyntree                  9.1.0           py310hcc9ab6b_1    conda-forge
idyntree-matlab-bindings  9.1.0               h59595ed_96    robotology
imath                     3.1.9                hfc55251_0    conda-forge
iniconfig                 2.0.0              pyhd8ed1ab_0    conda-forge
ipopt                     3.14.12              he6d3896_1    conda-forge
ipython                   8.15.0             pyh0d859eb_0    conda-forge
irrlicht                  1.8.5                h3749e40_3    conda-forge
isaac-wp1                 6.4                      pypi_0    pypi
isort                     5.12.0             pyhd8ed1ab_1    conda-forge
jasper                    4.0.0                h32699f2_1    conda-forge
jedi                      0.19.0             pyhd8ed1ab_0    conda-forge
json-c                    0.17                 h7ab15ed_0    conda-forge
jsoncpp                   1.9.5                h4bd325d_1    conda-forge
jxrlib                    1.1                  h7f98852_2    conda-forge
kealib                    1.5.1                h3e6883b_4    conda-forge
kernel-headers_linux-64   2.6.32              he073ed8_16    conda-forge
keyutils                  1.6.1                h166bdaf_0    conda-forge
kiwisolver                1.4.5           py310hd41b1e2_0    conda-forge
krb5                      1.21.2               h659d440_0    conda-forge
lame                      3.100             h166bdaf_1003    conda-forge
lcms2                     2.15                 haa2dc70_1    conda-forge
ld_impl_linux-64          2.40                 h41732ed_0    conda-forge
lerc                      4.0.0                h27087fc_0    conda-forge
libabseil                 20230125.3      cxx17_h59595ed_0    conda-forge
libaec                    1.0.6                hcb278e6_1    conda-forge
libarchive                3.6.2                h039dbb9_1    conda-forge
libass                    0.17.1               hc9aadba_0    conda-forge
libblas                   3.9.0           18_linux64_openblas    conda-forge
libbrotlicommon           1.1.0                hd590300_0    conda-forge
libbrotlidec              1.1.0                hd590300_0    conda-forge
libbrotlienc              1.1.0                hd590300_0    conda-forge
libcap                    2.69                 h0f662aa_0    conda-forge
libcblas                  3.9.0           18_linux64_openblas    conda-forge
libccd-double             2.1                  h59595ed_3    conda-forge
libclang                  15.0.7          default_h7634d5b_3    conda-forge
libclang13                15.0.7          default_h9986a30_3    conda-forge
libcups                   2.3.3                h4637d8d_4    conda-forge
libcurl                   8.3.0                hca28451_0    conda-forge
libdc1394                 2.2.7                h59595ed_0    conda-forge
libdeflate                1.18                 h0b41bf4_0    conda-forge
libdrm                    2.4.114              h166bdaf_0    conda-forge
libedit                   3.1.20191231         he28a2e2_2    conda-forge
libev                     4.33                 h516909a_1    conda-forge
libevent                  2.1.12               hf998b51_1    conda-forge
libexpat                  2.5.0                hcb278e6_1    conda-forge
libffi                    3.4.2                h7f98852_5    conda-forge
libflac                   1.4.3                h59595ed_0    conda-forge
libgcc-devel_linux-64     12.3.0               h8bca6fd_2    conda-forge
libgcc-ng                 13.2.0               h807b86a_2    conda-forge
libgcrypt                 1.10.1               h166bdaf_0    conda-forge
libgd                     2.3.3                hfa28ad5_6    conda-forge
libgdal                   3.7.1                hd2ada2b_6    conda-forge
libgfortran-ng            13.2.0               h69a702a_2    conda-forge
libgfortran5              13.2.0               ha4646dd_2    conda-forge
libglib                   2.78.0               hebfc3b9_0    conda-forge
libglu                    9.0.0             hac7e632_1003    conda-forge
libgomp                   13.2.0               h807b86a_2    conda-forge
libgpg-error              1.47                 h71f35ed_0    conda-forge
libhwloc                  2.9.1           nocuda_h7313eea_6    conda-forge
libi2c                    4.3                  hcb278e6_2    conda-forge
libiconv                  1.17                 h166bdaf_0    conda-forge
libidn2                   2.3.4                h166bdaf_0    conda-forge
libignition-cmake2        2.16.0               hcb278e6_1    conda-forge
libignition-common3       3.15.1               h1f55927_2    conda-forge
libignition-fuel-tools4   4.6.0                hf5721fa_2    conda-forge
libignition-math6         6.15.0          py310h64a2142_0    conda-forge
libignition-msgs5         5.11.0               h3189f74_1    conda-forge
libignition-tools1        1.5.0                h1caa08d_3    conda-forge
libignition-transport8    8.4.0                hb139ee8_3    conda-forge
libjpeg-turbo             2.1.5.1              hd590300_1    conda-forge
libkml                    1.3.0             h37653c0_1015    conda-forge
liblapack                 3.9.0           18_linux64_openblas    conda-forge
liblapacke                3.9.0           18_linux64_openblas    conda-forge
libllvm15                 15.0.7               h5cf9203_3    conda-forge
libnetcdf                 4.9.2           nompi_h7e745eb_109    conda-forge
libnghttp2                1.52.0               h61bc06f_0    conda-forge
libnsl                    2.0.0                h7f98852_0    conda-forge
libode                    0.16.2              hd8f1fbe_11    conda-forge
libogg                    1.3.4                h7f98852_1    conda-forge
libopenblas               0.3.24          pthreads_h413a1c8_0    conda-forge
libopencv                 4.7.0           py311h55ebc8a_6    conda-forge
libopus                   1.3.1                h7f98852_1    conda-forge
libosqp                   0.6.3                h59595ed_0    conda-forge
libpciaccess              0.17                 h166bdaf_0    conda-forge
libpng                    1.6.39               h753d276_0    conda-forge
libpq                     15.4                 hfc447b1_0    conda-forge
libprotobuf               4.23.3               hd1fb520_1    conda-forge
libqdldl                  0.1.5                h27087fc_1    conda-forge
libraw                    0.21.1               h501b40f_1    conda-forge
librsvg                   2.56.3               h98fae49_0    conda-forge
librttopo                 1.1.0               hb58d41b_14    conda-forge
libsanitizer              12.3.0               h0f45ef3_2    conda-forge
libsdformat               9.8.0                h5fffb2e_4    conda-forge
libsndfile                1.2.2                hbc2eb40_0    conda-forge
libsodium                 1.0.18               h36c2ea0_1    conda-forge
libspatialite             5.0.1               h15f6e67_28    conda-forge
libspral                  2023.08.02           h2baf039_0    conda-forge
libsqlite                 3.43.0               h2797004_0    conda-forge
libssh2                   1.11.0               h0841786_0    conda-forge
libstdcxx-devel_linux-64  12.3.0               h8bca6fd_2    conda-forge
libstdcxx-ng              13.2.0               h7e041cc_2    conda-forge
libsystemd0               254                  h3516f8a_0    conda-forge
libtar                    1.2.20            h7f98852_1004    conda-forge
libtasn1                  4.19.0               h166bdaf_0    conda-forge
libtiff                   4.5.1                h8b53f26_1    conda-forge
libtool                   2.4.7                h27087fc_0    conda-forge
libudev1                  254                  h3f72095_0    conda-forge
libunistring              0.9.10               h7f98852_0    conda-forge
libusb                    1.0.26             h0b4f0b6_100    conda-forge
libuuid                   2.38.1               h0b41bf4_0    conda-forge
libuv                     1.46.0               hd590300_0    conda-forge
libva                     2.20.0               hd590300_0    conda-forge
libvorbis                 1.3.7                h9c3ff4c_0    conda-forge
libvpx                    1.13.0               hcb278e6_0    conda-forge
libwebp                   1.3.1                hbf2b3c1_0    conda-forge
libwebp-base              1.3.1                hd590300_0    conda-forge
libxcb                    1.15                 h0b41bf4_0    conda-forge
libxkbcommon              1.5.0                h5d7e998_3    conda-forge
libxml2                   2.11.5               h0d562d8_0    conda-forge
libxslt                   1.1.37               h0054252_1    conda-forge
libzip                    1.10.1               h2629f0a_3    conda-forge
libzlib                   1.2.13               hd590300_5    conda-forge
liecasadi                 0.0.5                    pypi_0    pypi
loop-rate-limiters        0.6.0              pyhd8ed1ab_0    conda-forge
lxml                      4.9.3           py310h9b7343a_0    conda-forge
lz4-c                     1.9.4                hcb278e6_0    conda-forge
lzo                       2.10              h516909a_1000    conda-forge
mashumaro                 3.10               pyhd8ed1ab_0    conda-forge
matlab-whole-body-simulator 3.3.0               h59595ed_96    robotology
matplotlib                3.8.0           py310hff52083_0    conda-forge
matplotlib-base           3.8.0           py310h62c0568_0    conda-forge
matplotlib-inline         0.1.6              pyhd8ed1ab_0    conda-forge
meshcat-python            0.3.2              pyhd8ed1ab_0    conda-forge
meshcat-viz               0.1.1                    pypi_0    pypi
metis                     5.1.0             h59595ed_1007    conda-forge
mpg123                    1.31.3               hcb278e6_0    conda-forge
mumps-include             5.2.1               ha770c72_11    conda-forge
mumps-seq                 5.2.1               h2104b81_11    conda-forge
munkres                   1.1.4              pyh9f0ad1d_0    conda-forge
mypy_extensions           1.0.0              pyha770c72_0    conda-forge
mysql-common              8.0.33               hf1915f5_4    conda-forge
mysql-libs                8.0.33               hca2cd23_4    conda-forge
ncurses                   6.4                  hcb278e6_0    conda-forge
nettle                    3.8.1                hc379101_1    conda-forge
ninja                     1.11.1               h924138e_0    conda-forge
nspr                      4.35                 h27087fc_0    conda-forge
nss                       3.92                 h1d7d5a4_0    conda-forge
numpy                     1.26.0          py310hb13e2d6_0    conda-forge
octomap                   1.9.8                h924138e_0    conda-forge
ogre                      1.10.12             h7b21bec_13    conda-forge
openal-soft               1.22.2               h924138e_0    conda-forge
openexr                   3.2.0                h3f0fd8d_0    conda-forge
openh264                  2.3.1                hcb278e6_2    conda-forge
openjpeg                  2.5.0                hfec8fc6_2    conda-forge
openssl                   3.1.3                hd590300_0    conda-forge
osqp-eigen                0.8.0                hdd734ac_1    conda-forge
p11-kit                   0.24.1               hc5aa10d_0    conda-forge
packaging                 23.1               pyhd8ed1ab_0    conda-forge
pandas                    2.1.1           py310hcc13569_0    conda-forge
pango                     1.50.14              heaa33ce_1    conda-forge
parso                     0.8.3              pyhd8ed1ab_0    conda-forge
pathspec                  0.11.2             pyhd8ed1ab_0    conda-forge
pcre2                     10.40                hc3806b6_0    conda-forge
pexpect                   4.8.0              pyh1a96a4e_2    conda-forge
pickleshare               0.7.5                   py_1003    conda-forge
pillow                    10.0.0          py310h582fbeb_0    conda-forge
pip                       23.2.1             pyhd8ed1ab_0    conda-forge
pixman                    0.40.0               h36c2ea0_0    conda-forge
pkg-config                0.29.2            h36c2ea0_1008    conda-forge
pkgconfig                 1.5.5              pyhd8ed1ab_4    conda-forge
platformdirs              3.10.0             pyhd8ed1ab_0    conda-forge
pluggy                    1.3.0              pyhd8ed1ab_0    conda-forge
ply                       3.11                       py_1    conda-forge
poppler                   23.08.0              hd18248d_0    conda-forge
poppler-data              0.4.12               hd8ed1ab_0    conda-forge
portaudio                 19.6.0               h0e77e87_8    conda-forge
postgresql                15.4                 h8972f4a_0    conda-forge
prettytable               3.9.0              pyhd8ed1ab_0    conda-forge
proj                      9.2.1                ha643af7_0    conda-forge
prompt-toolkit            3.0.39             pyha770c72_0    conda-forge
prompt_toolkit            3.0.39               hd8ed1ab_0    conda-forge
proxsuite                 0.3.7           py310hd41b1e2_0    conda-forge
proxy-tools               0.1.0                    pypi_0    pypi
pthread-stubs             0.4               h36c2ea0_1001    conda-forge
ptyprocess                0.7.0              pyhd3deb0d_0    conda-forge
pugixml                   1.13                 h59595ed_1    conda-forge
pulseaudio-client         16.1                 hb77b528_5    conda-forge
pure_eval                 0.2.2              pyhd8ed1ab_0    conda-forge
pybind11-abi              4                    hd8ed1ab_3    conda-forge
pygments                  2.16.1             pyhd8ed1ab_0    conda-forge
pyngrok                   7.0.0              pyhd8ed1ab_0    conda-forge
pyparsing                 3.1.1              pyhd8ed1ab_0    conda-forge
pypng                     0.20220715.0             pypi_0    pypi
pyqt                      5.15.9          py310h04931ad_4    conda-forge
pyqt5-sip                 12.12.2         py310hc6cd4ac_4    conda-forge
pyqtwebengine             5.15.9          py310h704022c_4    conda-forge
pytest                    7.4.2              pyhd8ed1ab_0    conda-forge
python                    3.10.12         hd12c33a_0_cpython    conda-forge
python-dateutil           2.8.2              pyhd8ed1ab_0    conda-forge
python-tzdata             2023.3             pyhd8ed1ab_0    conda-forge
python_abi                3.10                    4_cp310    conda-forge
pytz                      2023.3.post1       pyhd8ed1ab_0    conda-forge
pywebview                 4.3.3                    pypi_0    pypi
pyyaml                    6.0.1           py310h2372a71_0    conda-forge
pyzmq                     25.1.1          py310h5bbb5d0_0    conda-forge
qpoases                   3.2.1           py310h22287dc_2    conda-forge
qt-main                   5.15.8              h7fe3ca9_15    conda-forge
qt-webengine              5.15.8               h92031a0_3    conda-forge
qtpy                      2.4.0              pyhd8ed1ab_0    conda-forge
qwt                       6.2.0                h16b76b2_6    conda-forge
readline                  8.2                  h8228510_1    conda-forge
rhash                     1.4.4                hd590300_0    conda-forge
robot-testing-framework   2.0.1                hcb278e6_1    conda-forge
rod                       0.1                      pypi_0    pypi
ruby                      3.2.2                hff50039_0    conda-forge
s2n                       1.3.51               h06160fa_0    conda-forge
scipy                     1.11.2          py310hb13e2d6_1    conda-forge
scotch                    6.0.9                hb2e6521_2    conda-forge
sdl                       1.2.64               h293081c_0    conda-forge
sdl2                      2.28.3               h77f46ba_0    conda-forge
setuptools                68.2.2             pyhd8ed1ab_0    conda-forge
simbody                   3.7                  h64f3f5a_3    conda-forge
simde                     0.7.6                h00ab1b0_0    conda-forge
sip                       6.7.11          py310hc6cd4ac_0    conda-forge
six                       1.16.0             pyh6c4a22f_0    conda-forge
snappy                    1.1.10               h9fff704_0    conda-forge
soxr                      0.1.3                h0b41bf4_3    conda-forge
spdlog                    1.12.0               hd2e6256_1    conda-forge
sqlite                    3.43.0               h2c6b66d_0    conda-forge
stack_data                0.6.2              pyhd8ed1ab_0    conda-forge
svt-av1                   1.7.0                h59595ed_0    conda-forge
swig                      4.1.1                he155508_1    conda-forge
sysroot_linux-64          2.12                he073ed8_16    conda-forge
tbb                       2021.9.0             hf52228f_0    conda-forge
tbb-devel                 2021.9.0             hf52228f_0    conda-forge
tiledb                    2.16.3               hf0b6e87_3    conda-forge
tinyxml                   2.6.2                h4bd325d_2    conda-forge
tinyxml2                  9.0.0                h9c3ff4c_2    conda-forge
tk                        8.6.12               h27826a3_0    conda-forge
toml                      0.10.2             pyhd8ed1ab_0    conda-forge
tomli                     2.0.1              pyhd8ed1ab_0    conda-forge
tornado                   6.3.3           py310h2372a71_0    conda-forge
traitlets                 5.10.0             pyhd8ed1ab_0    conda-forge
typing-extensions         4.8.0                hd8ed1ab_0    conda-forge
typing_extensions         4.8.0              pyha770c72_0    conda-forge
tzcode                    2023c                h0b41bf4_0    conda-forge
tzdata                    2023c                h71feb2d_0    conda-forge
u-msgpack-python          2.8.0              pyhd8ed1ab_0    conda-forge
unicodedata2              15.0.0          py310h5764c6d_0    conda-forge
unixodbc                  2.3.12               h661eb56_0    conda-forge
urdf-parser-py            0.0.4              pyhd8ed1ab_0    conda-forge
urdfdom                   3.1.1                h8a9b4ce_0    conda-forge
urdfdom-py                1.2.1           py310hff52083_2    conda-forge
urdfdom_headers           1.1.0                h924138e_0    conda-forge
wb-toolbox                5.6.0               h59595ed_96    robotology
wcwidth                   0.2.6              pyhd8ed1ab_0    conda-forge
wheel                     0.41.2             pyhd8ed1ab_0    conda-forge
x264                      1!164.3095           h166bdaf_2    conda-forge
x265                      3.5                  h924138e_3    conda-forge
xcb-util                  0.4.0                hd590300_1    conda-forge
xcb-util-image            0.4.0                h8ee46fc_1    conda-forge
xcb-util-keysyms          0.4.0                h8ee46fc_1    conda-forge
xcb-util-renderutil       0.3.9                hd590300_1    conda-forge
xcb-util-wm               0.4.1                h8ee46fc_1    conda-forge
xerces-c                  3.2.4                h8d71039_2    conda-forge
xkeyboard-config          2.39                 hd590300_0    conda-forge
xmltodict                 0.13.0             pyhd8ed1ab_0    conda-forge
xorg-compositeproto       0.4.2             h7f98852_1001    conda-forge
xorg-damageproto          1.2.1             h7f98852_1002    conda-forge
xorg-fixesproto           5.0               h7f98852_1002    conda-forge
xorg-inputproto           2.3.2             h7f98852_1002    conda-forge
xorg-kbproto              1.0.7             h7f98852_1002    conda-forge
xorg-libice               1.1.1                hd590300_0    conda-forge
xorg-libsm                1.2.4                h7391055_0    conda-forge
xorg-libx11               1.8.6                h8ee46fc_0    conda-forge
xorg-libxau               1.0.11               hd590300_0    conda-forge
xorg-libxaw               1.0.14               h7f98852_1    conda-forge
xorg-libxcomposite        0.4.6                h0b41bf4_1    conda-forge
xorg-libxcursor           1.2.0                h0b41bf4_1    conda-forge
xorg-libxdamage           1.1.5                h7f98852_1    conda-forge
xorg-libxdmcp             1.1.3                h7f98852_0    conda-forge
xorg-libxext              1.3.4                h0b41bf4_2    conda-forge
xorg-libxfixes            5.0.3             h7f98852_1004    conda-forge
xorg-libxi                1.7.10               h7f98852_0    conda-forge
xorg-libxinerama          1.1.5                h27087fc_0    conda-forge
xorg-libxmu               1.1.3                h7f98852_0    conda-forge
xorg-libxpm               3.5.16               hd590300_0    conda-forge
xorg-libxrandr            1.5.2                h7f98852_1    conda-forge
xorg-libxrender           0.9.11               hd590300_0    conda-forge
xorg-libxt                1.3.0                hd590300_1    conda-forge
xorg-libxtst              1.2.3             h7f98852_1002    conda-forge
xorg-randrproto           1.5.0             h7f98852_1001    conda-forge
xorg-recordproto          1.14.2            h7f98852_1002    conda-forge
xorg-renderproto          0.11.1            h7f98852_1002    conda-forge
xorg-util-macros          1.19.3               h7f98852_0    conda-forge
xorg-xextproto            7.3.0             h0b41bf4_1003    conda-forge
xorg-xf86vidmodeproto     2.3.1             h7f98852_1002    conda-forge
xorg-xproto               7.0.31            h7f98852_1007    conda-forge
xz                        5.2.6                h166bdaf_0    conda-forge
yaml                      0.2.5                h7f98852_2    conda-forge
yarp-cxx                  3.8.1                h245b40a_3    conda-forge
yarp-matlab-bindings      3.8.0               h59595ed_96    robotology
ycm-cmake-modules         0.15.3               h59595ed_0    conda-forge
zeromq                    4.3.4                h9c3ff4c_1    conda-forge
zlib                      1.2.13               hd590300_5    conda-forge
zstd                      1.5.5                hfc55251_0    conda-forge
zziplib                   0.13.69              h27826a3_1    conda-forge

Environment info

(isaacenv) traversaro@IITICUBLAP257:~/isaacws/isaac-wp1-5$ conda info

     active environment : /home/traversaro/micromamba/envs/isaacenv
    active env location : /home/traversaro/micromamba/envs/isaacenv
            shell level : 1
       user config file : /home/traversaro/.condarc
 populated config files : /home/traversaro/miniforge3/.condarc
                          /home/traversaro/.condarc
          conda version : 23.3.1
    conda-build version : not installed
         python version : 3.10.12.final.0
       virtual packages : __archspec=1=x86_64
                          __cuda=12.2=0
                          __glibc=2.35=0
                          __linux=5.15.123.1=0
                          __unix=0=0
       base environment : /home/traversaro/miniforge3  (writable)
      conda av data dir : /home/traversaro/miniforge3/etc/conda
  conda av metadata url : None
           channel URLs : https://conda.anaconda.org/conda-forge/linux-64
                          https://conda.anaconda.org/conda-forge/noarch
          package cache : /home/traversaro/miniforge3/pkgs
                          /home/traversaro/.conda/pkgs
       envs directories : /home/traversaro/miniforge3/envs
                          /home/traversaro/.conda/envs
               platform : linux-64
             user-agent : conda/23.3.1 requests/2.31.0 CPython/3.10.12 Linux/5.15.123.1-microsoft-standard-WSL2 ubuntu/22.04.3 glibc/2.35 solver/libmamba conda-libmamba-solver/23.3.0 libmambapy/1.4.2
                UID:GID : 1000:1000
             netrc file : None
           offline mode : False
traversaro commented 11 months ago

As mentioned in https://github.com/conda-forge/ctng-compilers-feedstock/issues/114#issuecomment-1718238163 , this problem can be easily reproduced with a custom shared library, for example the one in https://github.com/traversaro/reproduce-python-gomp-deepbind-issue/blob/d69e6a7e70b5be851b0206495ff4ecdc8734e1e1/testso.c .

In particular, one can run:

wget https://github.com/traversaro/reproduce-python-gomp-deepbind-issue/blob/d69e6a7e70b5be851b0206495ff4ecdc8734e1e1/testso.c
gcc -shared -fPIC testso.c -o testso.so
python -c "import ctypes; import os; ctypes._dlopen('./testso.so', os.RTLD_DEEPBIND)"

to reproduce the problem. Removing the os.RTLD_DEEPBIND the problem does not appear. It is still not clear in which platform this happens. It happens for all conda-forge builds I tried, while for example on Ubuntu 22.04 apt packages of Python it does not happen, while if I compile the same python version by source as the one installed by apt the problem occurs. On the other hand, on Ubuntu 23.04 and 23.10 with apt packages the problem occurs.

To investigate more, I patched the cpython source code with the following patch:

diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c
index 3ac1034972..e0dbf1171d 100644
--- a/Modules/_ctypes/callproc.c
+++ b/Modules/_ctypes/callproc.c
@@ -1539,6 +1539,10 @@ static PyObject *py_dl_open(PyObject *self, PyObject *args)
         return NULL;
     }
+    fprintf(stderr, "=====> Calling ctypes_dlopen(%s, %d)\n", name_str, mode);
+    fprintf(stderr, "=====> environ (%p) &environ (%p)\n", environ, &environ);
     handle = ctypes_dlopen(name_str, mode);
+    fprintf(stderr, "=====> Called ctypes_dlopen(%s, %d)\n", name_str, mode);
+    fprintf(stderr, "=====> environ (%p) &environ (%p)\n", environ, &environ);
     Py_XDECREF(name2);
     if (!handle) {
         const char *errmsg = ctypes_dlerror();

By running the reproducer with this patch, this is the output:

=====> Calling ctypes_dlopen((null), 2)
=====> environ (0x7fff5e89b868) &environ (0x55a647027c20)
=====> Called ctypes_dlopen((null), 2)
=====> environ (0x7fff5e89b868) &environ (0x55a647027c20)
=====> Calling ctypes_dlopen(./testso.so, 10)
=====> environ (0x7fff5e89b868) &environ (0x55a647027c20)
Print debug
environ (nil) &environ 0x7f59ba435200
=====> Called ctypes_dlopen(./testso.so, 10)
=====> environ (0x7fff5e89b868) &environ (0x55a647027c20)

So, it is possible to see that it is not the environ variable that change value, but simply that for some reason inside the testso.so a different address is binded to the symbol environ. I tried to understand why this is happend by investigating which of the .so shared libraries contained a environ symbol, and it seems that the dynamic loader contains a local environ symbol, beside the global environ symbol contained in glibc that should be the one used:

traversaro@IITICUBLAP257:~/cpython$ ldd ./install/bin/python3
        linux-vdso.so.1 (0x00007ffccf985000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fab811e2000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fab80fba000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fab81997000)
traversaro@IITICUBLAP257:~/cpython$ objdump --syms /lib/x86_64-linux-gnu/libc.so.6 | grep environ
000000000021aeb8 l     O .bss   0000000000000008 last_environ
0000000000000000 l    df *ABS*  0000000000000000 environ.c
0000000000044db0 l     F .text  000000000000039d __add_to_environ
0000000000221200  w    O .bss   0000000000000008 _environ
0000000000221200  w    O .bss   0000000000000008 environ
0000000000221200 g     O .bss   0000000000000008 __environ
traversaro@IITICUBLAP257:~/cpython$ objdump --syms /lib64/ld-linux-x86-64.so.2 | grep environ
0000000000000000 l    df *ABS*  0000000000000000 dl-environ.c
0000000000000000 l    df *ABS*  0000000000000000 environ.c
000000000003b2d0 l     O .bss   0000000000000008 _environ
000000000003b2d0 l     O .bss   0000000000000008 __environ
000000000003b2d0 l     O .bss   0000000000000008 environ

So, I am not sure but I am wondering if there is some strange interaction between this two environ symbols?

I also found this old glibc bug that seems related: https://sourceware.org/bugzilla/show_bug.cgi?id=9758 .

traversaro commented 11 months ago

Ok, I was able to reproduce reliably the problem in a C example, without the need to use Python, thanks to the input from https://sourceware.org/bugzilla/show_bug.cgi?id=9758 . This is what I understood (not an expert, so I could get things wrong).

The file to reproduce the behavior can be found in https://gist.github.com/traversaro/2d12a7067f686472207c942043f8c7b7 .

First of all, the root cause of this is the following behaviour, quoting from https://sourceware.org/bugzilla/show_bug.cgi?id=11717 :

Apparently, when linking a shared library which contains a variable in .bss with an executable referencing that variable, ld allocates space for that variable in the executable's .bss section and creates a duplicate symbol for this variable.

So, in the previous test with C++, I was not accessing environ from the executable, so there was only one environ symbol: the one in glibc's BSS (with weak visibility). So, in all cases in the loaded .so, the environ variable was correctly resolved to the variable in glibc's BSS. If instead the executable (in our case, Python) refers directly to environ, then a copy of environ is created in Python's bss section, with global visibility. Without using RTLD_DEEPBIND, everything works fine, as all the libraries use the environ from the executable bss, and ignore the environ from glibc's bss. Note that glibc initialization code use the environ from the executable bss, while the environ from glibc's bss remains to its initialization value (NULL). If instead RTLD_DEEPBIND is used, then in the shared library the environ in the executable bss is ignored, and instead the one in glibc's bss is used. However, the environ from glibc bss is still set to NULL, as glibc initialized the one in the executable bss. Clearly, nothing of this happens if the executable does not use environ directly. I guess all the differences between different versions of Python we experienced is due to the use or not directly of environ (this can be easily checked by looking if there is a B symbol for __environ in Python executable).

Interestingly, if the shared library that is opened via RTLD_DEEPBIND access the environment variables via the getenv or similar functions, everything works fine as inside glibc functions environ is correctly resolved to the environ from executable bss, even if the environ as seen by the loaded shared library is NULL .

traversaro commented 11 months ago

I opened a bug upstream in libgomp at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111556, and libgomp maintainers confirmed that this is not an issue that can be fixed on libgomp. Given that, I think the options are:

At the moment, I can't think of other solutions.

traversaro commented 11 months ago

At the moment, I can't think of other solutions.

I tought of another solution, added in https://github.com/conda-forge/casadi-feedstock/pull/94 that is working in my local tests.