Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conflict degree sort after priority topological sort #56

Merged
merged 5 commits into from
Feb 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ dependencies = [
"amaranth == 0.5.3",
"amaranth-stubs @ git+https://github.com/kuznia-rdzeni/amaranth-stubs.git@481b28c70812936d067e93e4e4cf2eb34bcc50d3",
"dataclasses-json == 0.6.3",
"tabulate == 0.9.0"
"tabulate == 0.9.0",
"networkx == 3.4.2"
]
requires-python = ">=3.11"
classifiers = [
Expand Down
4 changes: 2 additions & 2 deletions test/core/test_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,10 @@ async def process(sim):
def test_unsatisfiable(self, circuit: type[PriorityTestCircuit], priority: Priority):
m = circuit(priority, True)

import graphlib
import networkx

if priority != Priority.UNDEFINED:
cm = pytest.raises(graphlib.CycleError)
cm = pytest.raises(networkx.NetworkXUnfeasible)
else:
cm = contextlib.nullcontext()

Expand Down
8 changes: 6 additions & 2 deletions transactron/core/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from collections.abc import Callable, Iterable, Sequence, Collection, Mapping
from typing import TypeAlias, Optional
from os import environ
from graphlib import TopologicalSorter
from amaranth import *
from amaranth.lib.wiring import Component, connect, flipped
from itertools import chain, filterfalse, product
import networkx

from amaranth_types import AbstractComponent

Expand Down Expand Up @@ -190,7 +190,11 @@ def add_edge(begin: TBody, end: TBody, priority: Priority, conflict: bool):

porder: PriorityOrder = {}

for k, transaction in enumerate(TopologicalSorter(pgr).static_order()):
psorted: list[TBody] = list(
networkx.lexicographical_topological_sort(networkx.DiGraph(pgr).reverse(), key=lambda t: len(cgr[t]))
)

for k, transaction in enumerate(psorted):
porder[transaction] = k

return cgr, porder
Expand Down