Skip to content

Commit df986d3

Browse files
authored
Merge pull request #40 from aurelio-labs/james/allow-cycles
fix: allow cycles
2 parents 4913da1 + 5d1ddb2 commit df986d3

3 files changed

Lines changed: 5 additions & 17 deletions

File tree

graphai/graph.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
2-
from typing import Any, Protocol, Type
3-
from graphlib import TopologicalSorter, CycleError
2+
from typing import Any, Protocol
43
from graphai.callback import Callback
54
from graphai.utils import logger
65

@@ -63,7 +62,7 @@ def __init__(
6362
self.edges: list[Any] = []
6463
self.start_node: NodeProtocol | None = None
6564
self.end_nodes: list[NodeProtocol] = []
66-
self.Callback: Type[Callback] = Callback
65+
self.Callback: type[Callback] = Callback
6766
self.max_steps = max_steps
6867
self.state = initial_state or {}
6968

@@ -288,17 +287,6 @@ def _add_edge(src: str, dst: str) -> None:
288287
"(src, Iterable[dst]), mapping{'source'/'destination'}, or objects with .source/.destination"
289288
)
290289

291-
# cycle detection
292-
preds: dict[str, set[str]] = {n: set() for n in nodes.keys()}
293-
for s, ds in adj.items():
294-
for d in ds:
295-
preds[d].add(s)
296-
297-
try:
298-
list(TopologicalSorter(preds).static_order())
299-
except CycleError as e:
300-
raise GraphCompileError("Cycle detected in graph") from e
301-
302290
# reachability from start
303291
seen: set[str] = set()
304292
stack = [start_name]
@@ -388,7 +376,7 @@ def set_callback(self, callback_class: type[Callback]) -> "Graph":
388376
as the default callback when no callback is passed to the `execute` method.
389377
390378
:param callback_class: The callback class to use as the default callback.
391-
:type callback_class: Type[Callback]
379+
:type callback_class: type[Callback]
392380
"""
393381
self.Callback = callback_class
394382
return self

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "graphai-lib"
3-
version = "0.0.9rc1"
3+
version = "0.0.9rc2"
44
description = "Not an AI framework"
55
readme = "README.md"
66
requires-python = ">=3.10,<3.14"

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)