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. |
|
Thought: ImO, the core graph objects would have to be pretty abstract... no theano-specifics like is_somethingrelatedtoexecution(). |
|
#37 is related right? attrs has built in mgt for eq. |
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 |
Uh oh!
There was an error while loading. Please reload this page.
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 packagesattrsand the newly built-indataclassesprovide much—if not all—of what we need.Specifically, both packages provide automatic recursive conversion into
tuples anddicts and easily configurable defaults for things like equality, ordering,repr, hashing, etc. Theattrsgoes 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.replaceandattrs.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!All reactions