Skip to content
Closed
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
28 changes: 23 additions & 5 deletions wdl/wavgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import os
import collections

from genericToken import LexerError

# from IPython.core.debugger import Tracer
# from IPython.core.magic import register_line_magic
# import time as t
Expand Down Expand Up @@ -1062,6 +1064,8 @@ def plot(self, cycles=2, initialLevel=None):
# Tracer()()
return

def state_empty(sstr):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggest we start modernising just a little. This should work with anything > python 3.5

def state_empty(sstr: str) -> bool:

etc

return len(sstr.replace('"', '')) == 0

def state(outfile=None):
"""write states from the UniqueStateArr to the
Expand Down Expand Up @@ -1128,6 +1132,8 @@ def state(outfile=None):
)

statestring = statestring[:-1] + '"'
if state_empty(statestring):
print("Empty state: %d" % ii)
ofile.write(statestring + "\n")
offset += 2 * __chan_per_board__["drvr"] # !driver-speed-keep
for lvdsslot in slot["lvds"]:
Expand All @@ -1141,6 +1147,8 @@ def state(outfile=None):
else:
statestring += "%d,0," % (UniqueStateArr[ii, jj_level])
statestring = statestring[:-1] + '"'
if state_empty(statestring):
print("Empty state: %d" % ii)
ofile.write(statestring + "\n")
offset += 2 * __chan_per_board__["lvds"]
for htrslot in slot["htr"]:
Expand All @@ -1154,6 +1162,8 @@ def state(outfile=None):
else:
statestring += "%d,0," % (UniqueStateArr[ii, jj_level])
statestring = statestring[:-1] + '"'
if state_empty(statestring):
print("Empty state: %d" % ii)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these look like many functions almost identical can we refactor?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a plan for refactoring the entire repository. This PR was made only to fix the specific problem in Issue #27. I cannot guarantee that the refactoring you are requesting would be done in a timely manner.

ofile.write(statestring + "\n")
offset += 2 * __chan_per_board__["htr"]
for xvslot in slot["xvbd"]: # this is similar to the hvbd states
Expand Down Expand Up @@ -1214,9 +1224,9 @@ def state(outfile=None):
nxvbd_chan = np.where(nxvbdKeep == 0)[0]
statestring += "1,%d,%g" % (nxvbd_chan + 1, nxvbdLevel[nxvbd_chan])
else:
print(
"Error in negative XVBD state call -- multiple changes "
"in a state"
raise LexerError(
"Error in negative XVBD state call -- multiple changes in state "
+ str(ii)
)
# statestring = statestring[:-1] + '"'
ofile.write(statestring + '"\n')
Expand All @@ -1232,6 +1242,8 @@ def state(outfile=None):
else:
statestring += "%d,0," % (UniqueStateArr[ii, jj_level])
statestring = statestring[:-1] + '"'
if state_empty(statestring):
print("Empty state: %d" % ii)
ofile.write(statestring + "\n")
offset += 2
if True: # Backplane
Expand Down Expand Up @@ -1271,7 +1283,10 @@ def state(outfile=None):
hvbd_chan = np.where(hvbdKeep == 0)[0]
statestring += "1,%d,%g" % (hvbd_chan + 1, hvbdLevel[hvbd_chan])
else:
print("Error in HVBD state call -- multiple changes in a state")
raise LexerError(
"\nError in HVBD state call -- multiple changes in state "
+ str(ii)
)
ofile.write(statestring + '"\n')
offset += n_hvbd_X_2
for lvbdslot in slot["lvbd"]:
Expand Down Expand Up @@ -1318,7 +1333,10 @@ def state(outfile=None):
lvbd_chan = np.where(lvbdKeep == 0)[0]
statestring += "1,%d,%g" % (lvbd_chan + 1, lvbdLevel[lvbd_chan])
else:
print("Error in LVBD state call -- multiple changes in a state")
raise LexerError(
"\nError in LVBD state call -- multiple changes in state "
+ str(ii)
)
ofile.write(statestring + '"\n')
# offset += n_lvbd_X_2 # this is fine for voltages after DIO
# use for DIO after voltages
Expand Down
Loading