Skip to content

Commit

Permalink
0.0.1a3
Browse files Browse the repository at this point in the history
  • Loading branch information
eanorambuena committed Aug 23, 2021
1 parent 671ed94 commit 9ba2b57
Show file tree
Hide file tree
Showing 18 changed files with 204 additions and 154 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ Natural Quantum Script is a special domain programming language that aims to sim

Scripts written in NQS seek to visually resemble quantum circuits as much as possible. For example:

q0 q1
X
H
.--- X
c1
q0 q1<br>
X<br>
H<br>
.--- X<br>
c1<br>

NQS is initially based on Qiskit, but seeks to go mainstream in the future. This is an OS project whose initial goal was to make it easier to write basic scripts in Qiskit and to bridge the gap for people who don't dare to delve into quantum computing.

Expand Down
46 changes: 21 additions & 25 deletions build/lib/eggdriver/app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Imports
from eggdriver.resources.console import get, clearConsole
from eggdriver.resources.console import get, clearConsole, pg
from eggdriver.resources.constants import *
from eggdriver.resources.modules import installFromRequests, upgrade, Repo
from eggdriver.resources.help import help
Expand Down Expand Up @@ -28,42 +28,38 @@
This is the reason why condition only allows <<bool>> as data type
"""
def eggConsole(condition: bool = True):
print(white+"Egg Console is now running")
"""Display the Egg Console"""
print(white + "Egg Console is now running")
logged=0
while condition:
i=get("egg")
if i=="$nqs":
i = get("egg")
if i == "$nqs":
from eggdriver.nqs import developerConsole
developerConsole()
elif i=="$new":
elif i == "$new":
from eggdriver.news import journalistConsole
journalistConsole()
elif i=="$login":
elif i == "$login":
login()
elif i=="$register":
elif i == "$register":
register()
elif i=="$install":
print(white+"Package:")
name=get("egg")
elif i == "$install":
name = pg("Package:")
installFromRequests([name], False)
elif i=="$upgrade":
print(white+"Package:")
name=get("egg")
elif i == "$upgrade":
name = pg("Package:")
upgrade(name)
elif i=="$pull":
print(white+"Repo:")
name=get("egg")
repo=Repo(name)
print(white+"Package:")
package=get("egg")
last=repo.pull(package)
# *comming soon*
elif i=="$help":
elif i == "$pull":
org = pg("User or Organization:")
name = pg("Repository:")
repo = Repo(org, name)
repo.pull()
elif i == "$help":
help()
elif i=="$clear":
elif i == "$clear":
clearConsole()
elif i=="$end":
print(white+"Egg Console stopped running")
elif i == "$end":
print(white + "Egg Console stopped running")
return "done"
else:
pass
1 change: 1 addition & 0 deletions build/lib/eggdriver/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
>>> Requirement already satisfied: pip in <root> (21.2.4)
"""
def init():
"""Upgrade pip and install all the packages in requests file"""
install_option_1("$upgrade") # Upgrade pip
sleep(10) # Waits 10 ms
installFromRequests() # Install all the packages in requests file
8 changes: 4 additions & 4 deletions build/lib/eggdriver/nqs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from eggdriver.nqs.core import *
from eggdriver.nqs.developer import *

_author="eanorambuena"
_author_email="eanorambuena@uc.cl"
author = "eanorambuena"
author_email = "eanorambuena@uc.cl"

nqsCommands=[
nqsCommands = [
"host",
"shots",
"hist",
Expand All @@ -15,7 +15,7 @@
"delay"
]

consoleCommands=[
consoleCommands = [
"display",
"compile",
"save",
Expand Down
4 changes: 2 additions & 2 deletions build/lib/eggdriver/nqs/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
from eggdriver.nqs.core.quantum import *
from eggdriver.nqs.core.reader import *

_author="eanorambuena"
_author_email="eanorambuena@uc.cl"
author="eanorambuena"
author_email="eanorambuena@uc.cl"
58 changes: 29 additions & 29 deletions build/lib/eggdriver/nqs/core/functions.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
from eggdriver.resources.extensions import py

class Func():
def __init__(self,name: str,params,actions,indexfile: str,definitionsfile: str):
self.name=name
self.params=params
self.actions=actions
self.indexfile=indexfile
self.definitionsfile=definitionsfile
def __init__(self, name: str, params, actions, indexfile: str, definitionsfile: str):
self.name = name
self.params = params
self.actions = actions
self.indexfile = indexfile
self.definitionsfile = definitionsfile
def index(self):
#lines=py.getLines(self.indexfile)
lines=py.read(self.indexfile).split("\n")
# lines = py.getLines(self.indexfile)
lines = py.read(self.indexfile).split("\n")
lines.pop()
newline="\'"+self.name+"\': Definition."+self.name+", "
newline = f"\'{self.name}\': Definition.{self.name}, "
lines.append(newline)
lines.append("}")
text=""
text = ""
for i in lines:
text+=i+"\n"
py.write(text,self.indexfile)
text += i + "\n"
py.write(text, self.indexfile)
def define(self):
T="\tdef "+self.name+"("
last=self.params[-1]
j=self.params
T = "\tdef {self.name}("
last = self.params[-1]
j = self.params
j.pop()
for i in j:
T+=i+","
T+=last+"):\n"
T += i + ","
T += last + "):\n"
for i in self.actions:
T+="\t\t"+i+"\n"
py.append(T,self.definitionsfile)
T += "\t\t{i}\n"
py.append(T, self.definitionsfile)
def add(self):
self.define()
self.index()

def clear(param: str):
if param=="all":
t1="from user.definitions import Definition\n"
t1+="Index = { \n"
t1+="\'__init__\': Definition.__init__, # Do not remove this function, Index must not be void\n"
t1+="}\n"
py.write(t1,"user/index")
t2="class Definition():\n"
t2+="\tdef __init__(): # Do not remove this function, Definition must not be void\n"
t2+="\t\treturn \"done\""
py.write(t2,"user/definitions")
if param == "all":
t1 = "from user.definitions import Definition\n"
t1 += "Index = { \n"
t1 += "\'__init__\': Definition.__init__, # Do not remove this function, Index must not be void\n"
t1 += "}\n"
py.write(t1, "user/index")
t2 = "class Definition():\n"
t2 += "\tdef __init__(): # Do not remove this function, Definition must not be void\n"
t2 += "\t\treturn \"done\""
py.write(t2, "user/definitions")
80 changes: 40 additions & 40 deletions build/lib/eggdriver/nqs/core/reader.py
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
from eggdriver.library import nqsCommands, eggConsoleCommands
from eggdriver.nqs.core.functions import Func,clear
from eggdriver.nqs.core.functions import Func, clear
from eggdriver.resources.console import sleep

def settings(command: str,param):
t=""
if command=="host":
t="s=1024\nbackend=Aer.get_backend('"+param+"')\n"
t+="job=execute(circuit, backend, shots=s)\n"
t+="result=job.result()\n"
t+="counts=result.get_counts(circuit)\n"
elif command=="shots":
t="s="+param
elif command=="hist":
t="graph=plot_histogram(counts)\n"
t+="display(graph)\n"
elif command=="draw":
t="circuit.draw('mpl')\n"
elif command=="inject":
t=param+"\n"
elif command=="function":
p=Parameter(param)
def settings(command: str, param):
t = ""
if command == "host":
t = "s=1024\nbackend=Aer.get_backend('" + param + "')\n"
t += "job=execute(circuit, backend, shots=s)\n"
t += "result=job.result()\n"
t += "counts=result.get_counts(circuit)\n"
elif command == "shots":
t = "s=" + param
elif command == "hist":
t = "graph=plot_histogram(counts)\n"
t += "display(graph)\n"
elif command == "draw":
t = "circuit.draw('mpl')\n"
elif command == "inject":
t = param+"\n"
elif command == "function":
p = Parameter(param)
if p.name in nqsCommands or p.name in eggConsoleCommands:
print("Error: "+p.name+" is protected.")
print("Error: " + p.name + " is protected.")
return t
f=Func(p.name,p.params,p.actions,"user/index","user/definitions")
f = Func(p.name, p.params, p.actions, "user/index", "user/definitions")
f.add()
elif command=="clear":
elif command == "clear":
clear(param)
elif command=="delay":
elif command == "delay":
sleep(int(param))
else:
params=param.split(",")
t=executeFunction(command,params)
params = param.split(",")
t = executeFunction(command, params)
return t

class Parameter():
def __init__(self,param: str):
arr=param.split("|")
self.name=arr[0]
paramsBeforeSplit=arr[1]
self.params=paramsBeforeSplit.split(",")
actionsBeforeSplit=arr[2]
self.actions=actionsBeforeSplit.split(",")
def __init__(self, param: str):
arr = param.split("|")
self.name = arr[0]
paramsBeforeSplit = arr[1]
self.params = paramsBeforeSplit.split(",")
actionsBeforeSplit = arr[2]
self.actions = actionsBeforeSplit.split(",")

def executeFunction(command,params):
t="try:\n"
t+="\tIndex[\""+command+"\"]("
last=params[-1]
def executeFunction(command, params):
t = "try:\n"
t += "\tIndex[\""+command+"\"]("
last = params[-1]
params.pop()
for i in params:
t+="\""+i+"\""+","
t+="\""+last+"\""+")\n"
t+="except:\n"
t+="\tprint(\"Error: "+command+" is not defined or is inaccessible\")\n"
t += "\"" + i + "\","
t += "\"" + last + "\")\n"
t += "except:\n"
t += "\tprint(\"Error: " + command + " is not defined or is inaccessible\")\n"
return t
4 changes: 2 additions & 2 deletions build/lib/eggdriver/nqs/developer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
from eggdriver.nqs.developer.run import *
from eggdriver.nqs.developer.write import *

_author="eanorambuena"
_author_email="eanorambuena@uc.cl"
author = "eanorambuena"
author_email = "eanorambuena@uc.cl"
42 changes: 21 additions & 21 deletions build/lib/eggdriver/nqs/developer/app.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
from eggdriver.nqs.developer.run import run
from eggdriver.nqs.core import compile
from eggdriver.nqs.core.core import compile
from eggdriver.resources.extensions import nqa
from eggdriver.resources.console import display, get, sleep
from eggdriver.resources.constants import *

def developerDisplay(name: str):
content=nqa.read(name)
content = nqa.read(name)
display(content)

def developerConsole(condition: bool = True):
print(white+"Developer Console is now running")
print(white + "Developer Console is now running")
while condition:
i=get("nqs")
name="temp_compile"
if i=="$display":
content=nqa.read(name)
print(white+content)
elif i=="$compile":
i = get("nqs")
name = "temp_compile"
if i == "$display":
content = nqa.read(name)
print(white + content)
elif i == "$compile":
compile(name)
elif i=="$save":
print(white+"Save as:")
adress=get("nqs")
content=nqa.read(name)
nqa.write(content,adress)
elif i=="$run":
elif i == "$save":
print(white + "Save as:")
adress = get("nqs")
content = nqa.read(name)
nqa.write(content, adress)
elif i == "$run":
run(name)
elif i=="$delay":
print(white+"How many milliseconds?")
delta=get("nqs")
elif i == "$delay":
print(white + "How many milliseconds?")
delta = get("nqs")
sleep(int(delta))
elif i=="$end":
elif i == "$end":
try:
nqa.delete(name)
except:
pass
print(white+"Developer Console stopped running")
print(white + "Developer Console stopped running")
return "done"
else:
nqa.append(i+"\n",name)
nqa.append(i + "\n", name)
3 changes: 3 additions & 0 deletions build/lib/eggdriver/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

"""
FUNCTION build()
Build and upload a pypi package release
In Windows is equal to type in the console the following lines:
py -m build --sdist
py -m build --wheel
py -m twine check dist/*
py -m twine upload dist/*
"""
def build():
"""Build and upload a pypi package release"""
installFromRequests(["setuptools", "twine", "build"], False)
sysCommand("-m build --sdist")
sysCommand("-m build --wheel")
Expand Down
Loading

0 comments on commit 9ba2b57

Please sign in to comment.