Ejemplo n.º 1
0
 def generate_TablePulseTemplates(self,number_of_entries,max_dist=RANGE):
     while 1:
         x = TablePulseTemplate()
         name = "TablePulseTemplate_{}".format(self.__TablePulseTemplateOffset)
         self.__TablePulseTemplateOffset +=1
         if bool(random.getrandbits(1)):
             x.identifier = name
         previous_min = 0
         previous_max = 0
         parameter_names = []
         
         for i in range(number_of_entries):
             dict_ = {}
             for j in ["time","voltage"]:
                 a = random.choice(["float","str","ParameterDeclaration"])
                 if a == "float":
                     if j == "time":
                         dict_[j] = random.uniform(previous_max,previous_max+max_dist)
                         previous_min = dict_[j]
                         previous_max = dict_[j]
                     else:
                         dict_[j] = random.uniform(-RANGE,RANGE)
                 elif a == "str":
                     dict_[j] = "_".join([name,"str",str(i),str(j)])
                     parameter_names.append(dict_[j])
                 elif a == "ParameterDeclaration":
                     if j == "time":
                         dict_[j] = self.generate_ParameterDeclaration(previous_min, previous_min+max_dist, name, previous_max).__next__()
                         previous_min = dict_[j].min_value
                         previous_max = dict_[j].max_value
                     else:
                         dict_[j] = self.generate_ParameterDeclaration().__next__()
                     parameter_names.append(dict_[j].name)
             x.add_entry(time=dict_["time"],voltage=dict_["voltage"],interpolation=random.choice(INTERPOLATION_STRATEGIES))
         yield x
Ejemplo n.º 2
0
    def integrated_test_with_sequencer_and_pulse_templates(self) -> None:
        # Setup test data
        square = TablePulseTemplate()
        square.add_entry('up', 'v', 'hold')
        square.add_entry('down', 0, 'hold')
        square.add_entry('length', 0)

        mapping1 = {
            'up': 'uptime',
            'down': 'uptime + length',
            'v': 'voltage',
            'length': '0.5 * pulse_length'
        }

        outer_parameters = ['uptime', 'length', 'pulse_length', 'voltage']

        parameters = {}
        parameters['uptime'] = 5
        parameters['length'] = 10
        parameters['pulse_length'] = 100
        parameters['voltage'] = 10

        sequence = SequencePulseTemplate([(square, mapping1), (square, mapping1)], outer_parameters)

        # run the sequencer and render the plot
        sample_rate = 20
        plotter = Plotter(sample_rate=sample_rate)
        sequencer = Sequencer(plotter)
        sequencer.push(sequence, parameters)
        block = sequencer.build()
        times, voltages = plotter.render(block)

        # compute expected values
        expected_times = numpy.linspace(0, 100, sample_rate)
        expected_voltages = numpy.zeros_like(expected_times)
        expected_voltages[100:300] = numpy.ones(200) * parameters['voltage']

        # compare
        self.assertEqual(expected_times, times)
        self.assertEqual(expected_voltages, voltages)
Ejemplo n.º 3
0
#            /  |
#           /   |
#          b    |
#          |    |
#          |    |
#          |    |
# a--------|    ------------------d
#
# Point: Tuple
# a: (0,0)
# b: ('t_up', 'value1')
# c: ('t_down', 'value2')
# d: ('end', 0)
# t_down should not be given by the user, instead give the time between c and b as 'length'

squarePulse = TablePulseTemplate() # Prepare new empty Pulse
# Then add pulses sequentially
squarePulse.add_entry('t_up', 'value1', interpolation='hold') # hold is the standard interpolation value
squarePulse.add_entry('t_down', 'value2', interpolation='linear')
squarePulse.add_entry('end', 0, interpolation='jump')

# We can just plug in values for the parameters to get an actual pulse:
parameters = {'t_up': 200,
              't_down': 2000,
              'end': 4000,
              'value1': 2.2,
              'value2': 3.0}

# with these parameters, we can plot the pulse:
plot(squarePulse, parameters)