# TMVA PyTorch

**URL:** <https://root-forum.cern.ch/t/tmva-pytorch/49644>\
**Category:** TMVA\
**Created:** [April 20, 2022, 10:48am UTC](https://root-forum.cern.ch/t/tmva-pytorch/49644 "2022-04-20T10:48:26Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![11133](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/11133/32/25084_2.png) [@11133](https://root-forum.cern.ch/u/11133)\
**Post date:** [April 20, 2022, 10:48am UTC](https://root-forum.cern.ch/t/tmva-pytorch/49644/1 "2022-04-20T10:48:26Z")

</div>

Hi all,

I’m trying to train the NN using TMVA PyTorch. I’m stuck at one problem:  
when I run the script it outputs such error on terminal:

You are probably missing the definition of TMVA::PyMethodBase::PyInitialize()  
Maybe you need to load corresponding shared library?

It is strange because in the script there is such a piece of code: TMVA.PyMethodBase.PyInitialize(). Why even such a problem appears? For the note: I’m running the script on lxplus8 machine. Python version is 3.6.8. Root version is 6.26.00. Torch package is installed.

Am I missing something?

Cheers,  
Aizat

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [April 20, 2022, 9:54pm UTC](https://root-forum.cern.ch/t/tmva-pytorch/49644/2 "2022-04-20T21:54:18Z")

</div>

Hi,  
Yes this is strange, can you please post your code and if needed data file, so I can run your script and reproduce the problem

Cheers

Lorenzo

---

<div class="post-metadata">

**Author:** ![11133](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/11133/32/25084_2.png) [@11133](https://root-forum.cern.ch/u/11133)\
**Post date:** [April 21, 2022, 1:03pm UTC](https://root-forum.cern.ch/t/tmva-pytorch/49644/3 "2022-04-21T13:03:48Z")

</div>

Hi,

Actually this is a code which presented in root’s official webpage. I’d like to get familiar with TMVA PyTorch, so I just copy pasted the entire code and run it on lxplus8 machine. Please, find in attachment the script which I’ve used.  
[TMVA\_Pytorch.py](https://root-forum.cern.ch/uploads/short-url/oDbpIlRJTY390XAxmv6JpLeqd2B.py) (4.4 KB)  
The data file loads automatically when the running the script.

Thank you!

Cheers,

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [April 21, 2022, 1:25pm UTC](https://root-forum.cern.ch/t/tmva-pytorch/49644/4 "2022-04-21T13:25:57Z")

</div>

Can you also please upload the data so I can run it?

---

<div class="post-metadata">

**Author:** ![11133](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/11133/32/25084_2.png) [@11133](https://root-forum.cern.ch/u/11133)\
**Post date:** [April 21, 2022, 1:34pm UTC](https://root-forum.cern.ch/t/tmva-pytorch/49644/5 "2022-04-21T13:34:06Z")

</div>

When you run the script, it should load the data, because as I understand there is a line of code in the script which does that.

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [April 25, 2022, 8:23am UTC](https://root-forum.cern.ch/t/tmva-pytorch/49644/6 "2022-04-25T08:23:12Z")

</div>

Hi,  
Sorry for my late reply. Your script runs fine for me. I think you are maybe using a ROOT installation without PyMVA support ?  
What is the output of this command from the terminal:

```auto
root-config --has-tmva-pymva

```

Lorenzo

---

<div class="post-metadata">

**Author:** ![11133](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/11133/32/25084_2.png) [@11133](https://root-forum.cern.ch/u/11133)\
**Post date:** [April 25, 2022, 8:51am UTC](https://root-forum.cern.ch/t/tmva-pytorch/49644/7 "2022-04-25T08:51:57Z")

</div>

Hi,

No need to apologize. I checked the command you’ve sent, it perfectly finds the pymva.  
I run the command TMVA.PyMethodBase.PyInitialize() once again, and sending the full error output hoping that it will give more clear idea what is going wrong:

IncrementalExecutor::executeFunction: symbol ‘\_ZN4TMVA12PyMethodBase12PyInitializeEv’ unresolved while linking symbol ‘\_\_cf\_3’!  
You are probably missing the definition of TMVA::PyMethodBase::PyInitialize()  
Maybe you need to load the corresponding shared library?

Thank you!

Cheers,

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [April 25, 2022, 8:56am UTC](https://root-forum.cern.ch/t/tmva-pytorch/49644/8 "2022-04-25T08:56:34Z")

</div>

Very strange. Are you building ROOT from source on lxplus or using a pre-existing binary ?  
In this second case I could maybe check directly

Lorenzo

---

<div class="post-metadata">

**Author:** ![11133](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/11133/32/25084_2.png) [@11133](https://root-forum.cern.ch/u/11133)\
**Post date:** [April 25, 2022, 9:40am UTC](https://root-forum.cern.ch/t/tmva-pytorch/49644/9 "2022-04-25T09:40:41Z")

</div>

In lxplus8 I didn’t install root, using pre-existing binary. (By pre-existing binary I understand is as root is already built). Version is 6.26.

On the machine other than lxplus8, where mainly CentOS 7, in order to train NN using TMVA PyKeras, I use the shell script /cvmfs/sft.cern.ch/lcg/views/LCG\_88/x86\_64-centos7-gcc62-opt/setup.sh which puts environmental variables. In this case TMVA.PyMethodBase.PyInitialize() perfectly works.

Maybe there is alternative setup scripts for CentOS 8, which I can use ??

Cheers,

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [April 25, 2022, 10:31am UTC](https://root-forum.cern.ch/t/tmva-pytorch/49644/10 "2022-04-25T10:31:42Z")

</div>

Hi,

I can reproduce your problem with the default root installed in /usr/bin in CentOS8. That version does not contain libPyMVA, it is strange that `root-config --has-tmva-pymva` returns yes.  
You can use another ROOT version there, for example for 6.26.02 , from  
`/cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.26.02/`  
You need to do first:  
`. /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.26.02/x86_64-centos8-gcc85-opt/bin/thisroot.sh`  
or you can use an older version of ROOT in an LCG view as you were doing on CentoS7.  
For example you can use 6.24.06 by doing:  
`. /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.26.02/x86_64-centos8-gcc85-opt/bin/thisroot.sh`

Cheers

Lorenzo

---

<div class="post-metadata">

**Author:** ![11133](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/11133/32/25084_2.png) [@11133](https://root-forum.cern.ch/u/11133)\
**Post date:** [April 25, 2022, 11:20am UTC](https://root-forum.cern.ch/t/tmva-pytorch/49644/11 "2022-04-25T11:20:17Z")

</div>

Thank you Lorenzo,

with the setup script you sent me everything works fine!

Cheers,

---

<div class="post-metadata">

**Author:** ![11133](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/11133/32/25084_2.png) [@11133](https://root-forum.cern.ch/u/11133)\
**Post date:** [April 25, 2022, 1:39pm UTC](https://root-forum.cern.ch/t/tmva-pytorch/49644/12 "2022-04-25T13:39:48Z")

</div>

Sorry to bother you again!

Can you please reproduce the results on your own lxplus machine? The previous problem disappeared, but unfortunately some incomprehensible errors appeared. I’m uploading my script and my data files.

[PyTorch\_SM.py](https://root-forum.cern.ch/uploads/short-url/c4cTNxNckjDV0EU99tqf6CSwjVH.py) (5.9 KB)

Here the data:  
[New\_MiniNtuple\_tHbq\_SM\_300K.root](https://root-forum.cern.ch/uploads/short-url/hxDgGAoM2EsbIELXldw7Xnby7l.root) (682.6 KB)  
[New\_MiniNtiple\_tt\_SM\_3M.root](https://root-forum.cern.ch/uploads/short-url/yQNHE5gpXzMoxRBbd5rGnI3ZkqV.root) (764.3 KB)

Cheers,

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [April 25, 2022, 8:12pm UTC](https://root-forum.cern.ch/t/tmva-pytorch/49644/13 "2022-04-25T20:12:11Z")

</div>

Hi,  
I have this failure running your code:

```auto
<WARNING> : Failed to run python code: model = torch.jit.load('modelbmc_generated_data.h5')
<WARNING> : Python error message:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/moneta/Library/Python/3.8/lib/python/site-packages/torch/jit/_serialization.py", line 151, in load
    raise ValueError("The provided filename {} does not exist".format(f)) # type: ignore[str-bytes-safe]
ValueError: The provided filename modelbmc_generated_data.h5 does not exist

```

You need to provide also the input model file.

Lorenzo
