Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
Max paths heuristic
Browse files Browse the repository at this point in the history
  • Loading branch information
iopapamanoglou committed Nov 12, 2024
1 parent 3295c0e commit 4d3055d
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/faebryk/core/cpp/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,4 @@ def find_paths(src: Node, dst: Sequence[Node]) -> tuple[list[Path], list[Counter
def print_obj(obj: object) -> None: ...
def set_indiv_measure(value: bool) -> None: ...
def set_leak_warnings(value: bool) -> None: ...
def set_max_paths(value: int) -> None: ...
4 changes: 4 additions & 0 deletions src/faebryk/core/cpp/include/pathfinder/pathfinder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

inline uint32_t MAX_PATHS = 1 << 31;

inline void set_max_paths(uint32_t v) {
MAX_PATHS = v;
}

class PathFinder;

struct Filter {
Expand Down
1 change: 1 addition & 0 deletions src/faebryk/core/cpp/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ PYMOD(m) {
// TODO why this rv_pol needed
m.def("find_paths", &find_paths, "src"_a, "dst"_a, nb::rv_policy::reference);
m.def("set_indiv_measure", &set_indiv_measure, "value"_a);
m.def("set_max_paths", &set_max_paths, "value"_a);

// Graph
using GI = GraphInterface;
Expand Down
6 changes: 4 additions & 2 deletions src/faebryk/core/pathfinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@
from rich.console import Console
from rich.table import Table

from faebryk.core.cpp import Counter, Path, set_indiv_measure
from faebryk.core.cpp import Counter, Path, set_indiv_measure, set_max_paths
from faebryk.core.cpp import find_paths as find_paths_cpp
from faebryk.core.node import Node
from faebryk.libs.util import ConfigFlag
from faebryk.libs.util import ConfigFlag, ConfigFlagInt

# Also in C++
INDIV_MEASURE = ConfigFlag(
"INDIV_MEASURE", default=True, descr="Measure individual paths"
)
MAX_PATHS = ConfigFlagInt("MAX_PATHS", default=int(1e5), descr="Max paths to search")
set_indiv_measure(bool(INDIV_MEASURE))
set_max_paths(int(MAX_PATHS))


def find_paths(src: Node, dst: Sequence[Node]) -> Sequence[Path]:
Expand Down
3 changes: 3 additions & 0 deletions src/faebryk/libs/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,9 @@ def __init__(self, name: str, default: int = 0, descr: str = "") -> None:
def _convert(self, raw_val: str) -> int:
return int(raw_val)

def __int__(self) -> int:
return self.get()


def zip_dicts_by_key(*dicts):
keys = {k for d in dicts for k in d}
Expand Down
8 changes: 6 additions & 2 deletions test/core/test_performance.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from faebryk.core.module import Module
from faebryk.core.moduleinterface import ModuleInterface
from faebryk.core.node import Node
from faebryk.libs.app.parameters import resolve_dynamic_parameters
from faebryk.libs.library import L
from faebryk.libs.test.times import Times
from faebryk.libs.util import times
Expand Down Expand Up @@ -237,13 +238,16 @@ def test_mif_connect_hull(self):
def test_complex_module(self):
timings = Times()

modules = [F.USB2514B, F.RP2040]
modules = [
F.USB2514B,
F.RP2040,
]

for t in modules:
app = t() # noqa: F841
timings.add(f"{t.__name__}: construct")

# resolve_dynamic_parameters(app.get_graph())
resolve_dynamic_parameters(app.get_graph())
timings.add(f"{t.__name__}: resolve")

logger.info(f"\n{timings}")
Expand Down

0 comments on commit 4d3055d

Please sign in to comment.