Skip to content

Add bindings for matrix access#260

Merged
damienmarchal merged 8 commits intosofa-framework:masterfrom
alxbilger:matrixaccess
Jun 22, 2022
Merged

Add bindings for matrix access#260
damienmarchal merged 8 commits intosofa-framework:masterfrom
alxbilger:matrixaccess

Conversation

@alxbilger
Copy link
Contributor

Python bindings for accessing A, x and b from a linear solver solving the system Ax=b.

An example is introduced.
In the example, the output after a time step:

====================================
Global system matrix
====================================
dtype: float64
shape: (960, 960)
ndim: 2
nnz: 52200
====================================
System right hand side
====================================
dtype: float64
shape: (960,)
ndim: 1
====================================
System solution
====================================
dtype: float64
shape: (960,)
ndim: 1

Note: I took the same binding names than in Caribou

@damienmarchal
Copy link
Contributor

Hi @alxbilger,

Thanks for the PR.
It looks really nice to me, when looking at it I'm wondering wether or not there is possible memory pointer issues... I mean if the object is removed from the scene graph is it possible that dangling pointer remains on the python side ?

@alxbilger
Copy link
Contributor Author

I don't think so. The returned object of those bindings are copies in all functions A, b and x. For A, there is no choice as pybind cannot pass a sparse matrix by reference (Passing by reference is not supported for sparse types.). b and x return also a copy, but here they are dense vectors, so in theory there is room for improvement to pass the vectors by reference.

@hugtalbot hugtalbot added the pr: highlighted in next release Highlight this contribution in the notes of the upcoming release label May 18, 2022
@alxbilger
Copy link
Contributor Author

A unit test is required

@damienmarchal
Copy link
Contributor

Thanks for the added tests @alxbilger.

To make python scenes it is recommended to use python objects instead of Sofa string for passing parameters.

root.addObject('EulerImplicitSolver', rayleighStiffness="0.1", rayleighMass="0.1") 
root.addObject('BoxROI', name="box", box="-10 -1 -0.0001 -5 4 0.0001")

should become:

root.addObject('EulerImplicitSolver', rayleighStiffness=0.1, rayleighMass=0.1) 
root.addObject('BoxROI', name="box", box=[-10, -1, -0.0001, -5, 4, 0.0001])

Copy link
Contributor

@damienmarchal damienmarchal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes to do:

  • use python object instead of string
  • have a corrected lifetime management for the root node (or explain how/if it works)
  • remove the useless controller (if really useless)

@alxbilger
Copy link
Contributor Author

@damienmarchal thanks for the review. The last changes should follow your suggestions

@alxbilger
Copy link
Contributor Author

I suspect the failing unit test comes from sofa-framework/sofa#3036, highlighted by sofa-framework/sofa#3050.
Therefore, I'll modify the test

Co-authored-by: Hugo <hugo.talbot@sofa-framework.org>
@damienmarchal damienmarchal merged commit 64ecd52 into sofa-framework:master Jun 22, 2022
@damienmarchal
Copy link
Contributor

The generated file BindingsConfig.cmake does not work when used in find_package for an external directory. There is a failure on missing Bindings.SofaBaseLinearSolver.

Bindings.SofaGui
Bindings.SofaRuntime
Bindings.SofaTypes
Bindings.SofaLinearSolver
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commenting this line allows SoftRobots to compile. Otherwise it fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: highlighted in next release Highlight this contribution in the notes of the upcoming release pr: status ready

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants