Skip to content

Commit c4ee850

Browse files
committed
Fix bugs in lazy unrolling with init=False.
1 parent 8c2352c commit c4ee850

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

aiger/aig.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ def children(self):
6060
return (self.left, self.right)
6161

6262

63-
6463
@attr.frozen
6564
class Inverter(Node):
6665
input: Node
@@ -95,7 +94,7 @@ def children(self):
9594
return ()
9695

9796
def __eq__(self, other) -> bool:
98-
return isinstance(other, ConstFalse)
97+
return isinstance(other, ConstFalse)
9998

10099
def __hash__(self) -> int:
101100
return hash(False)

aiger/lazy.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,9 +459,13 @@ def __call__(self, inputs, latches=None, *, lift=None):
459459
if not init:
460460
assert (circ.latches & circ.inputs) == set()
461461

462-
latches = circ.latch2init if init else project(inputs, circ.inputs)
463462
if init:
464-
inputs = omit(inputs, circ.inputs)
463+
latches = circ.latch2init
464+
else:
465+
try:
466+
latches = {n: inputs[f'{n}##time_0'] for n in circ.latches}
467+
except KeyError:
468+
raise ValueError('not init, but missing latches from inputs.')
465469

466470
outputs = {}
467471
for time in range(horizon):

tests/test_common.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,25 @@ def unroll_key(key):
230230
assert sum1 == sum2
231231

232232

233+
def test_unroll_without_init():
234+
circ = aiger.parse('''aag 3 1 1 1 1
235+
2
236+
4 6 1
237+
6
238+
6 4 2
239+
i0 x
240+
o0 x
241+
l0 y
242+
''')
243+
circ2 = circ.unroll(2, init=False)
244+
assert circ2.inputs == {'x##time_0', 'x##time_1', 'y##time_0'}
245+
assert circ2.outputs == {'x##time_1', 'x##time_2'}
246+
out, _ = circ2({'x##time_0': 1, 'x##time_1': 1, 'y##time_0': 1})
247+
assert out['x##time_2'] and out['x##time_1']
248+
out, _ = circ2({'x##time_0': 1, 'x##time_1': 1, 'y##time_0': 0})
249+
assert not out['x##time_2'] and not out['x##time_1']
250+
251+
233252
@given(aigh.Circuits, st.data())
234253
def test_feedback_then_cut(circ, data):
235254
def renamer(_):

0 commit comments

Comments
 (0)