Skip to content

OpFromGraph difficult to subclass due to not allowing shared variables to be positioned explicitly as an input #473

Closed
@ricardoV94

Description

@ricardoV94

Description

The changes introduced in aesara-devs/aesara#902 make it hard to safely subclass OpFromGraph with initialization kwargs.

Here is an example:

import pytensor
import pytensor.tensor as pt
from pytensor.compile.builders import OpFromGraph

class OpFromGraphSub(OpFromGraph):
    
    def __init__(self, *args, kwarg, **kwargs):
        self.kwarg = kwarg
        super().__init__(*args, **kwargs)


x = pytensor.shared(2)
y = pytensor.shared(3)

out = OpFromGraphSub([], [x + 1], kwarg="test")()
out.owner.op(y) 
# TypeError: OpFromGraphSub.__init__() missing 1 required keyword-only argument: 'kwarg'

One would have to subclass made_node for this to work correctly, but that's highly non-trivial.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions