[SciPy-Dev] Python bindings for KLU

Richard Lincoln r.w.lincoln at gmail.com
Sun Mar 18 14:46:26 EDT 2012


On 18/03/12 12:16, Nathaniel Smith wrote:
> On Sun, Mar 18, 2012 at 11:01 AM, Robert Cimrman<cimrman3 at ntc.zcu.cz>  wrote:
>> Hi,
>>
>> On 03/18/2012 11:12 AM, Nathaniel Smith wrote:
>>> On Sun, Mar 18, 2012 at 1:08 AM, Richard Lincoln<r.w.lincoln at gmail.com>    wrote:
>>>> On 17 March 2012 20:36, Nathaniel Smith<njs at pobox.com>    wrote:
>>>>> On Mar 17, 2012 5:21 PM, "Richard Lincoln"<r.w.lincoln at gmail.com>    wrote:
>>>>>>
>>>>>> Hello SciPy-Dev,
>>>>>
>>>>> Hi Richard,
>>>>>
>>>>>> I am working on a distribution system simulator in Python.  I would
>>>>>> like to use KLU to solve sparse sets of complex linear equations.
>>>>>>
>>>>>> http://www.cise.ufl.edu/research/sparse/klu/
>>>>>>
>>>>>> What would you recommend I use to create Python bindings for this C
>>>>>> library?  I don't have any experience with this and there seem to be
>>>>>> several options available.  If you could point me towards any good
>>>>>> examples of similar bindings, that too would be very greatly
>>>>>> appreciated.
>>>>>
>>>>> I'd suggest using Cython for bindings, and taking a look at scikits.sparse:
>>>>>    https://code.google.com/p/scikits-sparse/
>>>>>
>>>>> It has quite complete Cython bindings for CHOLMOD:
>>>>>    http://packages.python.org/scikits.sparse/cholmod.html
>>>>>    https://code.google.com/p/scikits-sparse/source/browse/scikits/sparse/cholmod.pyx
>>>>>
>>>>> Not only does this give an example of using Cython to work with sparse
>>>>> matrices and Tim Davis' code, there's a fair amount of infrastructure
>>>>> that can probably be re-used -- I believe that KLU relies on CHOLMOD's
>>>>> data structures for basic sparse matrix tasks. If you'd like to
>>>>> contribute your work to scikits.sparse, then we can factor this out
>>>>> into shared code.
>>>>
>>>> Thank you for the advice Nathaniel.  Unfortunately, my project has a
>>>> BSD license and scikits-sparse uses the GNU GPL.  However, I found
>>>> scikits-umfpack by Robert Cimrman.
>>>>
>>>> http://scikits.appspot.com/umfpack
>>>>
>>>> It uses SWIG and shouldn't take much effort to adapt.
>>>
>>> I'm happy to release my wrapper code under the BSD; I just haven't
>>> bothered since CHOLMOD itself is GPLed. I can't see where Robert put a
>>> license on that UMFPACK wrapper, but it's in exactly the same
>>> situation -- UMFPACK is also GPLed.

CHOLMOD is "Distributed under the GNU LGPL license; the Supernodal and 
Modify (update/downdate) Modules are distributed under the GNU GPL license."

http://www.cise.ufl.edu/research/sparse/cholmod/

UMMPACK < v5.2 is available under LGPL and non GNU licenses can be 
arranged by contacting Tim Davis.

http://www.cise.ufl.edu/research/sparse/umfpack/

Having the scikits.sparse wrappers under a BSD license would be 
beneficial under certain circumstances.

>>
>> Yes, it's the same situation. I have BSDed the wrappers as they were
>> originally a part of scipy (this is now deprecated). It would be great
>> if you relicensed your wrappers under the BSD, see below.
>
> Yes, done:
>    https://code.google.com/p/scikits-sparse/source/detail?r=8e3e12ac6b075ba12ea3bcf791a010bf65545600

Great! Many thanks.

>
>>> I do also see that I was confused, and KLU doesn't depend on CHOLMOD
>>> (I was thinking of SuiteSparseQR). I do think you might still prefer
>>> to look at the CHOLMOD wrapper, both because people seem to prefer
>>> Cython to SWIG and because KLU and CHOLMOD seem to use very similar
>>> APIs, but of course it's up to you.

CHOLMOD is listed as an optional dependency for KLU because it is just 
used in some of the demos to read in matrix data in triplet form and 
compress it. However, your Cython CHOLMOD wrapper will still be very 
helpful in getting me started.

>>>
>>> I do think it would be nice if we could find a way to make your
>>> wrapper more generally available, and the idea of scikits.sparse is to
>>> try and gather up such code so people can find it. So if you have any
>>> thoughts on how we could make that work, I can be flexible :-).

If you give me (r.w.lincoln) commit rights I'll be happy to push my work 
to a branch of scikits.sparse. Otherwise, it'll be available on my 
GitHub page:

http://github.com/rwl

Should these wrappers be kept as separate projects? One wouldn't want to 
have to install UMFPACK and KLU just to compile the wrappers for 
CHOLMOD. If so, is there any common code that ought to be shared between 
them?

>>
>> I have written the umfpack wrappers a long time ago (no cython then) -
>> now I would have used definitely cython - I use it now in my projects
>> too. Ideally, I would prefer to have all Tim Davis code wrappers in one
>> place (scikits.sparse), BSD licensed, and in cython. Then the wrappers
>> could be easily bundled with other BSD-licensed codes.
>>
>> It should not be difficult to adapt the umfpack wrapper code, but I
>> cannot do it in the next couple of weeks (several article deadlines).
>> Later I would be happy to devote some care... Just my two 0.01CZK.
>
> I made a start at writing a scikits.sparse-style Cython wrapper for
> UMFPACK in a branch here:
>    https://code.google.com/p/scikits-sparse/source/browse/scikits/sparse/umfpack.pyx?spec=svne99b9e0af1d52b2e6effce24e25f318d9d016230&name=2010-wrap-umfpack&r=e99b9e0af1d52b2e6effce24e25f318d9d016230
>
> Not finished, but it might be a useful starting point for whoever next
> picks this up.



More information about the SciPy-Dev mailing list