Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ranzani committed Dec 5, 2024
1 parent ebc66af commit 621fcc2
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 13 deletions.
6 changes: 3 additions & 3 deletions QGL/drivers/APSPattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ def write_sequence_file(awgData, fileName, miniLLRepeat=1):
os.remove(fileName)

with open(fileName, 'wb') as FID:
channelDataFor = np.array([0,0,0,0], dtype=np.bool)
channelDataFor = np.array([0,0,0,0], dtype=bool)
if LLs12:
channelDataFor[0:2] = True
if LLs34:
Expand All @@ -722,7 +722,7 @@ def write_sequence_file(awgData, fileName, miniLLRepeat=1):
FID.write(b'APS1') # target hardware
FID.write(np.float32(2.2).tobytes()) # Version
FID.write(channelDataFor.tobytes()) # channelDataFor
FID.write(np.array(miniLLRepeat-1, dtype=np.bool).tobytes()) # MiniLLRepeat
FID.write(np.array(miniLLRepeat-1, dtype=bool).tobytes()) # MiniLLRepeat

#Create the waveform vectors
wfInfo = []
Expand Down Expand Up @@ -771,7 +771,7 @@ def read_sequence_file(fileName):
with open(fileName, 'rb') as FID:
target_hw = FID.read(4).decode('utf-8')
file_version = struct.unpack('<f', FID.read(4))[0]
channelDataFor = np.frombuffer(FID.read(4), dtype=np.bool)
channelDataFor = np.frombuffer(FID.read(4), dtype=bool)
miniLLRepeat = struct.unpack('?', FID.read(1))[0]

# channels = [chanStrs2[i] for i in range(4) if channelDataFor[i]]
Expand Down
10 changes: 6 additions & 4 deletions tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ def setup_test_lib():
m2 = Measurement(label='M-q2', control_chan=q2, channel_db=cl.channelDatabase)
m3 = Measurement(label='M-q3', control_chan=q3, channel_db=cl.channelDatabase)
m4 = Measurement(label='M-q4', control_chan=q4, channel_db=cl.channelDatabase)


cl.update_channelDict()

ChannelLibraries.channelLib.channelDict = {
'q1': q1,
'q2': q2,
'q3': q3,
'q4': q4,
'q1q2': Edge(label='q1q2', source=q1, target=q2, channel_db=cl.channelDatabase),
'q2q3': Edge(label='q2q3', source=q2, target=q3, channel_db=cl.channelDatabase),
'q3q4': Edge(label='q3q4', source=q3, target=q4, channel_db=cl.channelDatabase)
'q1->q2': Edge(label='q1->q2', source=q1, target=q2, channel_db=cl.channelDatabase),
'q2->q3': Edge(label='q2->q3', source=q2, target=q3, channel_db=cl.channelDatabase),
'q3->q4': Edge(label='q3->q4', source=q3, target=q4, channel_db=cl.channelDatabase)
}
cl.update_channelDict()
6 changes: 5 additions & 1 deletion tests/test_Compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,22 @@ def setUp(self):
self.q2 = Qubit(label='q2', gate_chan=self.q2gate, channel_db=self.cl.channelDatabase)
self.q2.phys_chan = self.q2phys
self.q2.pulse_params['length'] = 30e-9
self.cl.update_channelDict()

self.trigger = Channels.LogicalMarkerChannel(label='trigger', channel_db=self.cl.channelDatabase)
self.measq1 = Channels.Measurement(label='M-q1', meas_type='autodyne', channel_db=self.cl.channelDatabase)
self.measq1.trig_chan = self.trigger
self.measq2 = Channels.Measurement(label='M-q2', meas_type='autodyne', channel_db=self.cl.channelDatabase)
self.measq2.trig_chan = self.trigger

self.q1.measure_chan = self.measq1
self.q2.measure_chan = self.measq2
self.cl.update_channelDict()


def test_add_digitizer_trigger(self):
q1 = self.q1
seq = [X90(q1), MEAS(q1), Y(q1), MEAS(q1)]

PatternUtils.add_digitizer_trigger([seq])
assert (self.trigger in seq[1].pulses.keys())
assert (self.trigger in seq[3].pulses.keys())
Expand Down
5 changes: 5 additions & 0 deletions tests/test_Pulse_Types.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ def setUp(self):
self.q3 = QubitFactory('q3')
self.q4 = QubitFactory('q4')

ChannelLibraries.channelLib.new_edge(self.q1,self.q2)
ChannelLibraries.channelLib.new_edge(self.q3,self.q4)

self.q1q2 = EdgeFactory(self.q1,self.q2)
self.q3q4 = EdgeFactory(self.q3,self.q4)
# This appears to run successfully with the skip commented out;
# TJR, 07 Nov 2018
#@unittest.skip("Type promition for CNOT(q1, q2) * X(q3) gives PulseBlock not CompoundGate. Looking into this issue.")
Expand Down
8 changes: 8 additions & 0 deletions tests/test_Scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ def setUp(self):
self.q3 = QubitFactory('q3')
self.q4 = QubitFactory('q4')

ChannelLibraries.channelLib.new_edge(self.q1,self.q2)
ChannelLibraries.channelLib.new_edge(self.q2,self.q3)
ChannelLibraries.channelLib.new_edge(self.q3,self.q4)

self.q1q2 = EdgeFactory(self.q1,self.q2)
self.q1q2 = EdgeFactory(self.q2,self.q3)
self.q3q4 = EdgeFactory(self.q3,self.q4)

def test_1q_ops(self):
q1, q2, q3 = self.q1, self.q2, self.q3

Expand Down
1 change: 1 addition & 0 deletions tests/test_Sequences.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ def compare_file_data(self, testFile, truthFile):
'''
awgData = self.read_function(testFile)
truthData = self.read_function(truthFile)
#truthData = self.read_function(testFile)

awgDataLen = len(awgData)
truthDataLen = len(truthData)
Expand Down
8 changes: 3 additions & 5 deletions utils/convert_h5_to_aps.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os.path

def write_to_aps1(fileName, data):
channelDataFor = np.array([i in data['channelDataFor'] for i in range(1,5)], dtype=np.bool)
channelDataFor = np.array([i in data['channelDataFor'] for i in range(1,5)], dtype=bool)
try:
with open(fileName, 'wb') as FID:
FID.write(b'APS1') # target hardware
Expand All @@ -23,7 +23,7 @@ def write_to_aps1(fileName, data):
FID.write(np.uint64(data['channels'][name]['linkListDataLength']).tobytes()) # numEntries
for key, dataVec in data['channels'][name]['linkListData'].items():
FID.write(key.ljust(32,"#").encode("utf-8")) # Key 32 byte utf-8
FID.write(dataVec.tobytes())
FID.write(dataVec.tobytes())
except:
print(f"Warning: could not write aps1 file {fileName}")

Expand All @@ -34,7 +34,7 @@ def write_to_aps2(fileName, data):
wfInfo[1] = data['chan2']

with open(fileName, 'wb') as FID:
FID.write(b'APS2') # target
FID.write(b'APS2') # target
FID.write(np.float32(data['file_version']).tobytes()) # Version
FID.write(np.float32(data['fw_version']).tobytes()) # minimum firmware version
FID.write(np.uint16(2).tobytes()) # number of channels
Expand Down Expand Up @@ -102,5 +102,3 @@ def read_aps1_from_h5(fileName):
if inst == "APS1":
data = read_aps1_from_h5(basename+'.h5')
write_to_aps1(basename+".aps1", data)


0 comments on commit 621fcc2

Please sign in to comment.