qutip taking more number of cpus in cluster

27 views
Skip to first unread message

Muthumanimaran Vetrivelan

unread,
Dec 20, 2022, 6:09:10 AM12/20/22
to QuTiP: Quantum Toolbox in Python
I am running a code in cluster in which I use mesolve function to do time evolution of Ising model.  Even after I specify in options num_cpus =1 and (use_openmp = False, when i used mcsolve), the code somehow takes all cpus to do mesolve/mcsolve.  Apart from mesolve, I turn to mcsolve, same issue appears. I also have H.eigenstates() which I don't know will take multiple cpus to do the job, while searching for options in qutip page, no results were found.  Actually when i run the code for 10 spins, the cpu usage becomes 1000%, I am trying to run the code in a single node with 20 cpus.  But I just want to run the code in 1 cpu only.

Simon Cross

unread,
Dec 20, 2022, 7:02:45 AM12/20/22
to qu...@googlegroups.com
Hello,

It's possible that the BLAS library you are using is using multiple
threads, for example, MKL.

You can read more about this and about setting the number of threads in:

- https://numpy.org/doc/stable/reference/routines.linalg.html (just
the first two paragraphs)
- https://github.com/joblib/threadpoolctl (Python library for seeing
what libraries you're using and controlling the number of threads)

I'm keen to hear more about your setup and whether we can help make
QuTiP better for you on these bigger single nodes.

Regards,
Simon

Muthumanimaran Vetrivelan

unread,
Dec 20, 2022, 7:18:17 AM12/20/22
to qu...@googlegroups.com
I am using only using numpy and Qutip only.
I am trying a simple code, I am trying to simulate simple sudden quench problem.

I am getting ground state of an Ising Hamiltonian with 10 spins using H.eigenstates() and evolving the ground state using mesolve() for various values of coupling value say ‘g’.  (Using simple “for” loop to run for ten different values of ‘g’ ranging from 0 to 1), that’s all. In the mesolve(), I set options = Options(num_cpus = 1) to make the mesolve run in one cpu. Thats all I am doing.  But the cluster is running at approx 1000% and taking more than 1 cpu to execute this.

--
You received this message because you are subscribed to the Google Groups "QuTiP: Quantum Toolbox in Python" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qutip+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/qutip/CAD5NRCEH-smkeZc5AX%3D7ttV94oK5NmcJMiFcFhja4EngaoB_OA%40mail.gmail.com.

Muthumanimaran Vetrivelan

unread,
Dec 20, 2022, 7:47:11 AM12/20/22
to qu...@googlegroups.com
Here is my code:

from qutip import *
import numpy as np
N = 10

sx_list, sy_list, sz_list = [], [], []
for i in range(N):
    op_list = [qeye(2)] * N
    op_list[i] = sigmax()
    sx_list.append(tensor(op_list))
    op_list[i] = sigmay()
    sy_list.append(tensor(op_list))
    op_list[i] = sigmaz()
    sz_list.append(tensor(op_list))
 

J = 0.25
   
H0 = 0
Hint = 0
for i in range(N):
    H0 += - sz_list[i]
   
for n in range(N - 1):
    Hint += - sx_list[n] * sx_list[n + 1]

Hint += - sx_list[0] * sx_list[N-1]
   
lim = 20
t = np.linspace(0,0.5,lim)
gvec = np.linspace(0.1, 0.5, lim)
   
g1 = 0.01
H1 =  ((g1) * H0 + J * Hint)
evals, ekets = H1.eigenstates()
   
for i in range(lim):
        options = Options(num_cpus = 1, use_openmp = False)
        Ht1 = (gvec[i]*H0 + J * Hint)
        result = mesolve(Ht1, ekets[0], t, options = options)
        val = result.states[lim-1]

Neill Lambert

unread,
Dec 20, 2022, 7:47:40 AM12/20/22
to qu...@googlegroups.com
hi,

If it helps i had a similar issue running on a multi-core server.
as simon said, it was because of some underlying parralization from intel mkl
using this at the top of my code

import mkl
mkl.set_num_threads(1)

worked for me.  I guess depending on the server you are using the issue might be different, and you may have to play around a bit to find an answer.   if you can send the output of qutip.about() to use it might help.

all the best
neill



--
-----------------------------------
Senior Research Scientist
RIKEN, Japan
Research Homepage

Muthumanimaran Vetrivelan

unread,
Dec 20, 2022, 8:44:10 AM12/20/22
to qu...@googlegroups.com
this is what qutip.about() returns to me from the cluster.  The Intel MKL ext is set to false
Screenshot 2022-12-20 19.08.30.png
thanks for the suggestion. I think the option might be different for my server.  I'll check.

Muthumanimaran Vetrivelan

unread,
Dec 20, 2022, 11:43:32 AM12/20/22
to qu...@googlegroups.com
Dear Simon and Neill,
    Thanks for the help, the problem is with numpy, as Simon suggested. The following lines of code fixed the issue.
import os
os.environ["OPENBLAS_NUM_THREADS"] = "1"

Simon Cross

unread,
Dec 21, 2022, 10:58:09 AM12/21/22
to qu...@googlegroups.com
Glad you came right!
Reply all
Reply to author
Forward
0 new messages