-
Notifications
You must be signed in to change notification settings - Fork 2
Handle empty states #29
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -1062,6 +1064,8 @@ def plot(self, cycles=2, initialLevel=None): | |
| # Tracer()() | ||
| return | ||
|
|
||
| def state_empty(sstr): | ||
| return len(sstr.replace('"', '')) == 0 | ||
|
|
||
| def state(outfile=None): | ||
| """write states from the UniqueStateArr to the | ||
|
|
@@ -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"]: | ||
|
|
@@ -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"]: | ||
|
|
@@ -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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these look like many functions almost identical can we refactor?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
@@ -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') | ||
|
|
@@ -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 | ||
|
|
@@ -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"]: | ||
|
|
@@ -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 | ||
|
|
||
There was a problem hiding this comment.
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