-
Notifications
You must be signed in to change notification settings - Fork 7
/
check.py
executable file
·48 lines (43 loc) · 2.31 KB
/
check.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
#!/usr/bin/env python3
import os
import subprocess
import sys
if not os.path.exists("./twist"):
print("Error: Please execute `make` to produce the `twist` binary first.")
sys.exit(1)
tests = [
("Teleport", "paper/teleport.q", True),
("Teleport-NoCZ", "paper/teleport-noCZ.q", False),
("Teleport-Measure", "paper/teleport-measure.q", True),
("AndOracle", "paper/andoracle.q", True),
("AndOracle-NotUncomputed", "paper/andoracle-notuncomputed.q", False),
("Bell-GHZ", "paper/bell-ghz.q", False),
("Deutsch", "paper/deutsch.q", True),
("Deutsch-MissingH", "paper/deutsch-missingH.q", False),
("DeutschJozsa", "paper/deutschjozsa.q", True),
("DeutschJozsa-MixedInit", "paper/deutschjozsa-mixedinit.q", False),
("Grover", "paper/grover.q", True),
("Grover-BadOracle", "paper/grover-badoracle.q", False),
("QFT", "paper/qft.q", True),
("ShorCode", "paper/shorcode.q", True),
("ShorCode-Drop", "paper/shorcode-drop.q", False),
("ModMul(4)", "multiply/multiply4.q", True),
("ModMul(4)-NotInverse", "multiply/multiply4-notinverse.q", False),
("ModMul(12)", "multiply/multiply12.q", True),
("ModMul(12)-NotInverse", "multiply/multiply12-notinverse.q", False),
]
print(f'Executing the Twist interpreter on {len(tests)} benchmarks and parsing outputs.')
print('Results:\n')
print('| Paper Benchmark | Filename | Valid | Types | Static | Dynamic |')
print('| ----------------------- | ---------------------------------- | ----- | ----- | ------ | ------- |')
use_mixed = "-mixed" in sys.argv
for (name, test, valid) in tests:
result = subprocess.run(["./twist"] + (["-ignore_static", "-mixed"] if use_mixed else []) + ["-no_print", "tests/" + test], capture_output=True, text=True).stdout.split("\n")[1:-1]
types = 'Type checking successful' in result
static = 'Static analysis successful' in result if not use_mixed else True
dynamic = 'Program executed successfully.' in result
def fmt(prev, x):
if x: return ' o '
elif prev: return ' x '
else: return 'N/A'
print(f'| {name:23} | {"`" + test + "`":34} | {" " + fmt(True, valid) + " "} | {" " + fmt(True, types) + " "} | {" " + ("N/A" if use_mixed else fmt(types, static)) + " "} | {" " + fmt(types if use_mixed else types and static, dynamic) + " "} |')