Base core graph classes on attrs
or dataclasses
#421
Replies: 4 comments
-
Q: is it possible to keep treating these classes like data ('fix' the attribs?)? Over time, classes tend to acquire attribute-like methods. |
Beta Was this translation helpful? Give feedback.
-
Thought: ImO, the core graph objects would have to be pretty abstract... no theano-specifics like is_somethingrelatedtoexecution(). |
Beta Was this translation helpful? Give feedback.
-
#37 is related right? attrs has built in mgt for eq. |
Beta Was this translation helpful? Give feedback.
-
Yes, it could be related, but it's likely that we'll need/want custom
It looks like you might be referring to a requirement that we need to implement: i.e. immutability of the core graph classes. That is a motivating factor behind the interest in We can impose some immutability constraints using Symbolic PyMC uses If you look at Both of those metaclasses do things similar to what |
Beta Was this translation helpful? Give feedback.
-
In line with #37, we should consider basing the core graph objects (e.g.
theano.gof.graph.[Node, Variable, Apply]
,theano.gof.op.[PureOp, Op]
, and all their subclasses) on some form of flexible, (relatively) immutable, easily convertible data type. The packagesattrs
and the newly built-indataclasses
provide much—if not all—of what we need.Specifically, both packages provide automatic recursive conversion into
tuple
s anddict
s and easily configurable defaults for things like equality, ordering,repr
, hashing, etc. Theattrs
goes a little further and can perform automatic input validation and conversion, as well as use__slots__
for a relative performance gain.More importantly, both provide convenient mutation functions (i.e.
dataclasses.replace
andattrs.evolve
) that fit well with the existing object identity model and the pervasive requirement for object cloning. In this setting, graph object mutation could be turned into a considerably easier—and universal—process!Beta Was this translation helpful? Give feedback.
All reactions