Skip to content

Commit

Permalink
No peeks (#1781)
Browse files Browse the repository at this point in the history
  • Loading branch information
anshumanmohan authored Nov 16, 2023
1 parent 4fe0a9f commit 89bb6c7
Show file tree
Hide file tree
Showing 3 changed files with 217 additions and 208 deletions.
15 changes: 12 additions & 3 deletions calyx-py/calyx/queue_data_gen.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import random
import json
import sys
from typing import Dict, Union
from calyx import queue_util

Expand All @@ -11,19 +12,23 @@ def format_gen(width: int) -> FormatType:
return {"is_signed": False, "numeric_type": "bitnum", "width": width}


def dump_json():
def dump_json(no_peeks: bool):
"""Prints a JSON representation of the data to stdout.
The data itself is populated randomly, following certain rules:
- It has three "memories": `commands`, `values`, and `ans_mem`.
- The `commands` memory has queue_util.MAX_CMDS items, which are 0, 1, or 2.
If the `no_peeks` flag is set, then items are chosen randomly from 0 and 2.
- The `values` memory has queue_util.MAX_CMDS items:
random values between 0 and 400.
- The `ans_mem` memory has queue_util.MAX_CMDS items, all zeroes.
- Each memory has a `format` field, which is a format object for a bitvector.
"""
commands = {
"commands": {
"data": [random.randint(0, 2) for _ in range(queue_util.MAX_CMDS)],
"data": [
random.choice([0, 2]) if no_peeks else random.randint(0, 2)
for _ in range(queue_util.MAX_CMDS)
],
"format": format_gen(2),
}
}
Expand All @@ -47,5 +52,9 @@ def dump_json():


if __name__ == "__main__":
# Accept a flag that we pass to dump_json.
# This says whether we should have any 1s in the `commands` memory.

no_peeks = len(sys.argv) > 1 and sys.argv[1] == "--no-peeks"
random.seed(5)
dump_json()
dump_json(no_peeks)
160 changes: 80 additions & 80 deletions calyx-py/test/correctness/piezo_pifotree.data
Original file line number Diff line number Diff line change
Expand Up @@ -2,105 +2,105 @@
"commands": {
"data": [
2,
1,
2,
1,
2,
0,
2,
0,
0,
0,
0,
2,
2,
0,
1,
0,
2,
0,
0,
0,
1,
1,
0,
1,
2,
2,
0,
2,
0,
0,
0,
2,
0,
1,
1,
0,
1,
0,
0,
0,
0,
0,
0,
2,
2,
0,
0,
0,
0,
2,
2,
1,
0,
2,
2,
0,
0,
2,
0,
2,
2,
0,
2,
0,
2,
2,
2,
2,
2,
0,
2,
2,
0,
1,
1,
0,
2,
0,
2,
2,
0,
2,
2,
2,
0,
2,
0,
1,
1,
0,
1,
1,
0,
0,
1,
0,
1,
1,
2,
2,
0,
2,
2,
2,
1,
0,
1,
1,
1,
1,
2,
1,
0,
1,
1,
2,
0,
2,
0,
1,
0,
2,
1,
1,
2,
0,
2,
1,
1,
1,
2,
0,
1,
2,
2,
2,
0,
2
0
],
"format": {
"is_signed": false,
Expand All @@ -110,46 +110,6 @@
},
"values": {
"data": [
92,
319,
100,
60,
386,
125,
236,
176,
262,
181,
268,
128,
397,
236,
55,
301,
383,
399,
188,
151,
18,
221,
46,
106,
174,
262,
312,
185,
75,
174,
141,
359,
279,
47,
159,
351,
162,
156,
90,
40,
320,
76,
369,
Expand Down Expand Up @@ -209,7 +169,47 @@
240,
206,
75,
57
57,
193,
272,
91,
321,
255,
173,
92,
45,
251,
139,
263,
400,
280,
257,
184,
32,
396,
182,
355,
300,
339,
17,
388,
156,
186,
286,
360,
342,
143,
248,
135,
394,
353,
366,
150,
174,
332,
91,
297,
5
],
"format": {
"is_signed": false,
Expand Down
Loading

0 comments on commit 89bb6c7

Please sign in to comment.