コード例 #1
0
    def _monitor_cpu_gpu(self, monitor1, monitor2, bunch1, bunch2):
        '''
        Test whether monitor.dump(bunch1/bunch2) works. Read the resulting
        h5 files and compare (some) results
        '''
        params_to_check = [
            'mean_x', 'sigma_dp', 'macroparticlenumber',
            'n_macroparticles_per_slice'
        ]
        for i in range(monitor2.n_steps):
            bunch2.x += 1
            bunch2.xp -= 0.1
            bunch2.dp *= 0.97
            monitor2.dump(bunch2)
        res1 = self.read_h5_file(monitor2.filename + '.h5', params_to_check)

        with GPU(bunch1) as device:
            for i in range(monitor1.n_steps):
                bunch1.x += 1
                bunch1.xp -= 0.1
                bunch1.dp *= 0.97
                monitor1.dump(bunch1)
        res2 = self.read_h5_file(monitor1.filename + '.h5', params_to_check)

        for i in range(len(res1)):
            self.assertTrue(
                np.allclose(res1[i], res2[i]),
                msg='.h5 file generated by monitor of CPU/GPU differ' +
                str(params_to_check))
コード例 #2
0
    def _track_cpu_gpu(self, list_of_maps, bunch1, bunch2, nturns=1):
        '''
        Tracks both bunches through the list of maps (once GPU, once CPU)
        and checks whether it yields the same result. Returns True/False.
        Make sure bunch1, bunch2 are two identical objects (not one!)
        Change the actual implementation of the GPU interface/strategy here
        '''
        # GPU
        with GPU(bunch1) as device:
            for n in range(nturns):
                for m in list_of_maps:
                    m.track(bunch1)

        # CPU
        for n in range(nturns):
            for m in list_of_maps:
                m.track(bunch2)
        #print bunch1.x
        #print bunch2.x
        # make sure the beam is sorted according to it's id to be able to compare them
        # this is required since argsort for the slices is not unique
        # (particles within slices can be permuted, gpu/cpu might be different!)
        bunch1.sort_for('id')
        bunch2.sort_for('id')
        for att in bunch1.coords_n_momenta | set(['id']):
            if not np.allclose(getattr(bunch1, att),
                               getattr(bunch2, att),
                               rtol=1.e-5,
                               atol=1.e-8):
                return False
        return True
コード例 #3
0
 def test_if_beam_is_numpy(self):
     '''
     Check if beam.x is a numpy array before and after the with statement
     '''
     bunch = self.create_all1_bunch()
     self.assertTrue(self.check_if_npndarray(bunch),
                     msg='beam.x is not of type np.ndarray')
     with GPU(bunch) as device:
         foo = 1
     self.assertTrue(self.check_if_npndarray(bunch),
                     msg='beam.x is not of type np.ndarray')