TMVA_SOFIE_Keras on MacOS

I’m trying to run the TMVA_SOFIE_Keras.C tutorial on MacOSX (Monterey 12.6, i9). I’ve installed a python-aware version of root 6.26.10 using mamba, which seems to work normally. The problem is listed below. It runs fine on a linux-based machine following the same install procedure.

root [0] .x /Applications/root_v6.26.10/tutorials/tmva/TMVA_SOFIE_Keras.C
cling::DynamicLibraryManager::loadLibrary(): dlopen(/Users/brownd/mambaforge/envs/KKTrain/lib/libPyMVA.6.26.10.so, 0x0009): symbol not found in flat namespace (_PyCapsule_Type)
Error in <TCling__LazyFunctionCreatorAutoloadForModule>: Failed to load library /Users/brownd/mambaforge/envs/KKTrain/lib/libPyMVA.6.26.10.so

Maybe @moneta or @vpadulan can help.

Hi Dave,

it looks like th library libPyMVA is not there. You should use a build with tmva-pymva=On and you can check if the feature is there by typing on the command line.

root-config --has-tmva-pymva

Normally the feature is on when you have a valid Python and numpy version.

Cheers

Lorenzo

Lorenzo

Hi Lorenzo,
libPyMVA is present in my OSX root build:
KKTrain % root-config --has-tmva-pymva
yes

The problem can be replicated with a simple test:
root [0] .L $ROOTSYS/lib/libPyMVA.so
cling::DynamicLibraryManager::loadLibrary(): dlopen(/Users/brownd/mambaforge-pypy3/lib/libPyMVA.6.26.08.so, 0x0009): symbol not found in flat namespace (_PyCapsule_Type)

This is strange, it looks like libPyMVA.so has not been build correctly.
Can you run the tests in tmva/pymva/test or the tutorial tutorials/tmva/TMVA_CNN_Classification.C ?

Cheers

Lorenzo

Hi, Lorenzo,

I got similar errors as @Dave_Brown has described in this post when I was trying to run the macro tutorials/tmva/TMVA_CNN_Classification.C

Here are the errors I got:

cling::DynamicLibraryManager::loadLibrary(): dlopen(/Users/martin/opt/anaconda3/envs/tensorflow/lib/libPyMVA.6.28.00.so, 0x0009): symbol not found in flat namespace '_PyCapsule_Type'
Error in <AutoloadLibraryMU>: Failed to load library /Users/martin/opt/anaconda3/envs/tensorflow/lib/libPyMVA.6.28.00.socling JIT session error: Failed to materialize symbols: { (main, { __ZN4TMVA12PyMethodBase12PyInitializeEv }) }

Is there a solution to this problem?

P.S.
I got a “yes” when I did root-config --has-tmva-pymva in the terminal.

Hi,
It looks like then there is an issue for some builds of libPyMVA. Can you tell me exactly the configuration you are using, ROOT version, Python version, Numpy version, tensorflow version and how did you build ROOT, etc…, so I can reproduce the problem

Lorenzo

Hi, Lorenzo,

These are the information about my system:

ROOT Version: 6.28/00

Python Platform: macOS-12.4-x86_64-i386-64bit

Tensor Flow Version: 2.12.0

Keras Version: 2.12.0

Python 3.10.10 | packaged by conda-forge | (main, Mar 24 2023, 20:17:34) [Clang 14.0.6 ]

Numpy 1.23.5

Pandas 2.0.0

Scikit-Learn 1.2.2

GPU is available

And this is how I installed TensorFlow and ROOT on my Mac:

  1. Installed Anaconda

  2. Installed TensorFlow by doing this command in the terminal:
    conda env create -f tensorflow-apple-metal.yml -n tensorflow

In my tensorflow-apple-metal.yml file:

name: tensorflow
channels:

  • apple
  • conda-forge
    dependencies:
    • python=3.10
    • pip>=19.0
    • jupyter
    • scikit-learn
    • scipy
    • pandas
    • pandas-datareader
    • matplotlib
    • pillow
    • tqdm
    • requests
    • h5py
    • pyyaml
    • flask
    • boto3
    • ipykernel
    • pip:
      • tensorflow-macos
      • tensorflow-metal
      • bayesian-optimization
      • gym
      • kaggle

Then I did

  1. conda activate tensorflow

  2. python -m ipykernel install --user --name tensorflow --display-name "Python 3.10 (tensorflow)"

  3. Installed ROOT in the environment by using this command:
    conda install root -c conda-forge

I ran the macro tutorials/tmva/make_cnn_model.py to get the output file model_cnn.h5, and then in ROOT I did:

root [0] .x TMVA_CNN_Classification.C

Then I got the errors:

cling::DynamicLibraryManager::loadLibrary(): dlopen(/Users/martin/opt/anaconda3/envs/tensorflow/lib/libPyMVA.6.28.00.so, 0x0009): symbol not found in flat namespace '_PyCapsule_Type'
Error in <AutoloadLibraryMU>: Failed to load library /Users/martin/opt/anaconda3/envs/tensorflow/lib/libPyMVA.6.28.00.socling JIT session error: Failed to materialize symbols: { (main, { __ZN4TMVA12PyMethodBase12PyInitializeEv }) }

Hi,

Thank you for the information, it is maybe an issue with the ROOT conda builds on MacOS. I will test this and let you know

Cheers

Lorenzo

Sounds good, I appreciate it and thank you!

I’ve found another way to make the macro run successfully with Keras on my Mac but it has to be in Python, so I saw the macro TMVA_CNN_Classification.py, the Python version of this CNN script, and then I ran the macro directly in Python3 interface without going through the ROOT interface, and it worked.

Hi,
It is good that using Python the macro TMVA_CNN_Classification.py works and the C++ version, TMVA_CNN_Classification.C does not work. In principle both should use the Python interface to TMVA, libPyMVA. I would need to reproduce your condo environment. I’ll try to do it in the next days

Best,

Lorenzo