Skip to content
Snippets Groups Projects
Commit ddb0655d authored by Stephan's avatar Stephan
Browse files

update

parent 1a1ca5e0
No related branches found
No related tags found
No related merge requests found
File added
File added
import numpy as np
import matplotlib.pyplot as plt
from segments import *
from keysight_fx import *
'''
ideas:
......@@ -17,24 +19,46 @@ class pulselib:
def __init__(self):
self.awg_channels = ['P1','P2','P3','P4','P5','B0','B1','B2','B3','B4','B5',]
self.awg_channels_to_physical_locations = ['here_dict']
self.awg_channels = ['P1','P2','P3','P4','P5','B0','B1','B2','B3','B4','B5','I_MW', 'Q_MW', 'M1', 'M2']
self.awg_channels_to_physical_locations = [{'B0',('AWG1', 1)},
{'P1',('AWG1', 2)},
{'B1',('AWG1', 3)},
{'P2',('AWG1', 4)},
{'B2',('AWG2', 1)},
{'P3',('AWG2', 2)},
{'B3',('AWG2', 3)},
{'P4',('AWG2', 4)},
{'B4',('AWG3', 1)},
{'P5',('AWG3', 2)},
{'B5',('AWG3', 3)},
{'B1',('AWG3', 4)},
{'I_MW',('AWG4', 1)},
{'Q_MW',('AWG4', 2)},
{'M1',('AWG4', 3)},
{'M2',('AWG4', 4)}]
self.awg_channels_kind = []
# Not implemented
self.awg_markers =['mkr1', 'mkr2', 'mkr3' ]
self.awg_markers_to_location = []
self.delays = []
self.convertion_matrix= []
self.segments_bin = segment_bin(self.awg_channels)
self.devices = []
self.sequencer = sequencer(self.awg_channels, self.awg_markers)
# awg1 = keysight_awg.SD_AWG('awg1', chassis = 0, slot= 2, channels = 4, triggers= 8)
# awg2 = keysight_awg.SD_AWG('awg2', chassis = 0, slot= 3, channels = 4, triggers= 8)
# awg3 = keysight_awg.SD_AWG('awg3', chassis = 0, slot= 4, channels = 4, triggers= 8)
# awg4 = keysight_awg.SD_AWG('awg4', chassis = 0, slot= 5, channels = 4, triggers= 8)
# Keysight properties.
self.backend = 'keysight'
self.frequency = 1e9
self.max_mem = 2e9
self.mem_used = 0
self.in_mem = []
self.awg = keysight_awg(self.segments_bin, self.awg_channels_to_physical_locations)
# self.awg.add_awg('AWG1',awg1)
# self.awg.add_awg('AWG2',awg1)
# self.awg.add_awg('AWG3',awg1)
# self.awg.add_awg('AWG4',awg1)
self.sequencer = sequencer(self.awg, self.segments_bin)
def add_awgs(self, awg):
for i in awg:
......@@ -51,7 +75,7 @@ class pulselib:
def start_sequence(self, name):
self.sequencer.start_sequence(name)
def show_sequences(self):
self.segments_bin.print_segments_info()
......@@ -61,119 +85,6 @@ class pulselib:
def play():
return
class segment_container():
'''
Class containing all the single segments for for a series of channels.
This is a organisational class.
'''
def __init__(self, name, channels):
self.channels = channels
self.name = name
for i in self.channels:
setattr(self, i, segment_single())
def reset_time(self):
maxtime = 0
for i in self.channels:
k = getattr(self, i)
t = k.get_total_time()
if t > maxtime:
maxtime = t
for i in self.channels:
getattr(self, i).starttime = maxtime
class segment_single():
def __init__(self):
self.type = 'default'
self.to_swing = False
self.starttime = 0
self.my_pulse_data = np.zeros([1,2])
self.last = None
self.IQ_data = [] #todo later.
def add_pulse(self,array):
'''
format ::
[[t0, Amp0],[t1, Amp1]]
'''
arr = np.asarray(array)
arr[:,0] = arr[:,0] + self.starttime
self.my_pulse_data = np.append(self.my_pulse_data,arr, axis=0)
def add_block(self,start,stop, amplitude):
amp_0 = self.my_pulse_data[-1,1]
print(amp_0)
pulse = [ [start, amp_0], [start,amplitude], [stop, amplitude], [stop, amp_0]]
self.add_pulse(pulse)
def wait(self, wait):
amp_0 = self.my_pulse_data[-1,1]
t0 = self.my_pulse_data[-1,0]
pulse = [wait+t0, amp_0]
def repeat(self, number):
return
def add_np(self,start, array):
return
def add_IQ_pair():
return
def add():
return
def get_total_time(self):
return self.my_pulse_data[-1,0]
def get_sequence(self, voltage_range = None, off_set = None):
'''
Returns a numpy array that contains the points for each ns
'''
return None
def _generate_sequence(self):
# 1 make base sequence:
t_tot = self.my_pulse_data[-1,0]
times = np.linspace(0, int(t_tot-1), int(t_tot))
my_sequence = np.empty([int(t_tot)])
for i in range(0,len(self.my_pulse_data)-1):
my_loc = np.where(times < self.my_pulse_data[i+1,0])[0]
my_loc = np.where(times[my_loc] >= self.my_pulse_data[i,0])[0]
if my_loc.size==0:
continue;
end_voltage = self.my_pulse_data[i,1] + (self.my_pulse_data[i+1,1] - self.my_pulse_data[i,1])*(times[my_loc[-1]] - self.my_pulse_data[i,0])/(self.my_pulse_data[i+1,0]- self.my_pulse_data[i,0]);
start_stop_values = np.linspace(self.my_pulse_data[i,1],end_voltage,my_loc.size);
my_sequence[my_loc] = start_stop_values;
return times, my_sequence
def plot_sequence(self):
x,y = self._generate_sequence()
plt.plot(x,y)
plt.show()
class marker_single():
def __init__(self):
self.type = 'default'
self.swing = False
self.latest_time = 0
self.my_pulse_data = np.zeros([1,2])
def add(self, start, stop):
self.my_pulse_data = np,append(self.my_pulse_data, [[start,0],[start,1],[stop,1],[stop,0]])
class segment_bin():
def __init__(self, channels):
......@@ -183,16 +94,16 @@ class segment_bin():
return
def new(self,name):
if self.exists(name):
raise ValueError("sement with the name : % \n alreadt exists"%name)
self.segment.append(segment_container(name,self.channels))
return self.get_segment(name)
if self.exists(name):
raise ValueError("sement with the name : % \n alreadt exists"%name)
self.segment.append(segment_container(name,self.channels))
return self.get_segment(name)
def get_segment(self, name):
for i in self.segment:
if i.name == name:
return i
raise ValueError("segment not found :(")
for i in self.segment:
if i.name == name:
return i
raise ValueError("segment not found :(")
def print_segments_info(self):
mystring = "Sequences\n"
......@@ -206,48 +117,26 @@ class segment_bin():
return True
return False
def upload(self, name):
time = self.get_max_time(name)
upload_data = np.array[len(channels), time]
for i in range(len(channels)):
upload_data[i] = self.segment.
def get_time_segment(self, name):
return self.get_segment(name).total_time
class sequencer():
def __init__(self, channels, markers, segment_bin):
self.channels = channels
self.markers = markers
def __init__(self, awg_system, segment_bin):
self.awg = awg_system
self.segment_bin = segment_bin
self.sequences = dict()
def add_sequence(self, name, sequence):
self.sequences['name'] = sequence
self.sequences[name] = sequence
def start_sequence(self, name):
# Ask segmentbin to check if elements are present, if not -- upload
self.segment_bin.upload()
# Upload the relevant segments.
class keysight_awg():
def __init__(awg_object):
self.awg = awg_object
self.usable_mem = 1e9
self.current_waveform_number = 0
def upload_waveform(self, wfv):
if self.usable_mem - len(wfv) < 0:
raise Exception("AWG Full :(. Clear all the ram... Note that this error should normally be prevented automatically.")
# wfv.astype(np.int16)
def clear_mem(self):
return
def check_mem_availability(self, num_pt):
return True
self.awg.upload(self.sequences[name])
self.awg.start(self.sequences[name])
p = pulselib()
seg = p.mk_segment('INIT')
seg = p.mk_segment('INIT')
seg2 = p.mk_segment('Manip')
seg3 = p.mk_segment('Readout')
......
import numpy as np
import datetime
class keysight_awg():
def __init__(self, segment_bin, channel_locations):
self.awg = dict()
self.awg_memory = dict()
self.current_waveform_number = 0
self.channel_locations = channel_locations
self.segmentdata = dict()
self.segdata_awg_mem = dict()
self.segment_bin = segment_bin
self.maxmem = 1e9
def upload(self, sequence_data):
# step 1 prepare for upload, check how much memory is needed. (and is available)
mem_needed = 0
for i in sequence_data:
segment_name = i[0]
if segment_name in self.segmentdata:
if self.segment_bin.get_segment(segment_name).latest_mod > self.segmentdata(segment_name):
continue
else:
mem_needed += self.segment_bin.get_segment(segment_name).total_time
# If memory full, clear
if mem_needed > allocatable_mem:
self.clear_mem()
# step 2 upload
for i in sequence_data:
segment_name = i[0]
if segment_name not in self.segmentdata:
if self.segment_bin.get_segment(segment_name).latest_mod <= self.segmentdata(segment_name):
segmend_data, channels = segment_bin.get_pulse(segment_name)
# This is the location to do post processing?
def start(self, sequence_data):
return
# mem_needed
# for i in
# Ask segmentbin to check if elements are present, if not -- upload
# self.segment_bin.upload('INIT')
# Upload the relevant segments.
# if self.usable_mem - len(wfv) < 0:
# raise Exception("AWG Full :(. Clear all the ram... Note that this error should normally be prevented automatically.")
# wfv.astype(np.int16)
return
def check_mem_availability(self, num_pt):
return True
def add_awg(self, name, awg):
self.awg[name] = awg, self.maxmem
self.awg_memory[name] =self.maxmem
self.segdata_awg_mem[name] = dict()
@property
def allocatable_mem(self):
alloc = self.maxmem
for i in awg_memory:
if alloc > i:
allow = i
def clear_mem(self):
'''
Clears ram of all the AWG's
'''
self.segmentdata = dict()
for i in self.awg():
i.flush_waveform()
for i in self.awg_memory:
i = self.maxmem
\ No newline at end of file
......@@ -15,7 +15,7 @@ awg1.set_channel_amplitude(1,1)
# set_channel_offset
awg1.set_channel_wave_shape(4,1)
# load_waveform
# awg1.load_waveform
# load_waveform_int16
# reload_waveform_int16
......
import numpy as np
import datetime
import matplotlib.pyplot as plt
class segment_container():
'''
Class containing all the single segments for for a series of channels.
This is a organisational class.
'''
def __init__(self, name, channels):
self.channels = channels
self.name = name
for i in self.channels:
setattr(self, i, segment_single())
def reset_time(self):
maxtime = 0
for i in self.channels:
k = getattr(self, i)
t = k.get_total_time()
if t > maxtime:
maxtime = t
for i in self.channels:
getattr(self, i).starttime = maxtime
@property
def total_time(self):
time_segment = 0
for i in self.channels:
if time_segment <= getattr(self, i).total_time:
time_segment = getattr(self, i).total_time
return time_segment
def last_edited(f):
def wrapper(*args):
args[0].last_edit = datetime.datetime.now()
return f(*args)
return wrapper
class segment_single():
def __init__(self):
self.type = 'default'
self.to_swing = False
self.starttime = 0
self.last_edit = datetime.datetime.now()
self.my_pulse_data = np.zeros([1,2])
self.last = None
self.IQ_data = [] #todo later.
@last_edited
def add_pulse(self,array):
'''
format ::
[[t0, Amp0],[t1, Amp1]]
'''
arr = np.asarray(array)
arr[:,0] = arr[:,0] + self.starttime
self.my_pulse_data = np.append(self.my_pulse_data,arr, axis=0)
@last_edited
def add_block(self,start,stop, amplitude):
amp_0 = self.my_pulse_data[-1,1]
pulse = [ [start, amp_0], [start,amplitude], [stop, amplitude], [stop, amp_0]]
self.add_pulse(pulse)
@last_edited
def wait(self, wait):
amp_0 = self.my_pulse_data[-1,1]
t0 = self.my_pulse_data[-1,0]
pulse = [wait+t0, amp_0]
def repeat(self, number):
return
def add_np(self,start, array):
return
def add_IQ_pair():
return
def add():
return
@property
def total_time(self,):
return self.my_pulse_data[-1,0]
def get_total_time(self):
return self.my_pulse_data[-1,0]
def get_sequence(self, voltage_range = None, off_set = None):
'''
Returns a numpy array that contains the points for each ns
'''
return None
def _generate_sequence(self):
# 1 make base sequence:
t_tot = self.total_time
times = np.linspace(0, int(t_tot-1), int(t_tot))
my_sequence = np.empty([int(t_tot)])
for i in range(0,len(self.my_pulse_data)-1):
my_loc = np.where(times < self.my_pulse_data[i+1,0])[0]
my_loc = np.where(times[my_loc] >= self.my_pulse_data[i,0])[0]
if my_loc.size==0:
continue;
end_voltage = self.my_pulse_data[i,1] + (self.my_pulse_data[i+1,1] - self.my_pulse_data[i,1])*(times[my_loc[-1]] - self.my_pulse_data[i,0])/(self.my_pulse_data[i+1,0]- self.my_pulse_data[i,0]);
start_stop_values = np.linspace(self.my_pulse_data[i,1],end_voltage,my_loc.size);
my_sequence[my_loc] = start_stop_values;
return times, my_sequence
def plot_sequence(self):
x,y = self._generate_sequence()
plt.plot(x,y)
plt.show()
class marker_single():
def __init__(self):
self.type = 'default'
self.swing = False
self.latest_time = 0
self.my_pulse_data = np.zeros([1,2])
def add(self, start, stop):
self.my_pulse_data = np,append(self.my_pulse_data, [[start,0],[start,1],[stop,1],[stop,0]])
These are the initial thoughs for a general pulse lirary that should be maily used for keysight systems.
Note that the intend is to support also other systems
Library functions needed
-> general object: conatains AWG info
-> channels
-> makers
-> segment object
-> add function
-> add time based relative based
-> sequence object
-> option for virtual AWG
-
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment