Problems passing PyTrilinos objects to DOLFIN matrix/vector

Bug #884617 reported by Joachim Haga
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
DOLFIN
Fix Released
Medium
Johan Hake

Bug Description

With trilinos 10.8.3 and latest lp:dolfin, I get errors like the following when trying to create dolfin vectors/matrices:

  File "/home/jobh/src/cbc.block/block/algebraic/trilinos/Epetra.py", line 192, in create_vec
    return dolfin.EpetraVector(m) ### m is a PyTrilinos.Epetra.BlockMap
  File "/home/jobh/src/FEniCS/lib/python2.7/site-packages/dolfin/cpp.py", line 4466, in __init__
    _cpp.EpetraVector_swiginit(self,_cpp.new_EpetraVector(*args))
TypeError: expected positive 'int' for argument 1

  File "/home/jobh/src/cbc.block/block/algebraic/trilinos/Epetra.py", line 299, in create_identity
    matrix = dolfin.EpetraMatrix(graph) ### graph is a PyTrilinos.Epetra.CrsGraph
  File "/home/jobh/src/FEniCS/lib/python2.7/site-packages/dolfin/cpp.py", line 4352, in __init__
    _cpp.EpetraMatrix_swiginit(self,_cpp.new_EpetraMatrix(*args))
TypeError: in method 'new_EpetraMatrix', argument 1 of type 'Epetra_CrsGraph const &'

Revision history for this message
Garth Wells (garth-wells) wrote : Re: [Bug 884617] [NEW] Problems passing PyTrilinos objects to DOLFIN matrix/vector

On 1 Nov 2011, at 07:32, Joachim Haga <email address hidden> wrote:

> Public bug reported:
>
> With trilinos 10.8.3 and latest lp:dolfin, I get errors like the
> following when trying to create dolfin vectors/matrices:
>
> File "/home/jobh/src/cbc.block/block/algebraic/trilinos/Epetra.py", line 192, in create_vec
> return dolfin.EpetraVector(m) ### m is a PyTrilinos.Epetra.BlockMap
> File "/home/jobh/src/FEniCS/lib/python2.7/site-packages/dolfin/cpp.py", line 4466, in __init__
> _cpp.EpetraVector_swiginit(self,_cpp.new_EpetraVector(*args))
> TypeError: expected positive 'int' for argument 1
>
> File "/home/jobh/src/cbc.block/block/algebraic/trilinos/Epetra.py", line 299, in create_identity
> matrix = dolfin.EpetraMatrix(graph) ### graph is a PyTrilinos.Epetra.CrsGraph
> File "/home/jobh/src/FEniCS/lib/python2.7/site-packages/dolfin/cpp.py", line 4352, in __init__
> _cpp.EpetraMatrix_swiginit(self,_cpp.new_EpetraMatrix(*args))
> TypeError: in method 'new_EpetraMatrix', argument 1 of type 'Epetra_CrsGraph const &'
>

Trilinos nows uses its own shared pointers in its interface. Johan sorted this out for vectors and matrices. Take a look at what he added in the SWIG code. It's probably a case of extending this to more Epetra objects.

Garth

> ** Affects: dolfin
> Importance: Undecided
> Status: New
>
> --
> You received this bug notification because you are a member of DOLFIN
> Core Team, which is subscribed to DOLFIN.
> https://bugs.launchpad.net/bugs/884617
>
> Title:
> Problems passing PyTrilinos objects to DOLFIN matrix/vector
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/dolfin/+bug/884617/+subscriptions

Changed in dolfin:
milestone: none → 1.0-rc1
assignee: nobody → Johan Hake (johan-hake)
importance: Undecided → Medium
Revision history for this message
Johan Hake (johan-hake) wrote :

We can choose two fixes:

  1) we introduce an overloaded function taking a Teuchos::RCP<EpetraWhatEver> for Dolfin compiled with Trilinos 10.8.3 or more
  2) we introduce a typemap taking either a EpetraWhatEver or a Teuchos::RCP<EpetraWhatEver>

The latter is doable but more complex, as Joachim probably can confirm, but less intrusive for the interface.

Changed in dolfin:
status: New → Confirmed
Johan Hake (johan-hake)
Changed in dolfin:
status: Confirmed → Fix Committed
Anders Logg (logg)
Changed in dolfin:
status: Fix Committed → Fix Released
Revision history for this message
Ole Elvetun (oelvetun) wrote :

Hi,

I have a problem such as described in this post. I have a CrsMatrix (PyTrilinos object), and I would like to pass
this to a dolfin.cpp.matrix, like this naive example:

...
A = assemble(a)
B = down_cast(A).mat()

C = EpetraMatrix(B) #This is what I want to do!

Unfortunately, this last call gives me the same error message as above. I did some different approaches, and to do:

C = EpetraMatrix(B.Graph()) works in the sense that I do not get an error message, but then C does not hold the values
of the sparse matrix, only the structure. I could now run a loop to enter all the values, but this is slow.

Hence, is there some code that might produce what I need quickly?

Revision history for this message
Johan Hake (johan-hake) wrote : Re: [Bug 884617] Re: Problems passing PyTrilinos objects to DOLFIN matrix/vector

On 02/21/2012 02:59 PM, Ole Elvetun wrote:
> Hi,
>
> I have a problem such as described in this post. I have a CrsMatrix (PyTrilinos object), and I would like to pass
> this to a dolfin.cpp.matrix, like this naive example:
>
> ...
> A = assemble(a)
> B = down_cast(A).mat()
>
> C = EpetraMatrix(B) #This is what I want to do!
>
> Unfortunately, this last call gives me the same error message as above.
> I did some different approaches, and to do:
>
> C = EpetraMatrix(B.Graph()) works in the sense that I do not get an error message, but then C does not hold the values
> of the sparse matrix, only the structure. I could now run a loop to enter all the values, but this is slow.
>
> Hence, is there some code that might produce what I need quickly?

We need to add a typemap for this to be possible. It should be pretty
straight forward. We might not get the benefit of automatic shared_ptr
handling as we use different shared_ptr in dolfin and PyTrilinos.

I can have a look at this later today.

Johan

Revision history for this message
Joachim Haga (jobh) wrote :

On 21 February 2012 15:15, Johan Hake <email address hidden> wrote:

> On 02/21/2012 02:59 PM, Ole Elvetun wrote:
> >
> > I have a problem such as described in this post. I have a CrsMatrix
> (PyTrilinos object), and I would like to pass
> > this to a dolfin.cpp.matrix, like this naive example:
>
> We need to add a typemap for this to be possible. It should be pretty
> straight forward. We might not get the benefit of automatic shared_ptr
> handling as we use different shared_ptr in dolfin and PyTrilinos.
>

If the C++ interface is there, I think it should be as simple as adding

%RCP_to_const_ref_typemap(Epetra_CrsMatrix);

along with the other RCP_to_... in la/pre.i. Or maybe it has to be a
FECrsMatrix?

-j.

Revision history for this message
Johan Hake (johan-hake) wrote :

On 02/21/2012 04:29 PM, Joachim Haga wrote:
> On 21 February 2012 15:15, Johan Hake<email address hidden> wrote:
>
>> On 02/21/2012 02:59 PM, Ole Elvetun wrote:
>>>
>>> I have a problem such as described in this post. I have a CrsMatrix
>> (PyTrilinos object), and I would like to pass
>>> this to a dolfin.cpp.matrix, like this naive example:
>>
>> We need to add a typemap for this to be possible. It should be pretty
>> straight forward. We might not get the benefit of automatic shared_ptr
>> handling as we use different shared_ptr in dolfin and PyTrilinos.
>>
>
> If the C++ interface is there, I think it should be as simple as adding
>
> %RCP_to_const_ref_typemap(Epetra_CrsMatrix);
>
> along with the other RCP_to_... in la/pre.i. Or maybe it has to be a
> FECrsMatrix?

It have to be a shared_ptr version of that type. Working on it... Not
that straight forward actually.

Johan

> -j.
>

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.