Skip to content

Commit

Permalink
Fixed APS2Pattner update waveforms and wrote unit test that only test…
Browse files Browse the repository at this point in the history
…s that nothing breaks
  • Loading branch information
grahamrow committed May 12, 2020
1 parent bb3ea07 commit 944a4cb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
9 changes: 2 additions & 7 deletions QGL/drivers/APS2Pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,7 @@ def update_wf_library(filename, pulses, offsets):
"""
assert USE_PHASE_OFFSET_INSTRUCTION == False
#load the waveform file
with open(fileName, 'wb') as FID:
with open(filename, 'rb+') as FID:

# Find the necessary offsets into the file
target_hw = FID.read(4).decode('utf-8')
Expand All @@ -1298,7 +1298,7 @@ def update_wf_library(filename, pulses, offsets):
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, 1) # Skip over the data block, starting from current position
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

Expand All @@ -1319,11 +1319,6 @@ def update_wf_library(filename, pulses, offsets):
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())

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)


def tdm_instructions(seqs):
Expand Down
16 changes: 16 additions & 0 deletions tests/test_Sequences.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np
import unittest, time, os, random, sys
import tempfile
import pickle

from QGL import *
from QGL import GSTTools
Expand Down Expand Up @@ -504,6 +505,21 @@ def test_mux_CR(self):
filenames = compile_to_hardware(seqs, 'CNOT_CR_mux/CNOT_CR_mux')
self.compare_sequences('CNOT_CR_mux')

def test_update_in_place(self):
self.set_awg_dir('RabiAmpInPlace')
APS2Pattern.SAVE_WF_OFFSETS = True
# RabiAmp(self.q1, np.linspace(0, 5e-6, 11))
Ramsey(self.q1, np.linspace(0, 5e-6, 11))
# RabiWidth(self.q1, np.linspace(0, 5e-6, 11))
print(self.awg_dir)
with open(os.path.join(self.awg_dir, "Ramsey", "Ramsey-APS2.offsets"), "rb") as FID:
offsets = pickle.load(FID)
print(offsets)
pulses = {'MEAS': MEAS(self.q1, frequency=20e6)}
APS2Pattern.update_wf_library(os.path.join(self.awg_dir, "Ramsey", "Ramsey-APS2.aps2"), pulses, offsets)

APS2Pattern.SAVE_WF_OFFSETS = False


class TestAPS1(unittest.TestCase, AWGTestHelper, TestSequences):
def setUp(self):
Expand Down

0 comments on commit 944a4cb

Please sign in to comment.