Skip to content

Commit 07c2dd8

Browse files
Added QuaC compiler
Added files QuaCLexer.h, QuaCParser.h, QUaCExecutor.h, HashMap.h, Types.h and some examples
1 parent 16c819a commit 07c2dd8

File tree

15 files changed

+1368
-302
lines changed

15 files changed

+1368
-302
lines changed

.DS_Store

2 KB
Binary file not shown.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,5 @@ dkms.conf
5353

5454
.vscode
5555
quacc
56+
Aux files
57+
TestInput.qc

Examples/Grover_search.qc

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
# Two qubit grover search to find the number '2' or '10' in binary representation
22

3-
func grover_search_10 {
3+
func grover_search {
44
[H, H]
55
[-, S]
66
[-, H]
7-
[Co, Cx]
7+
[@, X]
88
[-, H]
99
[-, S]
1010
[H, H]
1111
[X, X]
1212
[-, H]
13-
[Co, Cx]
13+
[@, X]
1414
[-, H]
1515
[X, X]
1616
[H, H]
1717
}
1818

19-
quReg a = init [2]
20-
a.name = "quReg1: "
21-
a.prec = 6
19+
quReg a = new quReg[2] => 'quReg1'
20+
a.setPrecision(6)
2221

2322
a.Pa()
24-
a.grover_search_10()
23+
a.grover_search()
2524
a.Pa()

Examples/Hadamard_Fever.qc

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
# Hadamard Fever for 28 qubits!!! (only attempt to run if your system has a minimum of 8GB RAM)
22

33
func Hadamard_Fever {
4-
[H, H, H, H, H, H, H, H, H, H, H, H, H, H, -, -, -, -, -, -, -, -, -, -, -, -, -, -]
5-
Pnz()
6-
[-, -, -, -, -, -, -, -, -, -, -, -, -, -, H, H, H, H, H, H, H, H, H, H, H, H, H, H]
7-
4+
[H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H]
85
[H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H, H]
96
}
107

11-
quReg a = init [28]
12-
a.name = "quReg1: "
13-
a.prec = 6
8+
quReg a = new quReg[28] => 'quReg1'
9+
a.setPrecision(6)
1410

1511
a.Pnz()
1612
a.Hadamard_Fever()

Examples/basic.qc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ func basic {
66
[H, H]
77
}
88

9-
quReg a = init [2]
10-
a.name = "quReg1: "
11-
a.prec = 6
9+
quReg a = new quReg[2] => 'quReg1'
10+
a.setPrecision(6)
1211

1312
a.Pa()
1413
a.basic()

Examples/grover.qc

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
gate Uw[6] {
2+
[-, -, -, X, -, -]
3+
[X, @, @, @, @, @]
4+
[-, -, -, X, -, -]
5+
}
6+
7+
gate Us[6] {
8+
[-, H, H, H, H, H]
9+
[-, X, X, X, X, X]
10+
[X, @, @, @, @, @]
11+
[-, X, X, X, X, X]
12+
[-, H, H, H, H, H]
13+
}
14+
15+
func grover {
16+
[X, -, -, -, -, -]
17+
[H, H, H, H, H, H]
18+
[Uw]
19+
[Us]
20+
[Uw]
21+
[Us]
22+
[Uw]
23+
[Us]
24+
[Uw]
25+
[Us]
26+
Pa()
27+
}
28+
29+
quReg qr = new quReg[6] => 'qr1'
30+
qr.setPrecision(6)
31+
32+
qr.Pnz()
33+
qr.grover()
34+
qr.Pnz()
35+
36+
37+
######################################
38+
# Pauli-X: X
39+
# Pauli-Y: Y
40+
# Pauli-Z: Z
41+
# Phase: S
42+
# Rotation: R
43+
# Hadamard: H
44+
# Swap: x
45+
# QFT: ~
46+
# Control: @
47+
# Inverse Control: o
48+
# Power: <gate> ^ <num> (optional)
49+
# X-axis control: +
50+
# Y-axis control: *
51+
# Identity gate: -

Examples/shor.qc

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
func shor {
2+
[X, -, -, -, H, H, H, H]
3+
4+
[-, X, -, -, @, -, -, -]
5+
[-, -, X, -, @, -, -, -]
6+
7+
[-, X, -, @, -, @, -, -]
8+
[-, @, -, X, -, @, -, -]
9+
[-, X, -, @, -, @, -, -]
10+
[X, -, @, -, -, @, -, -]
11+
[@, -, X, -, -, @, -, -]
12+
[X, -, @, -, -, @, -, -]
13+
14+
[-, -, -, -, Q, Q, Q, Q]
15+
}
16+
17+
quReg q = init [8]
18+
q.name = "qr1: "
19+
q.prec = 6
20+
21+
q.Pnz()
22+
q.shor()
23+
q.Pnz()
24+
25+
######################################
26+
# Pauli-X: X
27+
# Pauli-Y: Y
28+
# Pauli-Z: Z
29+
# Phase: S
30+
# Rotation: R
31+
# Hadamard: H
32+
# Swap: x
33+
# QFT: ~
34+
# Control: @
35+
# Inverse Control: o
36+
# Power: <gate> ^ <num> (optional)
37+
# X-axis control: +
38+
# Y-axis control: *

QuaCLibs/HashMap.h

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#ifndef HASHMAP_H
2+
#define HASHMAP_H
3+
4+
#include "Types.h"
5+
6+
typedef struct kt {
7+
char *key;
8+
Type type;
9+
}KeyTypes;
10+
11+
typedef struct hm {
12+
KeyTypes *kt;
13+
int len;
14+
int maxSize;
15+
}HashMap;
16+
17+
HashMap* newHashMap() {
18+
int MS = 2;
19+
HashMap *hm = (HashMap*) malloc(sizeof(HashMap));
20+
hm-> kt = (KeyTypes*) malloc(MS * sizeof(KeyTypes));
21+
hm->len = 0;
22+
hm->maxSize = MS;
23+
return hm;
24+
}
25+
26+
void insertHM(HashMap *hm, char k[], Type t) {
27+
int i;
28+
int len = 0;
29+
for(i = 0; k[i] != '\0'; i++)
30+
len++;
31+
32+
if(hm->len == hm->maxSize) {
33+
int enlarge = hm->maxSize * 2;
34+
hm->kt = (KeyTypes*) realloc(hm->kt, (enlarge+1) * sizeof(KeyTypes));
35+
hm->maxSize = enlarge;
36+
// printf("Enlarged to %d\n", hm->maxSize);
37+
}
38+
39+
hm->kt[hm->len].key = (char*) malloc(len * sizeof(char));
40+
strcpy(hm->kt[hm->len].key, k);
41+
hm->kt[hm->len].type = t;
42+
hm->len++;
43+
}
44+
45+
void displayMap(HashMap hm) {
46+
int i;
47+
for(i = 0; i < hm.len; i++) {
48+
printf("'%s' : %s\n", hm.kt[i].key, Types_str[hm.kt[i].type]);
49+
}
50+
}
51+
52+
Type* toArrayofTypes(HashMap hm) {
53+
Type *t = (Type*) malloc(hm.len * sizeof(Type));
54+
int i = 0;
55+
for(i = 0; i < hm.len; i++) {
56+
t[i] = hm.kt[i].type;
57+
}
58+
59+
return t;
60+
}
61+
62+
KeyTypes* toArrayOfKeyTypes(HashMap hm) {
63+
KeyTypes *kt = (KeyTypes*) malloc(hm.len * sizeof(KeyTypes));
64+
int i;
65+
for(i = 0; i < hm.len; i++) {
66+
kt[i].key = (char*) malloc(strlen(hm.kt[i].key) * sizeof(char));
67+
strcpy(kt[i].key, hm.kt[i].key);
68+
kt[i].type = hm.kt[i].type;
69+
}
70+
71+
return kt;
72+
}
73+
74+
#endif

0 commit comments

Comments
 (0)