generated from eanorambuena/Driver
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
671ed94
commit 9ba2b57
Showing
18 changed files
with
204 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.