-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtest_bench.py
54 lines (40 loc) · 1.3 KB
/
test_bench.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from pathlib import Path
import pytest
import funcy as fn
import aiger
@pytest.mark.timeout(10)
def test_fast_call():
"""Based on https://github.com/mvcisback/py-aiger/issues/135."""
def gates(circ):
gg = []
count = 0
class NodeAlg:
def __init__(self, lit: int):
self.lit = lit
@fn.memoize
def __and__(self, other):
nonlocal count
nonlocal gg
count += 1
new = NodeAlg(count << 1)
right, left = sorted([self.lit, other.lit])
gg.append((new.lit, left, right))
return new
@fn.memoize
def __invert__(self):
return NodeAlg(self.lit ^ 1)
def lift(obj) -> NodeAlg:
if isinstance(obj, bool):
return NodeAlg(int(obj))
elif isinstance(obj, NodeAlg):
return obj
raise NotImplementedError
start = 1
inputs = {k: NodeAlg(i << 1) for i, k in enumerate(sorted(circ.inputs), start)}
count += len(inputs)
omap, _ = circ(inputs=inputs, lift=lift)
return gg
path = Path(__file__).parent / "bench1.aag"
circ = aiger.to_aig(path)
gg = gates(circ)
assert gg is not None