Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Begin code tidy, per Flake8 #5

Merged
merged 12 commits into from
Mar 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ venv.bak/
.spyderproject
.spyproject

# Swap files
*.swp

# Rope project settings
.ropeproject

Expand Down
Binary file removed src/.file.qasm.swp
Binary file not shown.
5 changes: 5 additions & 0 deletions src/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import sys
from qeda.qeda import QEDAManager


def test():
"""Runs the test suite"""
print(test)
sys.exit(0)


def help():
"""Prints the help information to terminal"""
print("\t\tQEDA")
Expand All @@ -21,12 +23,14 @@ def help():
print("\n\nCopyright 2020 Spooky Manufacturing, LLC")
sys.exit(0)


def run(inf, outf, proc, verbose, pcb, schema):
"""Runs QEDA"""
print("Starting QEDA Manager")
x = QEDAManager(inf, outf, proc, verbose, pcb, schema)
sys.exit(0)


def main(args=None):
"""The main routine"""
inf = ""
Expand Down Expand Up @@ -82,5 +86,6 @@ def main(args=None):
print(str(err))
sys.exit(2)


if __name__ == '__main__':
main()
1 change: 0 additions & 1 deletion src/fp-info-cache

This file was deleted.

39 changes: 18 additions & 21 deletions src/qeda/automaker.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/python3
from math import ceil as CEIL
from math import ceil
from pcb import PCB, Segment
from pykicad.module import Module


class Automaker():
def __init__(self):
self.pcb = PCB()
Expand All @@ -18,13 +19,12 @@ def __init__(self):
b.set_reference('b')
c = Module.from_library('Resistors_SMD', 'R_0805')
c.set_reference('c')
qcode = [[a,b,c], [x,y], [z]]
qcode = [[a, b, c], [x, y], [z]]
self.automake(qcode)
pass

def _find_max_x(self, comp):
"""Returns the maximal X size as an integer"""
global CEIL
max_x = 0
geo = comp.geometry()
x = [each for each in geo]
Expand All @@ -39,11 +39,10 @@ def _find_max_x(self, comp):
y = abs(each.start[0] - each.end[0])
if y > max_x:
max_x = y
return CEIL(max_x)
return ceil(max_x)

def _find_max_y(self, comp):
"""Return maximal Y size as an integer"""
global CEIL
max_y = 0
geo = comp.geometry()
x = [each for each in geo]
Expand All @@ -58,7 +57,7 @@ def _find_max_y(self, comp):
y = abs(each.start[1] - each.end[1])
if y > max_y:
max_y = y
return CEIL(max_y)
return ceil(max_y)

def _find_maxes(self, comp):
"""Returns the maximal x and y value of a component (starting at 0,0)"""
Expand All @@ -72,29 +71,28 @@ def _find_x(self, pos, maxx):

def _find_y(sef, pos, maxy):
return pos[1] + maxy

def _autoplace_unitary_gates(self, qcode):
pos = {
'X': 0,
'Y': 0
}
}
max_y = 0
for qubit in qcode:
for i in range(len(qubit)):
# Place component (horizontal line)
self.pcb._place_component(qubit[i], pos['X'], pos['Y'])
print('Component is at ', qubit[i].at)
x, y = self._find_maxes(qubit[i])
#update x, y values
# update x, y values
pos['X'] = pos['X'] + x
if y > max_y:
max_y += y
#loop
# loop
# Step down y by max_x
pos['X'] = 0
pos['Y'] = pos['Y'] + max_y


# if i == len(qubit)-1:
# start, end, np_pos = self.pcb._final_compute(qubit[i])
# else:
Expand All @@ -107,23 +105,21 @@ def _autoplace_controlled_gates(self, qcode):
pos = {
'X': 0,
'Y': 0
}
}
max_y = 0




def _autoplace3(self, qcode):
"""Automagically places components where they need to be"""
pos = {
'X': 0,
'Y': 0
}
}
cur_x = 0
cur_y = 0
for qubit in qcode:
for i in range(len(qubit)):
# Connect pads
# self.pcb._connect_pad(qubit[i], 1, 1)
# self.pcb._connect_pad(qubit[i], 1, 1)
# Find maxes
x, y = self._find_maxes(qubit[i])
print(x)
Expand All @@ -135,18 +131,18 @@ def _autoplace3(self, qcode):
self.pcb._place_component(qubit[i], pos['X'], pos['Y'])
print('Component is at ', qubit[i].at)
# compute and place vias
if i == len(qubit)-1:
if i == len(qubit) - 1:
start, end, pos_np = self.pcb._final_compute(qubit[i])
else:
start, end, pos_np = self.pcb._compute_positions(
qubit[i], qubit[i+1])
qubit[i], qubit[i + 1])
# Create segments
self.pcb._create_segment(start, end, self.pcb.nets[1])
print('Rechecking, component is at ', qubit[i].at)
cur_x = 0
pos['X'] = cur_x
pos['Y'] = cur_y

def automake(self, qcode):
"""Attempts to automagically make a PCB from modules

Expand All @@ -160,12 +156,13 @@ def automake(self, qcode):
For quantum gates, we only need to place footprints.

For electrical/analog gates we will need to computer positions, vias, etc"""
#Place components
# Place components
self._autoplace(qcode)
# Create PCB Zones
self.pcb._create_zones()
# Make the PCB
self.pcb._create_pcb()


if __name__ == '__main__':
a = Automaker()
41 changes: 20 additions & 21 deletions src/qeda/gates.py
Original file line number Diff line number Diff line change
@@ -1,69 +1,68 @@
from primitives import U1, U2, U3

global PI

PI = 3.14159


class X(U3):
global PI
def __init__(self):
self.theta = PI
self.phi = 0
self.lamda = PI
pass


class Y(U3):
global PI
def __init__(self):
self.theta = PI
self.phi = PI/2
self.lamda = PI/2
pass
self.phi = PI / 2
self.lamda = PI / 2


class Z(U1):
global PI
def __init__(self):
self.lamda = PI
pass


class H(U2):
global PI
def __init__(self):
self.phi = 0
self.lamda = PI


class S(U1):
global PI
def __init__(self):
self.lamda = PI/2
self.lamda = PI / 2


class SDG(U1):
global PI
def __init__(self):
self.lamda = -PI/2
self.lamda = -PI / 2


class T(U1):
global PI
def __init__(self):
self.lamda = PI/4
self.lamda = PI / 4


class TDG(U1):
global PI
def __init__(self):
self.lamda = -PI/4
self.lamda = -PI / 4


class RX(U3):
global PI
def __init__(self, theta):
self.theta = theta
self.phi = -PI/2
self.lamda = PI/2
self.phi = -PI / 2
self.lamda = PI / 2


class RY(U3):
def __init__(self, theta):
self.theta = theta
self.phi = 0
self.lamda = 0


class RZ(U1):
def __init__(self, lamda):
self.lamda = lamda
Expand Down
8 changes: 4 additions & 4 deletions src/qeda/lexer.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from rply import LexerGenerator


class Lexer():
def __init__(self):
self.lexer = LexerGenerator()

def _add_tokens(self):
# Specification
self.lexer.add('OPENQASM', r'(?i)OPENQASM')
#String support
# String support
self.lexer.add('STRING', r'".*"')
self.lexer.add('STRING', r"'.*'")
# Includes
Expand Down Expand Up @@ -54,7 +55,7 @@ def _add_tokens(self):
self.lexer.add('EXP', r'(?i)exp')
self.lexer.add('LN', r'(?i)ln')
self.lexer.add('SQRT', r'(?i)sqrt')
#ID support
# ID support
self.lexer.add('ID', r'[a-z][A-Za-z0-9_]*|[A-Z][A-Za-z0-9_]*')
# Numbers
self.lexer.add('REAL', r'([0-9]+\.[0-9]*|[0-9]*\.[0-9]+)([eE][-+]?[0-9]+)?')
Expand All @@ -63,9 +64,8 @@ def _add_tokens(self):
#self.lexer.add('CHARS', r'[A-Za-z]*')
self.lexer.add('DOT', r'\.')


# Other Chars
self.lexer.ignore('\s+')
self.lexer.ignore(r'\s+')
# Ignore Comments
self.lexer.ignore(r'\//.*//')
self.lexer.ignore(r'\\\.*\\')
Expand Down
Loading