Skip to content

Commit 2d46d60

Browse files
committed
Remove unused rewrites and functionality
1 parent 40ccab1 commit 2d46d60

File tree

10 files changed

+46
-518
lines changed

10 files changed

+46
-518
lines changed

doc/extending/graph_rewriting.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ computation graph.
134134
In a nutshell, :class:`ReplaceValidate` grants access to :meth:`fgraph.replace_validate`,
135135
and :meth:`fgraph.replace_validate` allows us to replace a :class:`Variable` with
136136
another while respecting certain validation constraints. As an
137-
exercise, try to rewrite :class:`Simplify` using :class:`NodeFinder`. (Hint: you
137+
exercise, try to rewrite :class:`Simplify` using :class:`WalkingGraphRewriter`. (Hint: you
138138
want to use the method it publishes instead of the call to toposort)
139139

140140
Then, in :meth:`GraphRewriter.apply` we do the actual job of simplification. We start by

doc/library/graph/features.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,3 @@ Guide
2626
.. class:: ReplaceValidate(History, Validator)
2727

2828
.. method:: replace_validate(fgraph, var, new_var, reason=None)
29-
30-
.. class:: NodeFinder(Bookkeeper)
31-
32-
.. class:: PrintListener(object)

pytensor/graph/features.py

Lines changed: 0 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -827,100 +827,6 @@ def validate(self, fgraph):
827827
raise InconsistencyError("Trying to reintroduce a removed node")
828828

829829

830-
class NodeFinder(Bookkeeper):
831-
def __init__(self):
832-
self.fgraph = None
833-
self.d = {}
834-
835-
def on_attach(self, fgraph):
836-
if hasattr(fgraph, "get_nodes"):
837-
raise AlreadyThere("NodeFinder is already present")
838-
839-
if self.fgraph is not None and self.fgraph != fgraph:
840-
raise Exception("A NodeFinder instance can only serve one FunctionGraph.")
841-
842-
self.fgraph = fgraph
843-
fgraph.get_nodes = partial(self.query, fgraph)
844-
Bookkeeper.on_attach(self, fgraph)
845-
846-
def clone(self):
847-
return type(self)()
848-
849-
def on_detach(self, fgraph):
850-
"""
851-
Should remove any dynamically added functionality
852-
that it installed into the function_graph
853-
"""
854-
if self.fgraph is not fgraph:
855-
raise Exception(
856-
"This NodeFinder instance was not attached to the provided fgraph."
857-
)
858-
self.fgraph = None
859-
del fgraph.get_nodes
860-
Bookkeeper.on_detach(self, fgraph)
861-
862-
def on_import(self, fgraph, node, reason):
863-
try:
864-
self.d.setdefault(node.op, []).append(node)
865-
except TypeError: # node.op is unhashable
866-
return
867-
except Exception as e:
868-
print("OFFENDING node", type(node), type(node.op), file=sys.stderr) # noqa: T201
869-
try:
870-
print("OFFENDING node hash", hash(node.op), file=sys.stderr) # noqa: T201
871-
except Exception:
872-
print("OFFENDING node not hashable", file=sys.stderr) # noqa: T201
873-
raise e
874-
875-
def on_prune(self, fgraph, node, reason):
876-
try:
877-
nodes = self.d[node.op]
878-
except TypeError: # node.op is unhashable
879-
return
880-
nodes.remove(node)
881-
if not nodes:
882-
del self.d[node.op]
883-
884-
def query(self, fgraph, op):
885-
try:
886-
all = self.d.get(op, [])
887-
except TypeError:
888-
raise TypeError(
889-
f"{op} in unhashable and cannot be queried by the optimizer"
890-
)
891-
all = list(all)
892-
return all
893-
894-
895-
class PrintListener(Feature):
896-
def __init__(self, active=True):
897-
self.active = active
898-
899-
def on_attach(self, fgraph):
900-
if self.active:
901-
print("-- attaching to: ", fgraph) # noqa: T201
902-
903-
def on_detach(self, fgraph):
904-
"""
905-
Should remove any dynamically added functionality
906-
that it installed into the function_graph
907-
"""
908-
if self.active:
909-
print("-- detaching from: ", fgraph) # noqa: T201
910-
911-
def on_import(self, fgraph, node, reason):
912-
if self.active:
913-
print(f"-- importing: {node}, reason: {reason}") # noqa: T201
914-
915-
def on_prune(self, fgraph, node, reason):
916-
if self.active:
917-
print(f"-- pruning: {node}, reason: {reason}") # noqa: T201
918-
919-
def on_change_input(self, fgraph, node, i, r, new_r, reason=None):
920-
if self.active:
921-
print(f"-- changing ({node}.inputs[{i}]) from {r} to {new_r}") # noqa: T201
922-
923-
924830
class PreserveVariableAttributes(Feature):
925831
"""
926832
This preserve some variables attributes and tag during optimization.

0 commit comments

Comments
 (0)