Skip to content

Commit

Permalink
Merge 82f3eab into 5e63bbc
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewware committed May 19, 2020
2 parents 5e63bbc + 82f3eab commit 3ca33a6
Show file tree
Hide file tree
Showing 3 changed files with 30,834 additions and 12 deletions.
46 changes: 34 additions & 12 deletions QGL/drivers/APS2Pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ def write_sequence_file(awgData, fileName):
#store offsets and wavefor lib length
#time ampltidue entries are clamped to ADDRESS_UNIT
wf_length = ADDRESS_UNIT if entry.isTimeAmp else entry.length
offsets[entry.label] = ([_[sig] for _ in wfInfo[0][1]],
offsets[str(entry)+"_"+hex(hash(entry))] = ([_[sig] for _ in wfInfo[0][1]],
wf_length)
wf_sigs.discard(sig)

Expand Down Expand Up @@ -1277,12 +1277,31 @@ def start_new_seq():

def update_wf_library(filename, pulses, offsets):
"""
Update a H5 waveform library in place give an iterable of (pulseName, pulse)
Update an aps2 waveform library in place give an iterable of (pulseName, pulse)
tuples and offsets into the waveform library.
"""
assert USE_PHASE_OFFSET_INSTRUCTION == False
#load the h5 file
with h5py.File(filename) as FID:
#load the waveform file
with open(filename, 'rb+') as FID:

# Find the necessary offsets into the file
target_hw = FID.read(4).decode('utf-8')
if target_hw != "APS2":
raise Exception("Cannot update non-APS2 waveform library.")

file_version = struct.unpack('<f', FID.read(4))[0]
min_fw = struct.unpack('<f', FID.read(4))[0]
num_chans = struct.unpack('<H', FID.read(2))[0]
inst_len = struct.unpack('<Q', FID.read(8))[0]

FID.seek(8*inst_len, 1) # Skip over the instructions, starting from current position
wf_len_chan1 = struct.unpack('<Q', FID.read(8))[0]
chan1_start = FID.tell() # Save beginning of chan1 data block

FID.seek(2*wf_len_chan1, 1) # Skip over the data block, starting from current position
wf_len_chan2 = struct.unpack('<Q', FID.read(8))[0]
chan2_start = FID.tell() # Save beginning of chan1 data block

for label, pulse in pulses.items():
#create a new waveform
if pulse.isTimeAmp:
Expand All @@ -1295,11 +1314,11 @@ def update_wf_library(filename, pulses, offsets):
print("\t{} not found in offsets so skipping".format(pulse))
continue
for offset in offsets[label][0]:
print("\tUpdating {} at offset {}".format(pulse, offset))
FID['/chan_1/waveforms'][offset:offset + length] = np.int16(
MAX_WAVEFORM_VALUE * shape.real)
FID['/chan_2/waveforms'][offset:offset + length] = np.int16(
MAX_WAVEFORM_VALUE * shape.imag)
# print("\tUpdating {} at offset {}".format(pulse, offset))
FID.seek(chan1_start + 2*offset, 0) # Chan 1 block + 2 bytes per offset sample
FID.write(np.int16(MAX_WAVEFORM_VALUE * shape.real).tobytes())
FID.seek(chan2_start + 2*offset, 0) # Chan 1 block + 2 bytes per offset sample
FID.write(np.int16(MAX_WAVEFORM_VALUE * shape.imag).tobytes())


def tdm_instructions(seqs):
Expand Down Expand Up @@ -1562,7 +1581,9 @@ def __init__(self, instructions, waveforms):
self.height = 1200
self.instructions = instructions
self.waveforms = waveforms
print(self.waveforms)
for wf in self.waveforms:
print(wf, len(wf))
# print(self.waveforms)
self.initUI()
self.plotters = []

Expand Down Expand Up @@ -1606,8 +1627,9 @@ def scroll_to_goto_target(row=target_row, tab=self.tableWidget):
# Not a TA pair
btn = QPushButton(self.tableWidget)
btn.setText('WFM')
addr = int(fields[6].split("=")[1])
count = int(fields[5].split("=")[1])
addr = (int(fields[6].split("=")[1])+0)*4
print(fields[5])
count = (int(fields[5].split("=")[1])+1)*4
def open_plotter(addr=None, I=self.waveforms[0][addr:addr+count], Q=self.waveforms[1][addr:addr+count]):
w = MatplotlibWidget(I,Q)
self.plotters.append(w)
Expand Down

0 comments on commit 3ca33a6

Please sign in to comment.