Skip to content

Commit 6014d46

Browse files
committed
Add gates and
1 parent 74e488c commit 6014d46

File tree

8 files changed

+78
-15
lines changed

8 files changed

+78
-15
lines changed

example.pfcf

+9
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,12 @@ H,
2828
.---X,
2929
c1,
3030
\</qiskit\>,
31+
32+
<qiskit>
33+
$host qasm_simulator
34+
q0 q1
35+
X
36+
H
37+
.---X
38+
c1
39+
</qiskit>

pfcf/__pycache__/code.cpython-38.pyc

614 Bytes
Binary file not shown.

pfcf/__pycache__/utils.cpython-38.pyc

147 Bytes
Binary file not shown.

pfcf/code.py

+32-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from pfcf.utils import *
2-
import pfcf.codel.qiskit as qiskit
2+
import pfcf.codel.qiskit as q
33

44
def codef(codel: str,text: str): #code function
55
form=".compile.py"
@@ -9,33 +9,57 @@ def codef(codel: str,text: str): #code function
99
t=qiskit(text)
1010
f.write(t)
1111
f.close()
12-
sleep(100)
12+
sleep(1000)
1313
delete(codel,form)
1414

1515
def qiskit(text: str):
1616
t=[]
17-
t.append("from qiskit import QuantumCircuit, execute, Aer")
18-
t.append("from qiskit.visualization import plot_histogram")
17+
t.append("from qiskit import QuantumCircuit, execute, Aer\n")
18+
t.append("from qiskit.visualization import plot_histogram\n")
1919
T=""
2020
s=0
2121
command=""
2222
param=""
23+
Q=0
24+
gate=""
25+
gatecount=0
26+
qdef=0
2327
for i in text:
2428
if s==1: #settings mode on
2529
if i!=" ":
2630
command+=i
2731
else:
2832
s=2
2933
elif s==2:
30-
if i!=" ":
34+
if i!=" " and i!="\n":
3135
param+=i
3236
else:
33-
qiskit.settings(command,param)
37+
t.append(q.settings(command,param))
3438
s=0
3539
elif i=="$":
36-
m=1
40+
s=1
41+
elif qdef==1:
42+
if i=="q":
43+
Q+=1
44+
elif i=="\n":
45+
qdef=2
46+
t.append("circuit== QuantumCircuit("+str(Q)+","+str(Q)+")\n")
47+
elif qdef==2:
48+
if i!="\n" and i!=" ":
49+
gate+=i
50+
elif i==" ":
51+
gatecount+=0.5
52+
t.append(q.quantum(gate,gatecount))
53+
gate=""
54+
else:
55+
t.append(q.quantum(gate,gatecount))
56+
gate=""
57+
gatecount=0
58+
elif i=="q":
59+
qdef=1
60+
Q+=1
3761

3862
for i in t:
39-
T+=i+"\n"
63+
T+=i
4064
return T
4165

138 Bytes
Binary file not shown.
1.19 KB
Binary file not shown.

pfcf/codel/qiskit.py

+32-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,43 @@
1-
global shots=1024
2-
1+
from pfcf.utils import *
32
def settings(command: str,param):
43
t=""
54
if command=="host":
6-
t0="backend=Aer.get_backend('"+param+"')\n"
7-
t1="job=execute(circuit, backend, shots="+shots+")\n"
5+
t0="s=1024\nbackend=Aer.get_backend('"+param+"')\n"
6+
t1="job=execute(circuit, backend, shots=s)\n"
87
t2="result=job.result()\n"
98
t3="counts=result.get_counts(circuit)\n"
109
t=t0+t1+t2+t3
1110
elif command=="shots":
12-
global shots=param
11+
t="s="+param
1312
elif command=="hist":
1413
t1="graph=plot_histogram(counts)\n"
1514
t2="display(graph)\n"
15+
t=t1+t2
16+
elif command=="draw":
17+
t="circuit.draw('mpl')\n"
18+
elif command=="inject":
19+
t=param+"\n"
1620
return t
21+
22+
def quantum(gate: str,n):
23+
t=""
24+
N=floor(n)
25+
n=str(N)
26+
T="circuit."
27+
if len(gate)==1:
28+
t=T+gate.lower()+"("+n+")\n"
29+
elif gate==".---X":
30+
t=T+"cx("+n+","+str(N+1)+")\n"
31+
elif gate=="X---.":
32+
t=T+"cx("+str(N+1)+","+n+")\n"
33+
else:
34+
number=""
35+
b=0
36+
for i in gate:
37+
if i!="c":
38+
number+=i
39+
else:
40+
b=1
41+
if b==1:
42+
t=T+"measure("+n+","+number+")\n"
43+
return t

pfcf/utils.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import time, os, json
1+
import time, os, json, math
22

33
def getLines(adress: str):
44
h=open(adress,"r")
@@ -19,4 +19,7 @@ def clearConsole():
1919
command = 'clear'
2020
if os.name in ('nt', 'dos'): # If Machine is running on Windows, use cls
2121
command = 'cls'
22-
os.system(command)
22+
os.system(command)
23+
24+
def floor(f: float):
25+
return math.floor(f)

0 commit comments

Comments
 (0)