# PyMVA KMeans crash

**URL:** <https://root-forum.cern.ch/t/pymva-kmeans-crash/24136>\
**Category:** TMVA\
**Tags:** python\
**Created:** [March 18, 2017, 5:31am UTC](https://root-forum.cern.ch/t/pymva-kmeans-crash/24136 "2017-03-18T05:31:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![satyarth934](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/satyarth934/32/11942_2.png) [@satyarth934](https://root-forum.cern.ch/u/satyarth934)\
**Post date:** [March 18, 2017, 5:31am UTC](https://root-forum.cern.ch/t/pymva-kmeans-crash/24136/1 "2017-03-18T05:31:39Z")

</div>

Hi,  
I was trying to implement KMeans for PyMVA. But below is the crash stack trace that I get. I am unable to pinpoint the exact error.  
It would be really helpful if someone could look into this once and provide some help.

```auto
(5, 'k-means++', 10, 300, 0.0001, 'auto', 0, None, 1, 1)
KMeans(copy_x=1, init='k-means++', max_iter=300, n_clusters=5, n_init=10,
    n_jobs=1, precompute_distances='auto', random_state=None, tol=0.0001,
    verbose=0)
                         : 
                         : --- Saving State File In:dl/weights/PyKMeansModel.PyData
                         : 
                         : Elapsed time for training with 6000 events: 0.327 sec         
                         : Dataset[dl] : Evaluation of PyKMeans on training sample (6000 events)

 ***Break*** segmentation violation

===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================

Thread 5 (Thread 0x7f33722ba880 (LWP 25193)):
#0 pthread_cond_wait

GLIBC_2.3.2 () at ../sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S:185
#1 0x00007f338a59b84c in ?? () from /home/satyarth934/anaconda2/lib/python2.7/site-packages/numpy/core/../../../../libiomp5.so
#2 0x00007f338a53ac5d in ?? () from /home/satyarth934/anaconda2/lib/python2.7/site-packages/numpy/core/../../../../libiomp5.so
#3 0x00007f338a53c014 in ?? () from /home/satyarth934/anaconda2/lib/python2.7/site-packages/numpy/core/../../../../libiomp5.so
#4 0x00007f338a563a60 in ?? () from /home/satyarth934/anaconda2/lib/python2.7/site-packages/numpy/core/../../../../libiomp5.so
#5 0x00007f338a596033 in ?? () from /home/satyarth934/anaconda2/lib/python2.7/site-packages/numpy/core/../../../../libiomp5.so
#6 0x00007f33a68436ba in start_thread (arg=0x7f33722ba880) at pthread_create.c:333
#7 0x00007f33a73e182d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109

Thread 4 (Thread 0x7f33726bb800 (LWP 25192)):
#0 pthread_cond_wait

GLIBC_2.3.2 () at ../sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S:185
#1 0x00007f338a59b84c in ?? () from /home/satyarth934/anaconda2/lib/python2.7/site-packages/numpy/core/../../../../libiomp5.so
#2 0x00007f338a53ac5d in ?? () from /home/satyarth934/anaconda2/lib/python2.7/site-packages/numpy/core/../../../../libiomp5.so
#3 0x00007f338a53c014 in ?? () from /home/satyarth934/anaconda2/lib/python2.7/site-packages/numpy/core/../../../../libiomp5.so
#4 0x00007f338a563a60 in ?? () from /home/satyarth934/anaconda2/lib/python2.7/site-packages/numpy/core/../../../../libiomp5.so
#5 0x00007f338a596033 in ?? () from /home/satyarth934/anaconda2/lib/python2.7/site-packages/numpy/core/../../../../libiomp5.so
#6 0x00007f33a68436ba in start_thread (arg=0x7f33726bb800) at pthread_create.c:333
#7 0x00007f33a73e182d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109

Thread 3 (Thread 0x7f3372abc780 (LWP 25191)):
#0 pthread_cond_wait

GLIBC_2.3.2 () at ../sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S:185
#1 0x00007f338a59b84c in ?? () from /home/satyarth934/anaconda2/lib/python2.7/site-packages/numpy/core/../../../../libiomp5.so
#2 0x00007f338a53ac5d in ?? () from /home/satyarth934/anaconda2/lib/python2.7/site-packages/numpy/core/../../../../libiomp5.so
#3 0x00007f338a53c014 in ?? () from /home/satyarth934/anaconda2/lib/python2.7/site-packages/numpy/core/../../../../libiomp5.so
#4 0x00007f338a563a60 in ?? () from /home/satyarth934/anaconda2/lib/python2.7/site-packages/numpy/core/../../../../libiomp5.so
#5 0x00007f338a596033 in ?? () from /home/satyarth934/anaconda2/lib/python2.7/site-packages/numpy/core/../../../../libiomp5.so
#6 0x00007f33a68436ba in start_thread (arg=0x7f3372abc780) at pthread_create.c:333
#7 0x00007f33a73e182d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109

Thread 2 (Thread 0x7f33a8622700 (LWP 25190)):
#0 pthread_cond_timedwait

GLIBC_2.3.2 () at ../sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S:225
#1 0x00007f338a596824 in ?? () from /home/satyarth934/anaconda2/lib/python2.7/site-packages/numpy/core/../../../../libiomp5.so
#2 0x00007f33a68436ba in start_thread (arg=0x7f33a8622700) at pthread_create.c:333
#3 0x00007f33a73e182d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109

Thread 1 (Thread 0x7f33a8648940 (LWP 25165)):
#0 0x00007f33a73a651b in __GI___ waitpid (pid=25196, stat_loc=stat_loc
entry=0x7ffd3f60a540, options=options
entry=0) at ../sysdeps/unix/sysv/linux/waitpid.c:29
#1 0x00007f33a731ffbb in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:148
#2 0x00007f33a7f20b2d in TUnixSystem::Exec (shellcmd=<optimized out>, this=0xb554f0) at /home/satyarth934/Documents/OpenSource/CERN/root/core/unix/src/TUnixSystem.cxx:2118
#3 TUnixSystem::StackTrace (this=0xb554f0) at /home/satyarth934/Documents/OpenSource/CERN/root/core/unix/src/TUnixSystem.cxx:2412
#4 0x00007f33a7f2311c in TUnixSystem::DispatchSignals (this=0xb554f0, sig=kSigSegmentationViolation) at /home/satyarth934/Documents/OpenSource/CERN/root/core/unix/src/TUnixSystem.cxx:3632
#5 <signal handler called>
#6 PyArray_DATA (arr=<optimized out>) at /usr/include/numpy/ndarraytypes.h:1435
#7 TMVA::PyMethodBase::GetMvaValues (this=0x367e870, firstEvt=<optimized out>, lastEvt=<optimized out>, logProgress=<optimized out>) at /home/satyarth934/Documents/OpenSource/CERN/root/tmva/pymva/src/PyMethodBase.cxx:294
#8 0x00007f3392325549 in TMVA::MethodBase::AddClassifierOutput (this=0x367e870, type=TMVA::Types::kTraining) at /home/satyarth934/Documents/OpenSource/CERN/root/tmva/tmva/src/MethodBase.cxx:872
#9 0x00007f339232427d in TMVA::MethodBase::TrainMethod (this=this
entry=0x367e870) at /home/satyarth934/Documents/OpenSource/CERN/root/tmva/tmva/src/MethodBase.cxx:694
#10 0x00007f339221baec in TMVA::Factory::TrainAllMethods (this=0x22ffc50) at /home/satyarth934/Documents/OpenSource/CERN/root/tmva/tmva/src/Factory.cxx:886
#11 0x00007f33a867445c in ?? ()
#12 0x000000002184bba3 in ?? ()
#13 0x0000000002059120 in ?? ()
#14 0x00000000ffffffff in ?? ()
#15 0x0000000000000000 in ?? ()
===========================================================

The lines below might hint at the cause of the crash.
You may get help by asking at the ROOT forum http://root.cern.ch/forum.
Only if you are really convinced it is a bug in ROOT then please submit a
report at http://root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#6 PyArray_DATA (arr=<optimized out>) at /usr/include/numpy/ndarraytypes.h:1435
#7 TMVA::PyMethodBase::GetMvaValues (this=0x367e870, firstEvt=<optimized out>, lastEvt=<optimized out>, logProgress=<optimized out>) at /home/satyarth934/Documents/OpenSource/CERN/root/tmva/pymva/src/PyMethodBase.cxx:294
#8 0x00007f3392325549 in TMVA::MethodBase::AddClassifierOutput (this=0x367e870, type=TMVA::Types::kTraining) at /home/satyarth934/Documents/OpenSource/CERN/root/tmva/tmva/src/MethodBase.cxx:872
#9 0x00007f339232427d in TMVA::MethodBase::TrainMethod (this=this
entry=0x367e870) at /home/satyarth934/Documents/OpenSource/CERN/root/tmva/tmva/src/MethodBase.cxx:694
#10 0x00007f339221baec in TMVA::Factory::TrainAllMethods (this=0x22ffc50) at /home/satyarth934/Documents/OpenSource/CERN/root/tmva/tmva/src/Factory.cxx:886
#11 0x00007f33a867445c in ?? ()
#12 0x000000002184bba3 in ?? ()
#13 0x0000000002059120 in ?? ()
#14 0x00000000ffffffff in ?? ()
#15 0x0000000000000000 in ?? ()
===========================================================

```

**The code for KMeans:** [https://github.com/satyarth934/root/blob/KMeans/tmva/pymva/src/MethodPyKMeans.cxx](https://github.com/satyarth934/root/blob/KMeans/tmva/pymva/src/MethodPyKMeans.cxx)  
**Forked Repo:** [https://github.com/satyarth934/root/tree/KMeans](https://github.com/satyarth934/root/tree/KMeans)  
**Branch:** KMeans

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [March 19, 2017, 7:18pm UTC](https://root-forum.cern.ch/t/pymva-kmeans-crash/24136/2 "2017-03-19T19:18:00Z")

</div>

All I can tell from the backtrace is that the crash is caused by PyMethodBase.cxx:294. Could be anything: an uninitialized data member; a wrong value; a missing overridden function from the base.

Maybe @moneta or @sergei or @omazapa could have a look and help you?

Axel.

---

<div class="post-metadata">

**Author:** ![omazapa](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/omazapa/32/12711_2.png) [@omazapa](https://root-forum.cern.ch/u/omazapa)\
**Post date:** [March 19, 2017, 11:38pm UTC](https://root-forum.cern.ch/t/pymva-kmeans-crash/24136/3 "2017-03-19T23:38:11Z")

</div>

Hi @satyarth934  
You need to check that your implementation is creating well the PyObject with the arguments for the classifier and the PyObject classifier.  
Appear to be that is returning a null PyObject for you kmeans instantiation.

Cheers,  
Omar

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [April 2, 2017, 11:38pm UTC](https://root-forum.cern.ch/t/pymva-kmeans-crash/24136/4 "2017-04-02T23:38:27Z")

</div>

Closed on April 2, 2017, 11:38pm UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
