[IPython-dev] Using IPython Parallel inside a class
Doug Blank
doug.blank at gmail.com
Wed Dec 3 12:28:57 EST 2014
I haven't done much parallel IPython, but it looks like you just need to
define/import everything on the remote clients, something like:
def get_energy(momentum):
import scipy.sparse.linalg as sla
from scipy.sparse import coo_matrix
from scipy.sparse import csc_matrix
import numpy as np
class Hamiltonian:
def get_matrix(self, k):
# sleep(3.0)
return k**2 * np.diag(range(100))
hamiltonian = Hamiltonian()
mat = hamiltonian.get_matrix(momentum)
mat = csc_matrix(mat)
ev = sla.eigsh(mat,k=5, sigma = 0.5, which = 'LM')
return ev[0]
def compute_parallel(momenta):
rc = parallel.Client()
dview = rc[:]
spectrum = dview.map_sync(get_energy,momenta)
return spectrum
-Doug
On Wed, Dec 3, 2014 at 12:21 PM, Rafał Skolasiński <rjtskolasinski at gmail.com
> wrote:
> Oh, in the file I attached there should ofc be line
> spectrum = dview.map_sync(self.get_energy,momenta)
> instead of
> spectrum = dview.map_sync(self.get_energy_for_parallel,momenta)
>
> Sorry for mistake.
> Raphael
>
>
> 2014-12-03 18:05 GMT+01:00 Rafał Skolasiński <rjtskolasinski at gmail.com>:
>
>> Hi Guys,
>>
>> I hope this is the right place to ask this kind of question.
>>
>> I would like to use IPython parallel in my physical simulation.
>> In my mind I've got class Simulation, which contain as a field object
>> hamiltonian of class Hamiltonian.
>>
>> Method get_energy should call hamiltonian.get_matrix(momentum),
>> diagonalize it with scipy method and return energies.
>>
>> I would like to execute it in parallel for a list of different momenta.
>>
>>
>> I tested it with a standard python 'map' function and it worked so I
>> thought that easiest way would be to use 'dview.map_sync' in the same way
>> but it doesn't looks like a proper way of doing it.
>>
>> I am attaching my testing code. I would be very grateful for any help and
>> ideas how to do it in a nice and clean way.
>>
>> Cheers,
>> Raphael
>>
>
>
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20141203/8eb85cd9/attachment.html>
More information about the IPython-dev
mailing list