Quality of life
In this merge request I propose multiple changes which should improve the usage of the Python API of Aidge:
New Features:
-
Add a set_attr
method to StaticAttribute objects -
Add a set_attr
method to DynamicAttribute objects -
Add magic method __set_attr__
&__get_attr__
toStaticAttribute
Allow the use of
dilation_dims = conv.DilationDims # __get_attr__ example
conv.DilationDims = [2, 2] # __set_attr__ example
-
Add magic method __set_attr__
&__get_attr__
toDynamicAttribute
-
Add **kwargs
to GeneriOp ctor to declare more easily attributes:
Usage example
test_op = aidge_core.GenericOperator(
"Test_generic",
1,
0,
1,
name="test_op",
attribute_1=1,
attribute_2=True,
attribute_3=0.001
)
-
Allow Numpy->Tensor conversion with no available Backends (move TensorImpl backend_cpu to core) -
Allow to specify a Backend to choose for Numpy->Tensor conversion
Merge request reports
Activity
assigned to @cmoineau
@pineapple I let you change Milestone if you want ! I have set target branch to be dev.
changed milestone to %aidge_core - v0.2.0
added LanguagePyBind PriorityMedium StatusWork in Progress labels
Very good idea! I think we should have an entire Epic dedicated to user interface with subjects such as:
- access / set attributes
-
Connector
to link Nodes - intuitive training process
- accessing Tensor values for Operators in the middle of a GraphView (pretty uneasy for now)
- setting backend, datatype, data format
added 1 commit
- f28a09ed - [PyBind] Add support for setAttrPy for Dynamic and Static Attributes.
added 1 commit
- 76e8a21d - Add __setattr__ and __getattr__ methods for Attributes. This recquired a...
76e8a21d introduces an "annoying" change.
Due to Python MRO, I needed to change the order of declaration of derived class to implement
__setattr__
and__getattr__
methods.See the related pybind issue : https://github.com/pybind/pybind11/issues/3804
I added this specification to the wiki: https://gitlab.eclipse.org/groups/eclipse/aidge/-/wikis/Python%20binding
I have just got a false hope ...
Looking at the PyBind doc, since 2.6 a tag
prepend
have been introduce to push a function to the top of the overload chain.But it looks like that
__setattr__
and__getattr__
are treated specially and are hard coded as pointed out by this pybind issue...So at the moment, we will still have to keep declaring
Attributes
beforeOperatorTensor
which I find annoying.Edited by Cyril Moineau
added 1 commit
- d68006ec - [PyBind] Update GenericOp ctor to use kwargs to set attributes.
added 1 commit
- 5686ecb8 - Add unittest for magic method setter and attribute set by kwargs.
added 1 commit
- e9c566d1 - Renamed pybind_Parameter.cpp -> pybind_Attributes.cpp to reflect name change.
With the changes made to
Attribute
, I am realizing that manipulating them is hard has we lack documentation on them.A solution I propose to add to this MR is to create a static method
getAttributesName()
which will return a list of all the availables Attribute for an object.This method will provide the user a quick check on what attribute he can call but it will also allow to automatically add to the documentation the Attributes available for an object.
This is possible using a Jinja template just as in : https://gitlab.eclipse.org/eclipse/aidge/aidge/-/blob/master/docs/conf.py?ref_type=heads#L96-102