Skip to content

Commit 8d28fad

Browse files
committed
Update settings function
1 parent 6014d46 commit 8d28fad

16 files changed

+77
-48
lines changed

example.pfcf

+7-3
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,23 @@ by Eanorambuena,|
2121

2222
Add qiskit code like this:,|
2323
\<qiskit\>,
24-
$host qasm_simulator,
2524
q0 q1,
2625
X,
2726
H,
2827
.---X,
2928
c1,
29+
$host qasm_simulator,
30+
$hist true,
31+
$draw true,
3032
\</qiskit\>,
3133

3234
<qiskit>
33-
$host qasm_simulator
3435
q0 q1
3536
X
3637
H
3738
.---X
3839
c1
39-
</qiskit>
40+
$host qasm_simulator
41+
$hist true
42+
$draw true
43+
</qiskit>,

example.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ by Eanorambuena
1818
Add qiskit code like this:
1919

2020
<qiskit>
21-
$host qasm_simulator
2221
q0 q1
2322
X
2423
H
2524
.---X
2625
c1
26+
$host qasm_simulator
27+
$hist true
28+
$draw true
2729
</qiskit>

main.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from pfcf.read import read,executepfcf
2-
2+
from pfcf.utils import execute
33
name="example"
4+
#execute("qiskit_compile")
45
executepfcf(name)

pfcf/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from pfcf.files import *
22
from pfcf.read import *
3-
from pfcf.parser import *
3+
from pfcf.utils import *
-1 Bytes
Binary file not shown.

pfcf/__pycache__/code.cpython-38.pyc

-65 Bytes
Binary file not shown.

pfcf/__pycache__/files.cpython-38.pyc

-23 Bytes
Binary file not shown.

pfcf/__pycache__/read.cpython-38.pyc

4 Bytes
Binary file not shown.

pfcf/__pycache__/utils.cpython-38.pyc

1.47 KB
Binary file not shown.

pfcf/code.py

+12-14
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,18 @@
22
import pfcf.codel.qiskit as q
33

44
def codef(codel: str,text: str): #code function
5-
form=".compile.py"
5+
form="_compile.py"
66
f=open(codel+form,"w")
77
t=""
88
if codel=="qiskit":
99
t=qiskit(text)
1010
f.write(t)
1111
f.close()
12-
sleep(1000)
13-
delete(codel,form)
1412

1513
def qiskit(text: str):
16-
t=[]
17-
t.append("from qiskit import QuantumCircuit, execute, Aer\n")
18-
t.append("from qiskit.visualization import plot_histogram\n")
1914
T=""
15+
T+="from qiskit import QuantumCircuit, execute, Aer\n"
16+
T+="from qiskit.visualization import plot_histogram,display\n"
2017
s=0
2118
command=""
2219
param=""
@@ -25,7 +22,9 @@ def qiskit(text: str):
2522
gatecount=0
2623
qdef=0
2724
for i in text:
28-
if s==1: #settings mode on
25+
if i==",":
26+
pass
27+
elif s==1: #settings mode on
2928
if i!=" ":
3029
command+=i
3130
else:
@@ -34,7 +33,9 @@ def qiskit(text: str):
3433
if i!=" " and i!="\n":
3534
param+=i
3635
else:
37-
t.append(q.settings(command,param))
36+
T+=q.settings(command,param)
37+
command=""
38+
param=""
3839
s=0
3940
elif i=="$":
4041
s=1
@@ -43,23 +44,20 @@ def qiskit(text: str):
4344
Q+=1
4445
elif i=="\n":
4546
qdef=2
46-
t.append("circuit== QuantumCircuit("+str(Q)+","+str(Q)+")\n")
47+
T+="circuit=QuantumCircuit("+str(Q)+","+str(Q)+")\n"
4748
elif qdef==2:
4849
if i!="\n" and i!=" ":
4950
gate+=i
5051
elif i==" ":
5152
gatecount+=0.5
52-
t.append(q.quantum(gate,gatecount))
53+
T+=q.quantum(gate,gatecount)
5354
gate=""
5455
else:
55-
t.append(q.quantum(gate,gatecount))
56+
T+=q.quantum(gate,gatecount)
5657
gate=""
5758
gatecount=0
5859
elif i=="q":
5960
qdef=1
6061
Q+=1
61-
62-
for i in t:
63-
T+=i
6462
return T
6563

0 Bytes
Binary file not shown.

pfcf/files.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from pfcf.read import *
2-
from pfcf.parser import *
32
from pfcf.utils import *
43

54
class FilesTree:

pfcf/parser.py

-23
This file was deleted.

pfcf/read.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from pfcf.utils import *
2-
from pfcf.parser import *
32
from pfcf.code import *
43

54
def read(name: str,printYesOrNo: int =1,returnText: int =0):
@@ -35,14 +34,17 @@ def read(name: str,printYesOrNo: int =1,returnText: int =0):
3534
if codel2==codel:
3635
codef(codel,code)
3736
codem==0
37+
codel=""
38+
codel2=""
39+
else:
40+
print("Sintax error")
3841
elif codem==3:
3942
if j!="/":
4043
codel2+=j
4144
elif codem==2:
4245
code+=j
4346
elif codem==1: #Code mode on
44-
if j!=" ":
45-
codel+=j
47+
codel+=j
4648
elif p.separator(j):
4749
T+=t+"\n"
4850
t=""

pfcf/utils.py

+32-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,35 @@ def clearConsole():
2222
os.system(command)
2323

2424
def floor(f: float):
25-
return math.floor(f)
25+
return math.floor(f)
26+
27+
class Parser():
28+
def __init__(self,name: str ="Parser"):
29+
self.sep=[',']
30+
self.sec=['|']
31+
self.ski=["\""]
32+
self.vip=["\\"]
33+
self.den=["~"]
34+
self.name=name
35+
def compare(self,x: str,arr):
36+
k = False
37+
for i in arr:
38+
k =( k or x==i)
39+
return k
40+
def separator(self,x: str ):
41+
return self.compare(x,self.sep)
42+
def section(self,x: str):
43+
return self.compare(x,self.sec)
44+
def skip(self,x: str):
45+
return self.compare(x,self.ski)
46+
def isVip(self,x: str):
47+
return self.compare(x,self.vip)
48+
def isDeny(self,x: str):
49+
return self.compare(x,self.den)
50+
51+
def execute(name):
52+
try:
53+
t="/usr/bin/python "+name+".py"
54+
os.system(t)
55+
except:
56+
print("Execute error in: "+"/usr/bin/python "+name+".py")

qiskit_compile.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from qiskit import QuantumCircuit, execute, Aer
2+
from qiskit.visualization import plot_histogram,display
3+
circuit=QuantumCircuit(2,2)
4+
circuit.x(2)
5+
circuit.h(0)
6+
circuit.cx(0,1)
7+
circuit.measure(0,1)
8+
s=1024
9+
backend=Aer.get_backend('qasm_simulator')
10+
job=execute(circuit, backend, shots=s)
11+
result=job.result()
12+
counts=result.get_counts(circuit)
13+
graph=plot_histogram(counts)
14+
display(graph)
15+
circuit.draw('mpl')

0 commit comments

Comments
 (0)