<commit_before>import logging
import time
import os
import numpy as np
from pycqed.utilities.general import setInDict
from pycqed.measurement.waveform_control_CC import qasm_compiler as qcx
from pycqed.instrument_drivers.virtual_instruments.pyqx import qasm_loader as ql
from pycqed.measurement.waveform_control_CC import qasm_to_asm as qta
from pycqed.measurement.waveform_control_CC import qasm_compiler as qcx
import pycqed.measurement.waveform_control_CC.qasm_compiler_helpers as qch


class Sweep_function(object):

    '''
    sweep_functions class for MeasurementControl(Instrument)
    '''

    def __init__(self, **kw):
        self.set_kw()

    def set_kw(self, **kw):
        '''
        convert keywords to attributes
        '''
        for key in list(kw.keys()):
            exec('self.%s = %s' % (key, kw[key]))

    def prepare(self, **kw):
        pass

    def finish(self, **kw):
        pass

    # note that set_paramter is only actively used in soft sweeps.
    # it is added here so that performing a "hard 2D" experiment
    # (see tests for MC) the missing set_parameter in the hard sweep does not
    # lead to unwanted errors
    def set_parameter(self, val):
        '''
        Set the parameter(s) to be sweeped. Differs per sweep function
        '''
        pass


class Soft_Sweep(Sweep_function):

    def __init__(self, **kw):
        self.set_kw()
        self.sweep_control = 'soft'

##############################################################################

class Elapsed_Time_Sweep(Soft_Sweep):
    """
    A sweep function to do a measurement periodically.
    Set the sweep points to the times at which you want to probe the
    detector function.
    """

    def __init__(self, sweep_control='soft',
                 as_fast_as_possible: bool=False, **kw):
        super().__init__()
        self.sweep_control = sweep_control
        self.name = 'Elapsed_Time_Sweep'
        self.parameter_name = 'Time'
        self.unit = 's'
        self.as_fast_as_possible = as_fast_as_possible
        self.time_first_set = None


    def set_parameter(self, val):
        if self.time_first_set is None:
            self.time_first_set = time.time()
            return 0
        elapsed_time = time.time() - self.time_first_set
        if self.as_fast_as_possible:
            return elapsed_time

        if elapsed_time > val:
            logging.warning('Elapsed time {:.2f}s larger than desired {:2f}s'
                            .format(elapsed_time, val))
            return elapsed_time

        while (time.time() - self.time_first_set) < val:
            pass  # wait
        elapsed_time = time.time() - self.time_first_set
        return elapsed_time

class Heterodyne_Frequency_Sweep(Soft_Sweep):
    """
    Performs a joint sweep of two microwave sources for the purpose of
    varying a heterodyne frequency.
    """

    def __init__(self, RO_pulse_type:str,
                 LO_source, IF:float,
                 RF_source=None,
                 sweep_control:str='soft',
                 sweep_points=None,
                 **kw):
        """
        RO_pulse_type (str) : determines wether to only set the LO source
            (in case of a modulated RF pulse) or set both the LO and RF source
            to the required frequency. Can be:
                "gated"             Will set both the LO and RF source
                "pulse_modulated"   Will only set the LO source
                "CW"                Will set both the LO and RF source
        LO_source (instr) : instance of the LO instrument
        IF (float)        : intermodulation frequency in Hz
        RF_source (instr) : instance of the RF instrument, can be None
            if the pulse type is "pulse_modulated"
        """

        super(Heterodyne_Frequency_Sweep, self).__init__()
        self.sweep_control = sweep_control
        self.name = 'Heterodyne frequency'
        self.parameter_name = 'Frequency'
        self.unit = 'Hz'
        self.RO_pulse_type = RO_pulse_type
        self.sweep_points = sweep_points
        self.LO_source = LO_source
        self.IF = IF
<<<<<<< HEAD
        if (('gated' in self.RO_pulse_type.lower()) or
            ('cw' in self.RO_pulse_type.lower())):
=======
        if 'gated' in self.RO_pulse_type.lower():
>>>>>>> master
            self.RF_source = RF_source

    def set_parameter(self, val):
        # RF = LO + IF
        self.LO_source.frequency(val-self.IF)
        if (('gated' in self.RO_pulse_type.lower()) or
            ('cw' in self.RO_pulse_type.lower())):
            self.RF_source.frequency(val)


class Heterodyne_Frequency_Sweep_simple(Soft_Sweep):
    # Same as above but less input arguments

    def __init__(self, MW_LO_source, IF,
                 sweep_points=None,
                 **kw):
        super().__init__()
        self.name = 'Heterodyne frequency'
        self.parameter_name = 'Frequency'
        self.unit = 'Hz'
        self.sweep_points = sweep_points
        self.MW_LO_source = MW_LO_source<commit_msg>Conflicts solved in the Sweep Functions, CW should be working for everyone<commit_after>import logging
import time
import os
import numpy as np
from pycqed.utilities.general import setInDict
from pycqed.measurement.waveform_control_CC import qasm_compiler as qcx
from pycqed.instrument_drivers.virtual_instruments.pyqx import qasm_loader as ql
from pycqed.measurement.waveform_control_CC import qasm_to_asm as qta
from pycqed.measurement.waveform_control_CC import qasm_compiler as qcx
import pycqed.measurement.waveform_control_CC.qasm_compiler_helpers as qch


class Sweep_function(object):

    '''
    sweep_functions class for MeasurementControl(Instrument)
    '''

    def __init__(self, **kw):
        self.set_kw()

    def set_kw(self, **kw):
        '''
        convert keywords to attributes
        '''
        for key in list(kw.keys()):
            exec('self.%s = %s' % (key, kw[key]))

    def prepare(self, **kw):
        pass

    def finish(self, **kw):
        pass

    # note that set_paramter is only actively used in soft sweeps.
    # it is added here so that performing a "hard 2D" experiment
    # (see tests for MC) the missing set_parameter in the hard sweep does not
    # lead to unwanted errors
    def set_parameter(self, val):
        '''
        Set the parameter(s) to be sweeped. Differs per sweep function
        '''
        pass


class Soft_Sweep(Sweep_function):

    def __init__(self, **kw):
        self.set_kw()
        self.sweep_control = 'soft'

##############################################################################

class Elapsed_Time_Sweep(Soft_Sweep):
    """
    A sweep function to do a measurement periodically.
    Set the sweep points to the times at which you want to probe the
    detector function.
    """

    def __init__(self, sweep_control='soft',
                 as_fast_as_possible: bool=False, **kw):
        super().__init__()
        self.sweep_control = sweep_control
        self.name = 'Elapsed_Time_Sweep'
        self.parameter_name = 'Time'
        self.unit = 's'
        self.as_fast_as_possible = as_fast_as_possible
        self.time_first_set = None


    def set_parameter(self, val):
        if self.time_first_set is None:
            self.time_first_set = time.time()
            return 0
        elapsed_time = time.time() - self.time_first_set
        if self.as_fast_as_possible:
            return elapsed_time

        if elapsed_time > val:
            logging.warning('Elapsed time {:.2f}s larger than desired {:2f}s'
                            .format(elapsed_time, val))
            return elapsed_time

        while (time.time() - self.time_first_set) < val:
            pass  # wait
        elapsed_time = time.time() - self.time_first_set
        return elapsed_time

class Heterodyne_Frequency_Sweep(Soft_Sweep):
    """
    Performs a joint sweep of two microwave sources for the purpose of
    varying a heterodyne frequency.
    """

    def __init__(self, RO_pulse_type:str,
                 LO_source, IF:float,
                 RF_source=None,
                 sweep_control:str='soft',
                 sweep_points=None,
                 **kw):
        """
        RO_pulse_type (str) : determines wether to only set the LO source
            (in case of a modulated RF pulse) or set both the LO and RF source
            to the required frequency. Can be:
                "gated"             Will set both the LO and RF source
                "pulse_modulated"   Will only set the LO source
                "CW"                Will set both the LO and RF source
        LO_source (instr) : instance of the LO instrument
        IF (float)        : intermodulation frequency in Hz
        RF_source (instr) : instance of the RF instrument, can be None
            if the pulse type is "pulse_modulated"
        """

        super(Heterodyne_Frequency_Sweep, self).__init__()
        self.sweep_control = sweep_control
        self.name = 'Heterodyne frequency'
        self.parameter_name = 'Frequency'
        self.unit = 'Hz'
        self.RO_pulse_type = RO_pulse_type
        self.sweep_points = sweep_points
        self.LO_source = LO_source
        self.IF = IF
        if (('gated' in self.RO_pulse_type.lower()) or
            ('cw' in self.RO_pulse_type.lower())):
            self.RF_source = RF_source

    def set_parameter(self, val):
        # RF = LO + IF
        self.LO_source.frequency(val-self.IF)
        if (('gated' in self.RO_pulse_type.lower()) or
            ('cw' in self.RO_pulse_type.lower())):
            self.RF_source.frequency(val)


class Heterodyne_Frequency_Sweep_simple(Soft_Sweep):
    # Same as above but less input arguments

    def __init__(self, MW_LO_source, IF,
                 sweep_points=None,
                 **kw):
        super().__init__()
        self.name = 'Heterodyne frequency'
        self.parameter_name = 'Frequency'
        self.unit = 'Hz'
        self.sweep_points = sweep_points
        self.MW_LO_source = MW_LO_source
{'fraction_non_alphanumeric': 0.0981760191368484, 'fraction_numerical': 0.0007973686833449616, 'mean_word_length': 2.286603340976089, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '233756', 'n_tokens_mistral': 3060, 'n_tokens_neox': 2929, 'n_words': 830}