<div dir="ltr">Hi All,<div><br></div><div>I found out that the "Hamiltonian" class I will be using is not good for pickling, therefore I used little different approach to define my solver as a separate class (that just gets the momentum value) and create object of it for every run separately. </div><div><br></div><div>My solution:</div><div><a href="http://www.codesend.com/view/ed72e945804613a914dbddb0d9d23e06/">http://www.codesend.com/view/ed72e945804613a914dbddb0d9d23e06/</a><br></div><div><a href="http://www.codesend.com/view/87df0f95e98e812398e444750784c907/">http://www.codesend.com/view/87df0f95e98e812398e444750784c907/</a><br></div><div><br></div><div><br></div><div>I even included passing some additional parameters as a default argument to the function.</div><div><br></div><div>If someone would have better solution I will appreciate any feedback.</div><div><br></div><div>Cheers,</div><div>Rafal</div></div><div class="gmail_extra"><br><div class="gmail_quote">2014-12-04 2:58 GMT+01:00 Michael McKerns <span dir="ltr"><<a href="mailto:mmckerns@caltech.edu" target="_blank">mmckerns@caltech.edu</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Try replacing the serialization engine with `dill` or `cloudpickle`.<br>
That's probably your best chance at serializing and shipping the<br>
objects across the wire.  IPython.parallel lets you override the<br>
serializer with either of these.<br>
<div><div class="h5"><br>
<br>
> On Wed, Dec 3, 2014 at 12:37 PM, Rafał Skolasiński<br>
> <<a href="mailto:rjtskolasinski@gmail.com">rjtskolasinski@gmail.com</a><br>
>> wrote:<br>
><br>
>> Hi,<br>
>><br>
>> It doesn't look like a solution. I still get bunch of errors. And I<br>
>> would<br>
>> like to use self.hamiltonian instance, not create more instances of it.<br>
>> the<br>
>> hamiltonian object in my real (not just a test) simulation code enters<br>
>> as<br>
>> the argument to the Simulation class constructor.<br>
>><br>
><br>
> Your original code gave errors trying to serialize the Hamiltonian<br>
> instance<br>
> in order to make copies for each machine in the cluster. Some objects<br>
> can't<br>
> be serialized like that. In any event, each machine needs to have access<br>
> to<br>
> the data that it will process. So, you need to somehow get that data (in<br>
> whole or in part) to each machine.<br>
><br>
> Hope that helps,<br>
><br>
> -Doug<br>
><br>
><br>
><br>
>><br>
>> And I would also like to execute hamiltonian.get_matrix method in<br>
>> parallel. The version of that method I use in my real simulation code is<br>
>> a<br>
>> little more complex and also take some time to be executed. Not maybe as<br>
>> much as diagonalization but still.<br>
>><br>
>> Cheers,<br>
>> Rafal<br>
>><br>
>> 2014-12-03 18:28 GMT+01:00 Doug Blank <<a href="mailto:doug.blank@gmail.com">doug.blank@gmail.com</a>>:<br>
>><br>
>>> I haven't done much parallel IPython, but it looks like you just need<br>
>>> to<br>
>>> define/import everything on the remote clients, something like:<br>
>>><br>
>>> def get_energy(momentum):<br>
>>>     import scipy.sparse.linalg as sla<br>
>>>     from scipy.sparse import coo_matrix<br>
>>>     from scipy.sparse import csc_matrix<br>
>>>     import numpy as np<br>
>>>     class Hamiltonian:<br>
>>>         def get_matrix(self, k):<br>
>>>             # sleep(3.0)<br>
>>>             return k**2 * np.diag(range(100))<br>
>>><br>
>>>     hamiltonian = Hamiltonian()<br>
>>>     mat = hamiltonian.get_matrix(momentum)<br>
>>>     mat = csc_matrix(mat)<br>
>>>     ev = sla.eigsh(mat,k=5, sigma = 0.5, which = 'LM')<br>
>>>     return ev[0]<br>
>>><br>
>>> def compute_parallel(momenta):<br>
>>>     rc = parallel.Client()<br>
>>>     dview = rc[:]<br>
>>>     spectrum = dview.map_sync(get_energy,momenta)<br>
>>>     return spectrum<br>
>>><br>
>>> -Doug<br>
>>><br>
>>> On Wed, Dec 3, 2014 at 12:21 PM, Rafał Skolasiński <<br>
>>> <a href="mailto:rjtskolasinski@gmail.com">rjtskolasinski@gmail.com</a>> wrote:<br>
>>><br>
>>>> Oh, in the file I attached there should ofc be line<br>
>>>> spectrum = dview.map_sync(self.get_energy,momenta)<br>
>>>> instead of<br>
>>>> spectrum = dview.map_sync(self.get_energy_for_parallel,momenta)<br>
>>>><br>
>>>> Sorry for mistake.<br>
>>>> Raphael<br>
>>>><br>
>>>><br>
>>>> 2014-12-03 18:05 GMT+01:00 Rafał Skolasiński<br>
>>>> <<a href="mailto:rjtskolasinski@gmail.com">rjtskolasinski@gmail.com</a>>:<br>
>>>><br>
>>>>> Hi Guys,<br>
>>>>><br>
>>>>> I hope this is the right place to ask this kind of question.<br>
>>>>><br>
>>>>> I would like to use IPython parallel in my physical simulation.<br>
>>>>> In my mind I've got class Simulation, which contain as a field object<br>
>>>>> hamiltonian of class Hamiltonian.<br>
>>>>><br>
>>>>> Method get_energy should call  hamiltonian.get_matrix(momentum),<br>
>>>>> diagonalize it with scipy method and return energies.<br>
>>>>><br>
>>>>> I would like to execute it in parallel for a list of different<br>
>>>>> momenta.<br>
>>>>><br>
>>>>><br>
>>>>> I tested it with a standard python 'map' function and it worked so I<br>
>>>>> thought that easiest way would be to use 'dview.map_sync' in the same<br>
>>>>> way<br>
>>>>> but it doesn't looks like a proper way of doing it.<br>
>>>>><br>
>>>>> I am attaching my testing code. I would be very grateful for any help<br>
>>>>> and ideas how to do it in a nice and clean way.<br>
>>>>><br>
>>>>> Cheers,<br>
>>>>> Raphael<br>
>>>>><br>
>>>><br>
>>>><br>
>>>> _______________________________________________<br>
>>>> IPython-dev mailing list<br>
>>>> <a href="mailto:IPython-dev@scipy.org">IPython-dev@scipy.org</a><br>
>>>> <a href="http://mail.scipy.org/mailman/listinfo/ipython-dev" target="_blank">http://mail.scipy.org/mailman/listinfo/ipython-dev</a><br>
>>>><br>
>>>><br>
>>><br>
>>> _______________________________________________<br>
>>> IPython-dev mailing list<br>
>>> <a href="mailto:IPython-dev@scipy.org">IPython-dev@scipy.org</a><br>
>>> <a href="http://mail.scipy.org/mailman/listinfo/ipython-dev" target="_blank">http://mail.scipy.org/mailman/listinfo/ipython-dev</a><br>
>>><br>
>>><br>
>><br>
>> _______________________________________________<br>
>> IPython-dev mailing list<br>
>> <a href="mailto:IPython-dev@scipy.org">IPython-dev@scipy.org</a><br>
>> <a href="http://mail.scipy.org/mailman/listinfo/ipython-dev" target="_blank">http://mail.scipy.org/mailman/listinfo/ipython-dev</a><br>
>><br>
>><br>
> _______________________________________________<br>
> IPython-dev mailing list<br>
> <a href="mailto:IPython-dev@scipy.org">IPython-dev@scipy.org</a><br>
> <a href="http://mail.scipy.org/mailman/listinfo/ipython-dev" target="_blank">http://mail.scipy.org/mailman/listinfo/ipython-dev</a><br>
><br>
<br>
<br>
</div></div>---<br>
<br>
Mike McKerns<br>
California Institute of Technology<br>
TEL: <a href="tel:%28626%29395-5773" value="+16263955773">(626)395-5773</a> or <a href="tel:%28626%29590-8470" value="+16265908470">(626)590-8470</a><br>
<a href="http://www.its.caltech.edu/~mmckerns" target="_blank">http://www.its.caltech.edu/~mmckerns</a><br>
<a href="mailto:mmckerns@caltech.edu">mmckerns@caltech.edu</a><br>
<div class="HOEnZb"><div class="h5"><br>
_______________________________________________<br>
IPython-dev mailing list<br>
<a href="mailto:IPython-dev@scipy.org">IPython-dev@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/ipython-dev" target="_blank">http://mail.scipy.org/mailman/listinfo/ipython-dev</a><br>
</div></div></blockquote></div><br></div>