Skip to content

Commit acae65f

Browse files
committed
Python 3 migration of PyPARIS_sim_class v1.2.4
1 parent 14abe96 commit acae65f

13 files changed

+42
-42
lines changed

LHC_custom.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def __init__(self, n_segments, machine_configuration, optics_dict=None, **kwargs
9191
pp.i_octupole_defocusing = None
9292
pp.octupole_knob = None
9393

94-
for attr in kwargs.keys():
94+
for attr in list(kwargs.keys()):
9595
if kwargs[attr] is not None:
9696
if type(kwargs[attr]) is list or type(kwargs[attr]) is np.ndarray:
9797
str2print = '[%s ...]'%repr(kwargs[attr][0])

Save_Load_Status.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def load_from_file(self):
3333

3434
def print_from_file(self):
3535
with open(self.filename) as fid:
36-
print fid.read()
36+
print(fid.read())
3737

3838
def before_simulation(self):
3939
self.first_run = False
@@ -43,7 +43,7 @@ def before_simulation(self):
4343
self.first_turn_part += self.N_turns_per_run
4444
self.last_turn_part += self.N_turns_per_run
4545
except IOError:
46-
print 'Simulation Status not found --> initializing simulation'
46+
print('Simulation Status not found --> initializing simulation')
4747
self.first_run = True
4848
self.present_simulation_part = 0
4949
self.first_turn_part = 0
@@ -59,24 +59,24 @@ def before_simulation(self):
5959

6060
self.dump_to_file()
6161

62-
print 'Starting part:\n\n'
62+
print('Starting part:\n\n')
6363
self.print_from_file()
64-
print '\n\n'
64+
print('\n\n')
6565

6666
def after_simulation(self):
6767
self.load_from_file()
6868
self.present_part_done = True
6969
self.present_part_running = False
7070
self.dump_to_file()
7171

72-
print 'Done part:\n\n'
72+
print('Done part:\n\n')
7373
self.print_from_file()
74-
print '\n\n'
74+
print('\n\n')
7575

7676
if self.check_for_resubmit:
7777

7878
if self.last_turn_part+1<self.N_turns_target:
79-
print 'resubmit the job'
79+
print('resubmit the job')
8080
os.system('bsub < job.cmd')
8181

8282
def restart_last(self):
@@ -93,7 +93,7 @@ def restart_last(self):
9393

9494
self.dump_to_file()
9595

96-
print 'Restored status:\n\n'
96+
print('Restored status:\n\n')
9797
self.print_from_file()
98-
print '\n\n'
98+
print('\n\n')
9999

Simulation.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def init_all(self):
3030
self.n_kick_smooth = pp.n_segments
3131

3232
# define the machine
33-
from LHC_custom import LHC
33+
from .LHC_custom import LHC
3434
self.machine = LHC(
3535
n_segments=pp.n_segments,
3636
machine_configuration=pp.machine_configuration,
@@ -181,10 +181,10 @@ def init_all(self):
181181
i_start_part, i_end_part = sharing.my_part(myid)
182182
self.mypart = self.machine.one_turn_map[i_start_part:i_end_part]
183183
if self.ring_of_CPUs.I_am_a_worker:
184-
print 'I am id=%d/%d (worker) and my part is %d long'%(myid, self.ring_of_CPUs.N_nodes, len(self.mypart))
184+
print('I am id=%d/%d (worker) and my part is %d long'%(myid, self.ring_of_CPUs.N_nodes, len(self.mypart)))
185185
elif self.ring_of_CPUs.I_am_the_master:
186186
self.non_parallel_part = self.machine.one_turn_map[i_end_parallel:]
187-
print 'I am id=%d/%d (master) and my part is %d long'%(myid, self.ring_of_CPUs.N_nodes, len(self.mypart))
187+
print('I am id=%d/%d (master) and my part is %d long'%(myid, self.ring_of_CPUs.N_nodes, len(self.mypart)))
188188

189189
#install eclouds in my part
190190
my_new_part = []
@@ -248,7 +248,7 @@ def init_all(self):
248248
self.mypart = my_new_part
249249

250250
if pp.footprint_mode:
251-
print 'Proc. %d computing maps'%myid
251+
print('Proc. %d computing maps'%myid)
252252
# generate a bunch
253253
bunch_for_map=self.machine.generate_6D_Gaussian_bunch_matched(
254254
n_macroparticles=pp.n_macroparticles_for_footprint_map, intensity=pp.intensity,
@@ -283,7 +283,7 @@ def init_all(self):
283283
else:
284284
for ss in slices_list_for_map:
285285
ele.track(ss)
286-
print 'Proc. %d done with maps'%myid
286+
print('Proc. %d done with maps'%myid)
287287

288288
with open('measured_optics_%d.pkl'%myid, 'wb') as fid:
289289
pickle.dump({
@@ -322,10 +322,10 @@ def init_master(self):
322322
elif SimSt.first_run:
323323

324324
if pp.bunch_from_file is not None:
325-
print 'Loading bunch from file %s ...'%pp.bunch_from_file
325+
print('Loading bunch from file %s ...'%pp.bunch_from_file)
326326
with h5py.File(pp.bunch_from_file, 'r') as fid:
327327
self.bunch = self.buffer_to_piece(np.array(fid['bunch']).copy())
328-
print 'Bunch loaded from file.\n'
328+
print('Bunch loaded from file.\n')
329329

330330
else:
331331
self.bunch = self.machine.generate_6D_Gaussian_bunch_matched(
@@ -344,12 +344,12 @@ def init_master(self):
344344
self.bunch.x += x_kick
345345
self.bunch.y += y_kick
346346

347-
print 'Bunch initialized.'
347+
print('Bunch initialized.')
348348
else:
349-
print 'Loading bunch from file...'
349+
print('Loading bunch from file...')
350350
with h5py.File('bunch_status_part%02d.h5'%(SimSt.present_simulation_part-1), 'r') as fid:
351351
self.bunch = self.buffer_to_piece(np.array(fid['bunch']).copy())
352-
print 'Bunch loaded from file.'
352+
print('Bunch loaded from file.')
353353

354354
# initial slicing
355355
self.slicer = UniformBinSlicer(n_slices = pp.n_slices, z_cuts=(-pp.z_cut, pp.z_cut))
@@ -371,7 +371,7 @@ def init_master(self):
371371

372372
pieces_to_be_treated = slice_obj_list
373373

374-
print 'N_turns', self.N_turns
374+
print('N_turns', self.N_turns)
375375

376376
if pp.footprint_mode:
377377
self.recorded_particles = ParticleTrajectories(pp.n_macroparticles_for_footprint_track, self.N_turns)
@@ -413,7 +413,7 @@ def finalize_turn_on_master(self, pieces_treated):
413413
if not pp.footprint_mode and self.bunch.macroparticlenumber < pp.sim_stop_frac * pp.n_macroparticles:
414414
orders_to_pass.append('stop')
415415
self.SimSt.check_for_resubmit = False
416-
print 'Stop simulation due to beam losses.'
416+
print('Stop simulation due to beam losses.')
417417

418418
# 2. for the emittance growth
419419
if pp.flag_check_emittance_growth:
@@ -422,7 +422,7 @@ def finalize_turn_on_master(self, pieces_treated):
422422
if not pp.footprint_mode and (self.bunch.epsn_x() > epsn_x_max or self.bunch.epsn_y() > epsn_y_max):
423423
orders_to_pass.append('stop')
424424
self.SimSt.check_for_resubmit = False
425-
print 'Stop simulation due to emittance growth.'
425+
print('Stop simulation due to emittance growth.')
426426

427427
return orders_to_pass, new_pieces_to_be_treated
428428

@@ -438,13 +438,13 @@ def finalize_simulation(self):
438438
# Tunes
439439

440440
import NAFFlib
441-
print 'NAFFlib spectral analysis...'
441+
print('NAFFlib spectral analysis...')
442442
qx_i = np.empty_like(self.recorded_particles.x_i[:,0])
443443
qy_i = np.empty_like(self.recorded_particles.x_i[:,0])
444444
for ii in range(len(qx_i)):
445445
qx_i[ii] = NAFFlib.get_tune(self.recorded_particles.x_i[ii] + 1j*self.recorded_particles.xp_i[ii])
446446
qy_i[ii] = NAFFlib.get_tune(self.recorded_particles.y_i[ii] + 1j*self.recorded_particles.yp_i[ii])
447-
print 'NAFFlib spectral analysis done.'
447+
print('NAFFlib spectral analysis done.')
448448

449449
# Save
450450
import h5py
@@ -460,7 +460,7 @@ def finalize_simulation(self):
460460
'y_centroid': np.mean(self.recorded_particles.y_i, axis=1)}
461461

462462
with h5py.File('footprint.h5', 'w') as fid:
463-
for kk in dict_beam_status.keys():
463+
for kk in list(dict_beam_status.keys()):
464464
fid[kk] = dict_beam_status[kk]
465465
else:
466466
#save data for multijob operation and launch new job

examples/000_feedback_damping_time/mystyle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def mystyle(fontsz=16):
88
font = {#'family' : 'normal',
99
#'weight' : 'bold',
1010
'size' : fontsz}
11-
print fontsz
11+
print(fontsz)
1212
rcdefaults()
1313
rc('font', **font)
1414

examples/001_simulation_with_eclouds/mystyle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def mystyle(fontsz=16):
88
font = {#'family' : 'normal',
99
#'weight' : 'bold',
1010
'size' : fontsz}
11-
print fontsz
11+
print(fontsz)
1212
rcdefaults()
1313
rc('font', **font)
1414

examples/003_save_electron_potential/000_save_pinch_first_ecloud_average.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def one_pinch(save_rho=True, save_sigmas=False, save_coords=False):
4141
t_start = time.mktime(time.localtime())
4242
for i_ss, ss in enumerate(list_slice_objects[::-1]):
4343
if np.mod(i_ss, 20)==0:
44-
print("%d / %d"%(i_ss, N_slices))
44+
print(("%d / %d"%(i_ss, N_slices)))
4545
first_ecloud.track(ss)
4646
if ss.slice_info != 'unsliced':
4747
z_centers.append(ss.slice_info['z_bin_center'])
@@ -51,7 +51,7 @@ def one_pinch(save_rho=True, save_sigmas=False, save_coords=False):
5151

5252
t_end = time.mktime(time.localtime())
5353

54-
print('Track time %.2f s' % (t_end - t_start))
54+
print(('Track time %.2f s' % (t_end - t_start)))
5555

5656
dd = {}
5757
dd['phi'] = first_ecloud.phi_ele_last_track
@@ -74,7 +74,7 @@ def one_pinch(save_rho=True, save_sigmas=False, save_coords=False):
7474
dd['rho'] /= 1.*n_pinches_to_average
7575

7676
for i in range(n_pinches_to_average-1):
77-
print('Running pinch #%d/%d.'%(i,n_pinches_to_average))
77+
print(('Running pinch #%d/%d.'%(i,n_pinches_to_average)))
7878
dd_temp = one_pinch(save_rho=save_rho, save_sigmas=False, save_coords=False)
7979
dd['phi'] += dd_temp['phi']/(1.*n_pinches_to_average)
8080
if save_rho:

examples/003_save_electron_potential/001_plots_and_video_of_saved_pinch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161

6262
for i_frame, z_obs in enumerate(list(z_movie) + [z_single_frame_interactive]):
6363

64-
print('Frame %d/%d'%(i_frame, len(z_movie)))
64+
print(('Frame %d/%d'%(i_frame, len(z_movie))))
6565

6666
if not gen_movie and i_frame < len(z_movie):
6767
continue

generate_python3

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ rm -rf ../python3/PyPARIS_sim_class
33
cp -r ../PyPARIS_sim_class ../python3/PyPARIS_sim_class
44
rm ../python3/PyPARIS_sim_class/*.so
55
2to3 --output-dir=../python3/PyPARIS_sim_class -W -n ../PyPARIS_sim_class
6-
rm -rf ../python3/PyPARIS_sim_class/.git
6+
#rm -rf ../python3/PyPARIS_sim_class/.git

t000_build_single_instance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Simulation as sim_mod
1+
from . import Simulation as sim_mod
22

33
N_proc_pretend = 4
44
myid_pretend = 2

t001_run_single_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Simulation as sim_mod
1+
from . import Simulation as sim_mod
22

33
ring = sim_mod.get_serial_CPUring()
44
ring.run()

0 commit comments

Comments
 (0)