ColwynGulliford / lume-gpt

Apache License 2.0
3 stars 4 forks source link

Easygdf issue #1

Closed curiome closed 1 year ago

curiome commented 3 years ago

I am experiencing a problem with loading the output gdf file after a successful gpt run.

Running the code:

from gpt import GPT

G = GPT(input_file="test.in", verbose=True)
G.set_variables({"scatter_on": 1})
G.run(gpt_verbose=True)
print(G)

with input file test.in:


### --------------------------------------------------------------------------
### Start initial beam ###
### --------------------------------------------------------------------------
distgen = 0.;

if (distgen == 1) {
    setfile("beam", "gpt.particles.gdf");
    # for single particle, see lume-gpt repo examples
} else {
    radius = 0.8e-3; # 2.5e-3
    tlen = 3e-10; # 3e-11
    setparticles("beam",10000,me,qe,-15e-12);
    setrxydist("beam","u",radius/2,radius);
    setphidist("beam","u",0,2*pi);
    #setzdist("beam", "u", 1e-6, 2e-6);
    #setGBxdist("beam", "u", 150e-15, 300e-15);
    setGBxdist("beam", "g", 0, 1e-6, 3, 3);
    setGBydist("beam", "g", 0, 1e-6, 3, 3);
    setGBxemittance("beam", 1e-7); # 100 meV MTE, r = 1.5e-3
    setGByemittance("beam", 1e-7);
    settdist("beam","u",0,tlen);
}
### --------------------------------------------------------------------------

### --------------------------------------------------------------------------
### Accuracy ###
### --------------------------------------------------------------------------
RadiusMax = 1.0;
### --------------------------------------------------------------------------

### --------------------------------------------------------------------------
### Pipe Boundary ###
### --------------------------------------------------------------------------
scatter_on = 1.;
if (scatter_on == 1) {
    forwardscatter("wcs", "I", "remove", 0.0);
    scatterpipe("wcs","I", -1, 1, RadiusMax) scatter="remove";
}
### --------------------------------------------------------------------------
### --------------------------------------------------------------------------
### Specify output ###
### --------------------------------------------------------------------------
npts = 20; #100
tend = 1.6e-8; #1.8e-8
zend = 2.736; # dump at 4.0
zstart = -1e-6;

#screen("wcs","I",zstart,zend,zend/npts); #1e-3,1.76,1e-2
tout(0, tend,tend/npts); 
#screen("wcs","I",2.736); # 2.736 3rd screen

#zminmax("wcs","I",zstart,zend); # Kill stationary particles
#GBzmin("wcs", "I", 5.0e-10, 0.0); # kill particles going backwards (gamma*beta < 0.0) after t=5e-10 s
#tmax = 20.8e-8;
#

I am getting the following errors:

   Loading GPT data from /tmp/tmpu1c2his6/test.out.gdf
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-3-0515a1c6e657> in <module>
      1 # it breaks due to easygdf when scatterpipe is on
      2 G.set_variables({"scatter_on": 1})
----> 3 G.run(gpt_verbose=True)
      4 print(G)

/nfs/user/jb2483/git/public/lume-gpt/gpt/gpt.py in run(self, gpt_verbose)
    299             self.configure()
    300         #pass
--> 301         self.run_gpt(verbose=self.verbose, timeout=self.timeout, gpt_verbose=gpt_verbose)
    302 
    303 

/nfs/user/jb2483/git/public/lume-gpt/gpt/gpt.py in run_gpt(self, verbose, parse_output, timeout, gpt_verbose)
    367 
    368         if parse_output:
--> 369             self.load_output(file=self.get_gpt_output_file())
    370 
    371         run_info['run_time'] = time() - t1

/nfs/user/jb2483/git/public/lume-gpt/gpt/gpt.py in load_output(self, file)
    176 
    177         self.vprint(f'   Loading GPT data from {self.get_gpt_output_file()}')
--> 178         touts, screens=parsers.read_gdf_file(file, self.verbose)  # Raw GPT data
    179 
    180         self.output['particles'] = raw_data_to_particle_groups(touts, screens, verbose=self.verbose, ref_ccs=self.ref_ccs)

/nfs/user/jb2483/git/public/lume-gpt/gpt/parsers.py in read_gdf_file(gdffile, verbose)
    150     t1 = time.time()
    151     with open(gdffile, 'rb') as f:
--> 152         touts, screens = easygdf.load(f, extra_screen_keys=['q','nmacro',"ID","m"], extra_tout_keys=['q','nmacro',"ID","m"])
    153     t2 = time.time()
    154     if(verbose):

/nfs/user/jb2483/git/public/lume-gpt/gpt/easygdf.py in load(file, tout_filter, screen_filter, screen_block_size, tout_block_size, extra_tout_keys, extra_screen_keys)
    277                         # Get the array
    278                         phase_space_array = numpy.array([
--> 279                             screen_tout_arrays['x'],
    280                             screen_tout_arrays['Bx'] * screen_tout_arrays['G'],
    281                             screen_tout_arrays['y'],

KeyError: 'x'

Note this problem occurs when the code has scatterpipe line with tout option.

ColwynGulliford commented 3 years ago

Unfortunately, I could not reproduce the error. Using the GPT input file provided I ran:

Screen Shot 2021-04-09 at 9 27 46 AM

And this was using the Easygdf forked into lume-gpt.

ColwynGulliford commented 3 years ago

It may be a difference between GPT versions? That would be unfortunate. Which GPT are you using?

curiome commented 3 years ago

I believe it is 3.22. When I run gpt -v command the date it prints is Apr 3 2019.

ColwynGulliford commented 3 years ago

Thanks, I'm apparently running a version from 2014. I'll try running on lab computers...

curiome commented 3 years ago

@ColwynGulliford Your suspicion was correct. It runs without an error with 3.0 version (Dec 2011).

ColwynGulliford commented 3 years ago

Ok thanks, I'll see if the new Easygdf works with both GPTs, that would be the nicest solution...