BhallaLab / moose-core

C++ basecode and python scripting interface
https://moose.ncbs.res.in
GNU General Public License v3.0
15 stars 26 forks source link

New python bindings using pybind11- many of function not exposed #418

Open hrani opened 4 years ago

hrani commented 4 years ago

function like getId(), getDataIndex(), mooseWriteSBML,mooseReadSBML mooseWriteKkit is not available at python binding level.

hrani commented 4 years ago

moose.Neutral('/m') moose.CubeMesh('/m/c') f = moose.Function('/m/c/f') moose.showfield(f) Not sure what does "derivative" hold in case of function, earlier it use to be derivative = 0.0 now its saying Nan derivative = nan

dilawar commented 4 years ago

function like getId(), getDataIndex(), mooseWriteSBML,mooseReadSBML mooseWriteKkit is not available at python binding level.

getId and getDataIndex are avaiable as a field.

In [7]: b = moose.Neutral('/a')                                                                                                                                 

In [8]: a.getId()                                                                                                                                               
Out[8]: <moose.vec: class=Neutral, id=448, path=/a>

In [9]: a.getDataIndex()                                                                                                                                        
Out[9]: 0

You may want to check pybind11/module.cpp as well.

When a value is assigned to a moose element, derivative does not make sense. For computing derivative, you need at least 2 values (f(x+h) - f(x)/h). In old API, it was initialized to 0.0. It doesn't break any existing code.

hrani commented 4 years ago
In [7]: b = moose.Neutral('/a')                                                                                                                                 

In [8]: a.getId()                                                                                                                                               
Out[8]: <moose.vec: class=Neutral, id=448, path=/a>

In [9]: a.getDataIndex()                                                                                                                                        
Out[9]: 0

ipython3 Python 3.8.2 (default, Jul 16 2020, 14:00:26) Type 'copyright', 'credits' or 'license' for more information IPython 7.13.0 -- An enhanced Interactive Python. Type '?' for help.

moose.about()
Out[1]: {'path': '/home/harsha/moose/moose-core/python/moose', 'version': '3.2.0.dev20200826', 'docs': 'https://moose.readthedocs.io/en/latest/', 'development': 'https://github.com/BhallaLab/moose-core'}

b = moose.Neutral('/a')
b.getDataIndex()
KeyError Traceback (most recent call last)

in ----> 1 b.getDataIndex() KeyError: "getDataIndex is not found on '/a[0]'." b.getId() KeyError Traceback (most recent call last) in ----> 1 b.getId() KeyError: "getId is not found on '/a[0]'." > * `mooseWriteSBML` is changed to `[writeSBML](https://github.com/BhallaLab/moose-core/blob/b4aac15bf9e696c442f8d4c972f329d16ff97f7f/python/moose/__init__.py#L766)`. Similarly `mooseReadSBML`, and `mooseWriteKkit` are renamed to `readSBML` and `writeKkit`. You can create an alias in `python/__init__.py` file. I know writeSBML,readSBML,writeKkit works and this makes more sense which I always preferred but in the documentation it still says as mooseWriteSBML and snippets also failing due to this. > > You may want to check `pybind11/module.cpp` as well. > > When a value is assigned to a moose element, `derivative` does not make sense. For computing derivative, you need at least 2 >values (`f(x+h) - f(x)/h`). In old API, it was initialized to `0.0`. It doesn't break any existing code. Yes its not breaking any existing code, but warning as in earlier API it was initialized 0.0 which is better than Nan Also in documentation, specially cookbook https://moose.readthedocs.io/en/latest/user/py/cookbook/ https://moose.ncbs.res.in/readthedocs/user/py/cookbook/ has different version, the one which is on moose.ncbs.res.in is the latest
dilawar commented 4 years ago

https://github.com/BhallaLab/moose-core/pull/422 fixes the missing getFieldIndex, getDataIndex functions. I miswrote in the previous update: they were available as dataIndex, fieldIndex. Sorry about that! Only one script in the moose-examples, still uses getDataIndex. If they have made into the published code, I'd suggest to deprecate them in favor of fieldIndex and dataIndex.

About missing mooseReadSBML etc., it's up to you and @upibhalla to either tweak the API or change the docs. It's a one-line change in the __init__.py. As far as I can recall, mooseReadSBML etc. were introduced because C++ had the name-clash with this readSBML etc. function which is no longer the case.

About derivative set to nan in the beginning, it is mathematically correct now and does not break any code. There is no need to make it wrong.

Many other PRs I've opened are diverging and getting stale and I hardly hear about them for 2-3 months. I am feeling a little less motivated to work on this project.