Skip to content
Snippets Groups Projects
Commit 0a821ab1 authored by Stephan Philips's avatar Stephan Philips
Browse files

update

parent 267fe43e
No related branches found
No related tags found
No related merge requests found
Showing
with 168 additions and 76 deletions
File added
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -41,9 +41,16 @@ class pulse_data():
total_time = self.my_pulse_data[-1,0]
return total_time
def reset_time(self,):
self.start_time = self.total_time
def reset_time(self, time = None):
if time is not None:
if self.start_time + time <= self.total_time:
pass
else:
pulse = np.asarray([[0, 0],[self.start_time + time, 0]])
self.add_pulse_data(pulse)
self.start_time = self.total_time
def get_vmax(self,sample_rate = 1e9):
'''
calculate the maximum voltage in the current segment_single.
......@@ -347,8 +354,11 @@ class IQ_data():
return total_time
def reset_time(self,):
self.start_time = self.total_time
def reset_time(self, time = None):
if time is not None:
self.start_time = None
else:
self.start_time = self.total_time
def __copy__(self,):
my_copy = IQ_data(self.LO)
......
from pulse_lib.segments.looping import linspace
from pulse_lib.segments.looping import loop_obj
from pulse_lib.segments.data_classes import data_container
import numpy as np
import copy
......@@ -150,29 +150,32 @@ def loop_controller(func):
loop_info_kwargs = []
for i in range(1,len(args)):
if type(args[i]) == linspace :
if isinstance(args[i], loop_obj):
info = {
'nth_arg': i,
'name': args[i].name,
'name': args[i].names,
'shape' : args[i].shape,
'len': len(args[i]),
'axis': args[i].axis,
'data' : args[i].data}
loop_info_args.append(info)
for key in kwargs.keys():
if type(kwargs[key]) == linspace :
if isinstance(kwargs[key], loop_obj):
info = {
'nth_arg': key,
'name': kwargs[key].name,
'name': kwargs[key].names,
'shape' : args[i].shape,
'len': len(kwargs[key]),
'axis': kwargs[key].axis,
'data' : kwargs[key].data}
loop_info_kwargs.append(info)
for lp in loop_info_args:
new_dim = get_new_dim_loop(obj.data.shape, lp)
obj.data = update_dimension(obj.data, new_dim)
for i in range(len(lp['axis'])-1,-1,-1):
new_dim, axis = get_new_dim_loop(obj.data.shape, lp['axis'][i], lp['shape'][i])
lp['axis'][i] = axis
obj.data = update_dimension(obj.data, new_dim)
for lp in loop_info_kwargs:
new_dim = get_new_dim_loop(obj.data.shape, lp)
......@@ -208,10 +211,10 @@ def loop_over_data(func, data, args, args_info, kwargs, kwargs_info):
for i in range(shape[0]):
for arg in args_info:
if arg['axis'] == n_dim-1:
if n_dim-1 in arg['axis']:
args_cpy[arg['nth_arg']] = args[arg['nth_arg']].data[i]
for kwarg in kwargs_info:
if arg['axis'] == n_dim-1:
if n_dim-1 in kwarg['axis']:
kwargs_cpy[kwargs_info['nth_arg']] = kwargs[kwargs_info['nth_arg']].data[i]
if n_dim == 1:
......@@ -222,42 +225,45 @@ def loop_over_data(func, data, args, args_info, kwargs, kwargs_info):
# clean up args, kwards
loop_over_data(func, data[i], args_cpy, args_info, kwargs_cpy, kwargs_info)
def get_new_dim_loop(current_dim, loop_spec):
def get_new_dim_loop(current_dim, axis, shape):
'''
function to get new dimensions from a loop spec.
Args:
current_dim [tuple/array] : current dimensions of the data object
loop_spec [dict] : format of the loop
current_dim [tuple/array] : current dimensions of the data object.
axis [int] : on which axis to put the new loop dimension.
len [int] : the number of elements that a are along that loop axis.
Returns:
new_dim [array] : new dimensions of the data obeject when one would include the loop spec
axis [int] : axis on which a loop variable was put (if free assign option was used (axis of -1))
'''
current_dim = list(current_dim)
new_dim = []
if loop_spec["axis"] == -1:
new_dim = [loop_spec["len"]] + current_dim
if axis == -1:
new_dim = [shape] + current_dim
# assign new axis.
loop_spec["axis"] = len(new_dim) - 1
axis = len(new_dim) - 1
else:
if loop_spec["axis"] >= len(current_dim):
new_dim = [1]*(loop_spec["axis"]+1)
if axis >= len(current_dim):
new_dim = [1]*(axis+1)
for i in range(len(current_dim)):
new_dim[loop_spec["axis"]-len(current_dim)+1 + i] = current_dim[i]
new_dim[0] = loop_spec["len"]
new_dim[axis-len(current_dim)+1 + i] = current_dim[i]
new_dim[0] = shape
else:
if current_dim[-1-loop_spec["axis"]] == loop_spec["len"]:
if current_dim[-1-axis] == shape:
new_dim = current_dim
elif current_dim[-1-loop_spec["axis"]] == 1:
elif current_dim[-1-axis] == 1:
new_dim = current_dim
new_dim[-1-loop_spec["axis"]] = loop_spec['len']
new_dim[-1-axis] = shape
else:
raise ValueError("Dimensions on loop axis {} not compatible with previous loops\n\
(current dimensions is {}, wanted is {}).\n\
Please change loop axis or update the length.".format(loop_spec["axis"],
current_dim[loop_spec["axis"]], loop_spec["len"]))
Please change loop axis or update the length.".format(axis,
current_dim[axis], shape))
return new_dim
return new_dim, axis
def update_labels(data_object, loop_spec):
pass
......
import numpy as np
class linspace():
class loop_obj():
"""objecet that initializes some standard fields that need to be there in a loop object"""
def __init__(self):
# little inspiration from qcodes parameter ...
self.names = list()
self.units = list()
self.axis = list()
self.dtype = None
def add_data(self, data, axis = None, names = None, units = None):
self.data = data
self.dtype = data.dtype
if axis is None:
self.axis = [-1]*len(data)
else:
if len(axis) != len(data.shape):
raise ValueError("Provided incorrect dimensions for the axis.")
self.axis = axis
if names is None:
self.names = ["undefined"]*len(data)
else:
if len(names) != len(data.shape):
raise ValueError("Provided incorrect dimensions for the axis.")
self.names = names
if units is None:
self.units = ["a.u"]*len(data)
else:
if len(units) != len(data.shape):
raise ValueError("Provided incorrect dimensions for the axis.")
self.units = units
def __len__(self):
return len(self.data)
@property
def shape(self):
return self.data.shape
def __getitem__(self, key):
if len(self.axis) == 1:
return self.data[key]
else:
partial = loop_obj()
partial.names =self.names[1:]
partial.units = self.units[1:]
partial.axis = self.axis[1:]
partial.dtype = self.dtype
partial.data = self.data[key]
return partial
class linspace(loop_obj):
"""docstring for linspace"""
def __init__(self, start, stop, n_steps = 50, name = "undefined", unit = 'a.u.', axis = -1):
super().__init__()
self.data = np.linspace(start, stop, n_steps)
self.name = name
self.unit = unit
self.axis = axis
def __len__(self):
return len(self.data)
self.names = [name]
self.units = [unit]
self.axis = [axis]
import pulse_lib.segments.segments_base as seg_base
import pulse_lib.segments.segments_IQ as seg_IQ
import pulse_lib.segments.looping as lp
from pulse_lib.segments.data_handling_functions import find_common_dimension, update_dimension
import numpy as np
......@@ -121,7 +123,17 @@ class segment_container():
-> totaltime will be 140 ns,
when you now as a new pulse (e.g. at time 0, it will actually occur at 140 ns in both blocks)
'''
raise NotImplemented
times = self.total_time
loop_obj = lp.loop_obj()
loop_obj.add_data(times, list(range(len(times.shape)-1, -1,-1)))
for i in self.channels:
segment = getattr(self, i)
segment.reset_time(loop_obj)
def get_waveform(self, channel, Vpp_data, sequence_time, pre_delay=0, post_delay = 0, return_type = np.double):
'''
......@@ -160,19 +172,23 @@ class segment_container():
def clear_chache(self):
raise NotImplemented
@property
def shape(self):
'''
get combined shape of all the waveforms
'''
my_shape = (1,)
for i in self.channels:
dim = getattr(self, i).data.shape
my_shape = find_common_dimension(my_shape, dim)
return my_shape
def __extend_dim_all_waveforms(self):
"""
function to make sure that all the waveforms have the same dimentionality.
Note that the mode here is copy and not referencing.
"""
# find global dimension
my_dimension = (1,)
for i in self.channels:
dim = getattr(self, i).data.shape
my_dimension = find_common_dimension(my_dimension, dim)
# now update the size
for i in self.channels:
getattr(self, i).data = update_dimension(getattr(self, i).data, my_dimension)
getattr(self, i).data = update_dimension(getattr(self, i).data, self.shape)
......@@ -64,10 +64,16 @@ class segment_single():
'''
virtual_IQ_segment = {'name': channel_name, 'segment': pointer_to_channel, 'I/Q': I_or_Q_part}
self.IQ_ref_channels.append(virtual_IQ_segment)
@last_edited
@loop_controller
def reset_time(self):
self.data_tmp.reset_time()
def reset_time(self, time=None):
'''
resets the time back to zero after a certain point
Args:
time (double) : (optional), after time to reset back to 0. Note that this is absolute time and not rescaled time.
'''
self.data_tmp.reset_time(time)
@last_edited
@loop_controller
......@@ -119,22 +125,6 @@ class segment_single():
self.data_tmp.add_pulse_data(pulse)
@last_edited
@loop_controller
def wait_until(self, time):
'''
makes a wait for the waveform until a certain point in time.
Args:
time (double) : time in ns that there must be a point inside the waveform
'''
if self.data_tmp.start_time + time <= self.data_tmp.total_time:
pass
else:
pulse = np.asarray([[0, 0],[self.data_tmp.start_time + time, 0]])
self.data_tmp.add_pulse_data(pulse)
@last_edited
@loop_controller
def add_sin(self, start, stop, amp, freq, phase_offset=0):
......@@ -294,8 +284,8 @@ class segment_single():
A numpy array that contains the points for each ns
points is the expected lenght.
'''
t, wvf = self._generate_segment(index, pre_delay, post_delay, sample_rate)
return t, wvf
wvf = self._generate_segment(index, pre_delay, post_delay, sample_rate)
return wvf
def v_max(self, index, sample_rate = 1e9):
index = np.ravel_multi_index(tuple(index), self.pulse_data_all.shape)
......
......@@ -48,29 +48,42 @@ seg = p.mk_segment('INIT')
# B0 is the barrier 0 channel
# adds a linear ramp from 10 to 20 ns with amplitude of 5 to 10.
seg.B0.add_pulse([[10.,0.],[10.,5.],[20.,10.],[20.,0.]])
# seg.B0.add_pulse([[10.,0.],[10.,5.],[20.,10.],[20.,0.]])
# add a block pulse of 2V from 40 to 70 ns, to whaterver waveform is already there
seg.B0.add_block(40,70,2)
seg.B0.add_block(0,1000,2)
import pulse_lib.segments.looping as lp
times = lp.linspace(5,20e3, 20, axis=0, name="time", unit="ns")
# just waits (e.g. you want to ake a segment 50 ns longer)
seg.B0.wait(20)
# test = lp.loop_obj()
# data = np.linspace(0,5,1000)
# data = np.resize(data, (10,100))
# test.data = data
# test.names = ["a","b"]
# test.units = ["a","b"]
# test.axis = [-1,-1]
# just waits (e.g. you want to ake a segment 50 ns longer)
# times = lp.linspace(50, 80)
seg.B0.wait(times)
# resets time back to zero in segment. Al the commannds we run before will be put at a negative time.
seg.B0.reset_time()
seg.reset_time()
# this pulse will be placed directly after the wait()
# seg.B0.add_pulse([[10.,0.],[10.,5.],[20.,10.],[20.,2.]])
seg.B0.add_block(40,70,2)
# seg.B0.add_block(0,1000,-2)
# seg.B0.wait(100)
print(seg.B0.data.shape)
print(seg.B0.total_time)
print(seg.B1.total_time)
# print(seg.B0.v_min([0]))
# print(seg.B0.v_max([0]))
# print(seg.B0.integrate([0]))
print(seg.B0._generate_segment([0], pre_delay = 10, post_delay = 10))
# print(seg.B1.data.shape)
# seg.B0.plot_segment( render_full=False)
# print(seg.total_time)
\ No newline at end of file
# print(seg.total_time)
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