From d7cfac8a04beb665e54e785a4cd9222d6b156919 Mon Sep 17 00:00:00 2001
From: Sander de Snoo <59472150+sldesnoo-Delft@users.noreply.github.com>
Date: Thu, 12 Oct 2023 11:37:59 +0200
Subject: [PATCH] Cleanup

---
 pulse_lib/base_pulse.py                       | 150 +++---------------
 pulse_lib/segments/data_classes/data_pulse.py | 100 ++++++------
 pulse_lib/segments/segment_container.py       |  39 +----
 3 files changed, 73 insertions(+), 216 deletions(-)

diff --git a/pulse_lib/base_pulse.py b/pulse_lib/base_pulse.py
index 0f2b2bff..eaef2adf 100644
--- a/pulse_lib/base_pulse.py
+++ b/pulse_lib/base_pulse.py
@@ -14,13 +14,15 @@ from pulse_lib.virtual_matrix.virtual_gate_matrices import VirtualGateMatrices
 
 logger = logging.getLogger(__name__)
 
+
 class pulselib:
     '''
     Global class that is an organisational element in making the pulses.
     The idea is that you first make individual segments,
     you can than later combine them into a sequence, this sequence will be uploaded
     '''
-    def __init__(self, backend = "Keysight"):
+
+    def __init__(self, backend="Keysight"):
         self.awg_devices = dict()
         self.digitizers = dict()
         self.awg_channels = dict()
@@ -117,14 +119,14 @@ class pulselib:
         '''
         define the channels and their location
         Args:
-            channel_name (str) : name of a given channel on the AWG. This would usually the name of the gate that it is connected to.
+            channel_name (str) : name of a given channel on the AWG.
             AWG_name (str) : name of the instrument (as given in add_awgs())
             channel_number (int) : channel number on the AWG
             amplitude (float): (maximum) amplitude in mV. Uses instrument default when not set.
 
         Notes:
-            For Keysight AWG the amplitude should only be set to enforce a maximum output level. The amplitude is applied
-            digitally and setting it does not improve resolution of noise level.
+            For Keysight AWG the amplitude should only be set to enforce a maximum output level.
+            The amplitude is applied digitally and setting it does not improve resolution of noise level.
             For Tektronix AWG the amplitude applies to the analogue output range.
             For Qblox setting the amplitude has no effect.
         '''
@@ -136,11 +138,12 @@ class pulselib:
         '''
         define the channels and their location
         Args:
-            marker_name (str) : name of a given channel on the AWG. This would usually the name of the gate that it is connected to.
+            marker_name (str) : name of a given channel on the AWG.
             AWG_name (str) : name of the instrument (as given in add_awgs())
             channel_number (int or Tuple(int, int)) : channel number on the AWG
             setup_ns (float): setup time for the device using the marker. marker raises `setup_ns` earlier.
-            hold_ns (float): hold time for the device using the marker to ensure proper output. marker falls `hold_ns` later.
+            hold_ns (float):
+                hold time for the device using the marker to ensure proper output. marker falls `hold_ns` later.
             amplitude (float): amplitude in mV (only applies when instrument allows control)
             invert (bool): invert the ouput, i.e. high voltage when marker not set and low when marker is active.
 
@@ -151,7 +154,6 @@ class pulselib:
         self.marker_channels[marker_name] = marker_channel(marker_name, AWG_name, channel_number,
                                                            setup_ns, hold_ns, amplitude, invert)
 
-
     def define_digitizer_channel(self, name, digitizer_name, channel_number, iq_out=False):
         ''' Defines a digitizer channel.
         Args:
@@ -197,8 +199,6 @@ class pulselib:
         '''
         self.digitizer_channels[channel_name].frequency = frequency
 
-    # Changed [v1.6.0] amplitude optional
-    # Changed [v1.6.0] trigger_offset_ns -> delay + startup_time_ns
     def set_digitizer_rf_source(self, channel_name, output,
                                 mode='pulsed',
                                 amplitude=0,
@@ -241,7 +241,7 @@ class pulselib:
             Qblox driver only supports module name with channel number(s).
         '''
         if trigger_offset_ns is not None:
-            print(f'Warning: trigger_offset_ns is deprecated. Use startup_time_ns and/or source_delay_ns')
+            print('Warning: trigger_offset_ns is deprecated. Use startup_time_ns and/or source_delay_ns')
             if startup_time_ns == 0:
                 startup_time_ns = trigger_offset_ns
         rf_source = resonator_rf_source(output=output, mode=mode,
@@ -281,10 +281,9 @@ class pulselib:
         else:
             raise ValueError(f"Channel delay error: Channel '{channel}' is not defined")
 
-
     def add_channel_compensation_limit(self, channel_name, limit):
         '''
-        add voltage limitations per channnel that can be used to make sure that the intregral of the total voltages is 0.
+        Sets voltage limits per channnel. They are used to make sure that the intregral of the total voltages is 0.
         Args:
             channel (str) : channel name as defined in self.define_channel().
             limit (tuple<float,float>) : lower/upper limit for DC compensation, e.g. (-100,500)
@@ -379,8 +378,7 @@ class pulselib:
 
     def define_qubit_channel(self, qubit_channel_name, IQ_channel_name,
                              resonance_frequency=None,
-                             correction_phase=0.0, correction_gain=(1.0,1.0),
-                             reference_frequency=None, # TODO: remove in next release.
+                             correction_phase=0.0, correction_gain=(1.0, 1.0)
                              ):
         """
         Creates a qubit channel on an IQ channel. A qubit channel keeps track of the
@@ -393,11 +391,6 @@ class pulselib:
             correction_phase (float) : phase in rad added to Q component of IQ channel
             correction_gain (float,float) : correction of I and Q amplitude
         """
-        if reference_frequency is not None:
-            print('WARNING: argument reference_frequency of define_qubit_channel() is deprecated')
-            if resonance_frequency is None:
-                resonance_frequency = reference_frequency
-
         iq_channel = self.IQ_channels[IQ_channel_name]
         qubit = QubitChannel(qubit_channel_name, resonance_frequency, iq_channel,
                              correction_phase, correction_gain)
@@ -417,7 +410,7 @@ class pulselib:
     def set_qubit_correction_gain(self, qubit_channel_name, correction_gain_I, correction_gain_Q):
         self.qubit_channels[qubit_channel_name].correction_gain = (correction_gain_I, correction_gain_Q)
 
-    def set_channel_attenuations(self, attenuation_dict:Dict[str, float]):
+    def set_channel_attenuations(self, attenuation_dict: Dict[str, float]):
         for channel, attenuation in attenuation_dict.items():
             if channel not in self.awg_channels:
                 logger.info(f'Channel {channel} defined in hardware, but not in pulselib; skipping channel')
@@ -467,6 +460,7 @@ class pulselib:
                                                self.awg_channels, self.marker_channels,
                                                self.digitizer_markers, self.qubit_channels,
                                                self.digitizer_channels, self.awg_sync)
+
     def _old_Tektronix5014_message(self):
         raise Exception('''
         Pulselib Tektronix driver has changed in pulselib version 1.3.6.
@@ -518,9 +512,6 @@ class pulselib:
         elif self._backend == "Qblox":
             self._create_QbloxPulsar_uploader()
 
-        elif self._backend in ["Demo", "None", None]:
-            logger.info('No backend defined')
-            TODO('define demo backend')
         else:
             raise Exception(f'Unknown backend: {self._backend}')
 
@@ -577,13 +568,13 @@ class pulselib:
         '''
         try:
             from core_tools.drivers.hardware.hardware import hardware as hw_cls
-        except:
+        except Exception:
             logger.warning('old version of core_tools detected ..')
 
         try:
             new_hardware_class = isinstance(hardware, hw_cls)
-        except:
-           new_hardware_class = False
+        except Exception:
+            new_hardware_class = False
 
         if new_hardware_class:
             for virtual_gate_set in hardware.virtual_gates:
@@ -625,108 +616,7 @@ class pulselib:
 
     def _check_uniqueness_of_channel_name(self, channel_name):
         if (channel_name in self.awg_channels
-            or channel_name in self.marker_channels
-            or channel_name in self.digitizer_channels
-            or channel_name in self.qubit_channels):
+                or channel_name in self.marker_channels
+                or channel_name in self.digitizer_channels
+                or channel_name in self.qubit_channels):
             raise ValueError(f"double declaration of the a channel/marker name ({channel_name}).")
-
-
-if __name__ == '__main__':
-    from pulse_lib.virtual_channel_constructors import IQ_channel_constructor
-    from pulse_lib.virtual_channel_constructors import virtual_gates_constructor
-
-    p = pulselib()
-
-
-    class AWG(object):
-        """docstring for AWG"""
-        def __init__(self, name):
-            self.name = name
-            self.chassis = 0
-            self.slot = 0
-            self.type = "DEMO"
-
-    AWG1 = AWG("AWG1")
-    AWG2 = AWG("AWG2")
-    AWG3 = AWG("AWG3")
-    AWG4 = AWG("AWG4")
-
-    # add to pulse_lib
-    # p.add_awgs('AWG1',AWG1)
-    # p.add_awgs('AWG2',AWG2)
-    # p.add_awgs('AWG3',AWG3)
-    # p.add_awgs('AWG4',AWG4)
-
-    # define channels
-    p.define_channel('B0','AWG1', 1)
-    p.define_channel('P1','AWG1', 2)
-    p.define_channel('B1','AWG1', 3)
-    p.define_channel('P2','AWG1', 4)
-    p.define_channel('B2','AWG2', 1)
-    p.define_channel('P3','AWG2', 2)
-    p.define_channel('B3','AWG2', 3)
-    p.define_channel('P4','AWG2', 4)
-    p.define_channel('B4','AWG3', 1)
-    p.define_channel('P5','AWG3', 2)
-    p.define_channel('B5','AWG3', 3)
-    p.define_channel('G1','AWG3', 4)
-    p.define_channel('I_MW','AWG4',1)
-    p.define_channel('Q_MW','AWG4',2)
-    p.define_marker('M1','AWG4', 3, setup_ns=15, hold_ns=15)
-    p.define_marker('M2','AWG4', 4, setup_ns=15, hold_ns=15)
-
-
-    # format : channel name with delay in ns (can be posive/negative)
-    p.add_channel_delay('I_MW',50)
-    p.add_channel_delay('Q_MW',50)
-
-    # add limits on voltages for DC channel compenstation (if no limit is specified, no compensation is performed).
-    # p.add_channel_compensation_limit('B0', (-100, 500))
-
-    try:
-        from V2_software.drivers.virtual_gates.harware import hardware_example
-        hw =  hardware_example("hw")
-        p.load_hardware(hw)
-
-    except:
-        # set a virtual gate matrix (note that you are not limited to one matrix if you would which so)
-        virtual_gate_set_1 = virtual_gates_constructor(p)
-        virtual_gate_set_1.add_real_gates('P1','P2','P3','P4','P5','B0','B1','B2','B3','B4','B5')
-        virtual_gate_set_1.add_virtual_gates('vP1','vP2','vP3','vP4','vP5','vB0','vB1','vB2','vB3','vB4','vB5')
-        virtual_gate_set_1.add_virtual_gate_matrix(np.eye(11))
-
-    #make virtual channels for IQ usage (also here, make one one of these object per MW source)
-    IQ_chan_set_1 = IQ_channel_constructor(p)
-    # set right association of the real channels with I/Q output.
-    IQ_chan_set_1.add_IQ_chan("I_MW", "I")
-    IQ_chan_set_1.add_IQ_chan("Q_MW", "Q")
-    IQ_chan_set_1.add_marker("M1")
-    IQ_chan_set_1.add_marker("M2")
-    # set LO frequency of the MW source. This can be changed troughout the experiments, bit only newly created segments will hold the latest value.
-    IQ_chan_set_1.set_LO(1e9)
-    # name virtual channels to be used.
-    IQ_chan_set_1.add_virtual_IQ_channel("MW_qubit_1")
-    IQ_chan_set_1.add_virtual_IQ_channel("MW_qubit_2")
-
-    print(p.channels)
-    # p.finish_init()
-
-    seg  = p.mk_segment()
-    # seg2 = p.mk_segment()
-    # seg3 = p.mk_segment()
-
-    # seg.vP1.add_block(0,10,1)
-
-
-    # # 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.]])
-    # # add a block pulse of 2V from 40 to 70 ns, to whaterver waveform is already there
-    # seg.B0.add_block(40,70,2)
-    # # just waits (e.g. you want to ake a segment 50 ns longer)
-    # seg.B0.wait(50)
-    # # resets time back to zero in segment. Al the commannds we run before will be put at a negative time.
-    # seg.B0.reset_time()
-    # # this pulse will be placed directly after the wait()
-    # seg.B0.add_block(0,10,2)
-
diff --git a/pulse_lib/segments/data_classes/data_pulse.py b/pulse_lib/segments/data_classes/data_pulse.py
index 8f6ef077..b6ae6912 100644
--- a/pulse_lib/segments/data_classes/data_pulse.py
+++ b/pulse_lib/segments/data_classes/data_pulse.py
@@ -32,8 +32,8 @@ class pulse_delta:
 
     def __iadd__(self, other):
         if isinstance(other, pulse_delta):
-           self.step += other.step
-           self.ramp += other.ramp
+            self.step += other.step
+            self.ramp += other.ramp
         else:
             raise Exception(f'Cannot add pulse_data to {type(other)}')
         return self
@@ -48,8 +48,8 @@ class pulse_delta:
 
     def __imul__(self, other):
         if isinstance(other, Number):
-           self.step *= other
-           self.ramp *= other
+            self.step *= other
+            self.ramp *= other
         else:
             raise Exception(f'Cannot multiply pulse_data with {type(other)}')
         return self
@@ -62,13 +62,14 @@ class pulse_delta:
         # Regular floats have 16 digits precision.
         return abs(self.step) < 1e-9 and abs(self.ramp) < 1e-9
 
+
 @dataclass
 class custom_pulse_element:
     start: float
     stop: float
     amplitude: float
     func: Callable[..., np.ndarray]
-    kwargs: Dict[str,Any]
+    kwargs: Dict[str, Any]
     scaling: int = 1.0
 
     def render(self, sample_rate):
@@ -76,6 +77,7 @@ class custom_pulse_element:
         data = self.func(duration, sample_rate, self.amplitude, **self.kwargs)
         return data*self.scaling
 
+
 @dataclass
 class rendered_element:
     start: int
@@ -83,18 +85,20 @@ class rendered_element:
     wvf: np.ndarray = None
 
 
-def shift_start_stop(data:List[Any], delta) -> None:
+def shift_start_stop(data: List[Any], delta) -> None:
     for element in data:
         element.start += delta
         element.stop += delta
 
-def get_max_time(data:List[Any]) -> float:
+
+def get_max_time(data: List[Any]) -> float:
     stop = 0
     for element in data:
         stop = max(stop, element.stop)
     return stop
 
-def shift_time(data:List[Any], delta) -> None:
+
+def shift_time(data: List[Any], delta) -> None:
     for element in data:
         element.time += delta
 
@@ -129,11 +133,11 @@ class PhaseShift:
         eps = 1e-9
         return -eps < self.phase_shift < eps
 
-# Changed [v1.6.0] time,duration -> start,stop
+
 @dataclass
 class OffsetRamp:
     start: float
-    stop: float # time of next OffsetRamp
+    stop: float  # time of next OffsetRamp
     v_start: float
     v_stop: float
 
@@ -149,6 +153,7 @@ class pulse_data(parent_data):
     """
     class defining base (utility) operations for baseband and microwave pulses.
     """
+
     def __init__(self, hres=False):
         super().__init__()
         self.pulse_deltas = list()
@@ -186,7 +191,6 @@ class pulse_data(parent_data):
         if t != np.inf and t > self.end_time:
             self.end_time = t
 
-
     def add_MW_data(self, MW_data_object):
         """
         add object that defines a microwave pulse.
@@ -201,11 +205,11 @@ class pulse_data(parent_data):
         self.chirp_data.append(chirp)
         self._update_end_time(chirp.stop)
 
-    def add_custom_pulse_data(self, custom_pulse:custom_pulse_element):
+    def add_custom_pulse_data(self, custom_pulse: custom_pulse_element):
         self.custom_pulse_data.append(custom_pulse)
         self._update_end_time(custom_pulse.stop)
 
-    def add_phase_shift(self, phase_shift:PhaseShift):
+    def add_phase_shift(self, phase_shift: PhaseShift):
         if not phase_shift.is_near_zero:
             self._phase_shifts_consolidated = False
             self.phase_shifts.append(phase_shift)
@@ -226,7 +230,6 @@ class pulse_data(parent_data):
         Preform a reset time on the current segment.
         Args:
             time (float) : time where you want the reset. Of None, the totaltime of the segment will be taken.
-            extend_only (bool) : will just extend the time in the segment and not reset it if set to true [do not use when composing wavoforms...].
         '''
         if time is None:
             time = self.total_time
@@ -290,7 +293,7 @@ class pulse_data(parent_data):
 
     def shift_MW_frequency(self, frequency):
         '''
-        shift the frequency of a MW signal that is defined. This is needed for dealing with the upconverion of a IQ signal.
+        shift the frequency of a MW signal. This is needed for dealing with the upconverion of a IQ signal.
 
         Args:
             frequency (float) : frequency you want to shift
@@ -318,9 +321,6 @@ class pulse_data(parent_data):
         for chirp in self.chirp_data:
             chirp.phase += phase_shift
 
-    '''
-    operators for the data object.
-    '''
     def __copy__(self):
         # NOTE: Copy is called in pulse_data_all, before adding virtual channels.
         #       It is also called when a dimension is added in looping.
@@ -413,7 +413,7 @@ class pulse_data(parent_data):
 
             new_data.MW_pulse_data = copy.deepcopy(self.MW_pulse_data)
             for mw_pulse in new_data.MW_pulse_data:
-                mw_pulse.amplitude *=other
+                mw_pulse.amplitude *= other
 
             new_data.custom_pulse_data = copy.deepcopy(self.custom_pulse_data)
             for custom_pulse in new_data.custom_pulse_data:
@@ -421,7 +421,7 @@ class pulse_data(parent_data):
 
             new_data.chirp_data = copy.deepcopy(self.chirp_data)
             for chirp in new_data.chirp_data:
-                chirp.amplitude *=other
+                chirp.amplitude *= other
 
             new_data.phase_shifts = copy.copy(self.phase_shifts)
             new_data.end_time = self.end_time
@@ -443,7 +443,7 @@ class pulse_data(parent_data):
             raise Exception(f'Error in pulse data: {self.pulse_deltas}')
 
         if len(self.pulse_deltas) > 1:
-            self.pulse_deltas.sort(key=lambda p:p.time)
+            self.pulse_deltas.sort(key=lambda p: p.time)
             new_deltas = []
             last = self.pulse_deltas[0]
             for delta in self.pulse_deltas[1:]:
@@ -464,8 +464,7 @@ class pulse_data(parent_data):
 
     def _pre_process(self, sample_rate=None):
         self._consolidate()
-        if (self._preprocessed
-            and (not self._hres or self._preprocessed_sample_rate == sample_rate)):
+        if self._preprocessed and (not self._hres or self._preprocessed_sample_rate == sample_rate):
             return
         n = len(self.pulse_deltas)
         if n == 0:
@@ -487,7 +486,7 @@ class pulse_data(parent_data):
             samples2 = np.zeros(n)
             if self._hres and sample_rate is not None:
                 t_sample = 1e9/sample_rate
-                for i,delta in enumerate(self.pulse_deltas):
+                for i, delta in enumerate(self.pulse_deltas):
                     if delta.time != np.inf:
                         t = int(delta.time/t_sample)*t_sample
                         dt = (delta.time - t)
@@ -504,7 +503,7 @@ class pulse_data(parent_data):
                     samples[i] += - dt*(t_sample-dt)*delta.ramp/2/2
                     samples2[i] = - dt*(t_sample-dt)*delta.ramp/2/2
             else:
-                for i,delta in enumerate(self.pulse_deltas):
+                for i, delta in enumerate(self.pulse_deltas):
                     times[i] = delta.time
                     steps[i] = delta.step
                     ramps[i] = delta.ramp
@@ -546,7 +545,7 @@ class pulse_data(parent_data):
             # add breaks as 0.0 delta
             for time in breaks:
                 self.pulse_deltas.append(pulse_delta(time))
-            self.pulse_deltas.sort(key=lambda p:p.time)
+            self.pulse_deltas.sort(key=lambda p: p.time)
             self._preprocessed = False
 
         self._breaks_processed = True
@@ -580,7 +579,7 @@ class pulse_data(parent_data):
 
         # consolidate also if there is only 1 phase shift. It can be 0.0.
         if len(self.phase_shifts) > 0:
-            self.phase_shifts.sort(key=lambda p:p.time)
+            self.phase_shifts.sort(key=lambda p: p.time)
             new_shifts = []
             last = self.phase_shifts[0]
             for phase_shift in self.phase_shifts[1:]:
@@ -622,7 +621,7 @@ class pulse_data(parent_data):
         for time, duration, v_start, v_stop in zip(self._times, self._intervals,
                                                    self._amplitudes, self._amplitudes_end):
             elements.append(OffsetRamp(time, time+duration, v_start, v_stop))
-        elements.sort(key=lambda p:(p.start,p.stop))
+        elements.sort(key=lambda p: (p.start, p.stop))
         return elements
 
     def _render(self, sample_rate, ref_channel_states, LO):
@@ -673,8 +672,8 @@ class pulse_data(parent_data):
             stop_pulse = mw_pulse.stop
 
             # max amp, freq and phase.
-            amp  =  mw_pulse.amplitude
-            freq =  mw_pulse.frequency
+            amp = mw_pulse.amplitude
+            freq = mw_pulse.frequency
             if LO:
                 freq -= LO
             if abs(freq) > sample_rate*1e9/2:
@@ -705,8 +704,10 @@ class pulse_data(parent_data):
                 amp_envelope = mw_pulse.envelope.get_AM_envelope((stop_pulse - start_pulse), sample_rate)
                 phase_envelope = np.asarray(mw_pulse.envelope.get_PM_envelope((stop_pulse - start_pulse), sample_rate))
 
-            #self.baseband_pulse_data[-1,0] convert to point numbers
-            n_pt = int((stop_pulse - start_pulse) * sample_rate) if isinstance(amp_envelope, float) else len(amp_envelope)
+            # self.baseband_pulse_data[-1,0] convert to point numbers
+            n_pt = (int((stop_pulse - start_pulse) * sample_rate)
+                    if isinstance(amp_envelope, float)
+                    else len(amp_envelope))
             start_pt = iround(start_pulse * sample_rate)
             stop_pt = start_pt + n_pt
 
@@ -759,7 +760,7 @@ class pulse_data(parent_data):
     def _merge_elements(self, elements):
         if len(elements) < 1:
             return elements
-        elements.sort(key=lambda e:e.start)
+        elements.sort(key=lambda e: e.start)
         result = []
         last = elements[0]
         for element in elements[1:]:
@@ -774,7 +775,7 @@ class pulse_data(parent_data):
         result.append(last)
         return result
 
-    def render_MW_and_custom(self, sample_rate, ref_channel_states): # @@@ Is this method used anywhere?
+    def render_MW_and_custom(self, sample_rate, ref_channel_states):  # @@@ Is this method used anywhere?
         '''
         Render MW pulses and custom data in 'rendered_elements'.
         '''
@@ -799,8 +800,8 @@ class pulse_data(parent_data):
             stop_pulse = mw_pulse.stop
 
             # max amp, freq and phase.
-            amp  =  mw_pulse.amplitude
-            freq =  mw_pulse.frequency
+            amp = mw_pulse.amplitude
+            freq = mw_pulse.frequency
             phase = mw_pulse.phase_offset
             if ref_channel_states and mw_pulse.ref_channel in ref_channel_states.start_phase:
                 ref_start_time = ref_channel_states.start_time
@@ -808,8 +809,8 @@ class pulse_data(parent_data):
                 phase_shift = 0
                 if mw_pulse.ref_channel in phase_shifts_channels:
                     for ps in phase_shifts_channels[mw_pulse.ref_channel]:
-                         if ps.time <= start_pulse:
-                             phase_shift += ps.phase_shift
+                        if ps.time <= start_pulse:
+                            phase_shift += ps.phase_shift
             else:
                 ref_start_time = 0
                 ref_start_phase = 0
@@ -822,8 +823,10 @@ class pulse_data(parent_data):
             amp_envelope = mw_pulse.envelope.get_AM_envelope((stop_pulse - start_pulse), sample_rate)
             phase_envelope = mw_pulse.envelope.get_PM_envelope((stop_pulse - start_pulse), sample_rate)
 
-            #self.baseband_pulse_data[-1,0] convert to point numbers
-            n_pt = int((stop_pulse - start_pulse) * sample_rate) if isinstance(amp_envelope, float) else len(amp_envelope)
+            # self.baseband_pulse_data[-1,0] convert to point numbers
+            n_pt = (int((stop_pulse - start_pulse) * sample_rate)
+                    if isinstance(amp_envelope, float)
+                    else len(amp_envelope))
             start_pt = iround(start_pulse * sample_rate)
             stop_pt = start_pt + n_pt
 
@@ -859,10 +862,10 @@ class pulse_data(parent_data):
             if stop - start < 1 or (v_start == 0 and v_stop == 0):
                 continue
             bb_d[f'p{j}'] = {
-                'start':start,
-                'stop':stop,
-                'v_start':v_start,
-                'v_stop':v_stop
+                'start': start,
+                'stop': stop,
+                'v_start': v_start,
+                'v_stop': v_stop
                 }
             j += 1
 
@@ -871,11 +874,11 @@ class pulse_data(parent_data):
 
         pulsedata = self.MW_pulse_data
         all_pulse = {}
-        for (i,pulse) in enumerate(pulsedata):
+        for i, pulse in enumerate(pulsedata):
             phase_shift = 0
             for ps in self.phase_shifts:
-                 if ps.time <= pulse.start:
-                     phase_shift += ps.phase_shift
+                if ps.time <= pulse.start:
+                    phase_shift += ps.phase_shift
             pd = {}
             pd['start'] = pulse.start
             pd['stop'] = pulse.stop
@@ -887,10 +890,9 @@ class pulse_data(parent_data):
                 envelope = envelope_generator()
             pd['AM_envelope'] = repr(envelope.AM_envelope_function)
             pd['PM_envelope'] = repr(envelope.PM_envelope_function)
-            all_pulse[('p%i' %i)] = pd
+            all_pulse[('p%i' % i)] = pd
 
         if all_pulse:
             metadata[name+'_pulses'] = all_pulse
 
         return metadata
-
diff --git a/pulse_lib/segments/segment_container.py b/pulse_lib/segments/segment_container.py
index cfe66fcc..9bb7743f 100644
--- a/pulse_lib/segments/segment_container.py
+++ b/pulse_lib/segments/segment_container.py
@@ -399,49 +399,14 @@ class segment_container():
         if reset_time:
             self.reset_time()
 
-    def add_HVI_marker(self, marker_name, t_off = 0):
-        '''
-        add a HVI marker that corresponds to the current time of the segment (defined by reset_time).
-
-        Args:
-            marker_name (str) : name of the marker to add
-            t_off (str) : offset to be given from the marker
-        '''
-        start_time = self._start_time
-        if start_time.shape != (1,):
-            setpoint_data = self.setpoint_data
-            axis = setpoint_data.axis
-            time_shape = []
-            for i in range(start_time.ndim):
-                s = start_time.shape[i]
-                if i in axis:
-                    time_shape.append(s)
-            start_time = start_time.reshape(time_shape)
-            times = lp.loop_obj()
-            times.add_data(start_time,
-                           labels=setpoint_data.labels[::-1],
-                           units=setpoint_data.units[::-1],
-                           axis=setpoint_data.axis[::-1],
-                           setvals=setpoint_data.setpoints[::-1])
-            time = t_off + times
-        else:
-            time = t_off + start_time[0]
-
-#        print('start', type(start_time), start_time)
-#        print('t_off', t_off)
-#        print('time', time)
-
-        self.add_HVI_variable(marker_name, time, True)
-
-    def add_HVI_variable(self, marker_name, value, time=False):
+    def add_HVI_variable(self, marker_name, value):
         """
         add time for the marker.
         Args:
             name (str) : name of the variable
             value (double) : value to assign to the variable
-            time (bool) : if the value is a timestamp (determines behaviour when the variable is used in a sequence) (coresponding to a master clock)
         """
-        self._software_markers._add_HVI_variable(marker_name, value, time)
+        self._software_markers._add_HVI_variable(marker_name, value, False)
 
     def add_measurement_expression(self, expression=None, name=None, accept_if=None):
         '''
-- 
GitLab