ColwynGulliford / lume-gpt

Apache License 2.0
3 stars 4 forks source link

GPT lattice template causes error because spacechargeGPU #5

Closed ColwynGulliford closed 1 year ago

ColwynGulliford commented 1 year ago

User reports issue with GPT lattice template file:

image001

ColwynGulliford commented 1 year ago

To try and see if there is an issue, I'll install lume-GPT from conda and try the same commands:

  1. Create a fresh conda environment:

    Screenshot 2023-09-20 at 12 47 01 PM
  2. Install lume-gpt:

    Screenshot 2023-09-20 at 12 48 16 PM
  3. Check main dependencies

    Screenshot 2023-09-20 at 12 49 07 PM
  4. Run notebooks:

Screenshot 2023-09-20 at 12 51 34 PM

The simple drift example works...

ColwynGulliford commented 1 year ago

I found a more complicated example which seems to reproduce the error shown above:

It seems like the function Lattice.write_gpt_lines is sometimes not including a "\n" at the end of the lattice file line strings:


setfile("beam", "gpt_particles.gdf");time=0.0;auto_phase=0.0;space_charge=0.0;cathode=0.0;space_charge_type=1.0;RadiusMax=0.04;GBacc=5.5;xacc=6.5;accuracy(GBacc, xacc);dtmin=1e-16;dtmax=1e-10; Alpha=1.0;Fn=0.5;verror=0.005;Nstd=5.0;tree_code_theta=1.0;tree_code_R=1e-06;if (space_charge == 1) {    if (space_charge_type == 1) {        if(cathode == 1) {            spacecharge3Dmesh("Cathode", "MeshNfac", Alpha, "MeshAdapt", Fn, "SolverAcc", verror, "MeshBoxSize", Nstd);        } else {            spacecharge3Dmesh("MeshNfac", Alpha, "MeshAdapt", Fn, "SolverAcc", verror, "MeshBoxSize", Nstd);        }    }    if (space_charge_type == 2) {        setrmacrodist("beam","u",tree_code_R,0) ;        spacecharge3Dtree(tree_code_theta) ;   }            #if (space_charge_type == 3) {    #    spacechargeP2Pgpu("3D", "SinglePrecision");    #    }}Ntout=50.0;tmax=10e-9;ZSTART=-0.005;ZSTOP=3;zminmax("wcs", "I", ZSTART, ZSTOP);if(Ntout>0) {    tout(time, tmax, tmax/Ntout);}
# b1
petr-lanl commented 1 year ago

I have found the difference: from gpt.element import Lattice in multiple_runs.ipynb seems to be the issue.

The working example provided uses from gpt.lattice import Lattice which is a different Class. Why do we have two Lattice Classes?

The new class uses file_lines = [line+'\n' for line in BASIC_TEMPLATE] on line 276 while the problematic class uses file_lines = BASIC_TEMPLATE on line 785.

That is why I made a comment about """...""".split('\n') and missing \n in the BASIC_TEMPLATE in my email to you.

ColwynGulliford commented 1 year ago

The issue was importing a stale Lattice class definition from gpt.element. Please import the Lattice class from gpt.lattice. I've removed the stale definition and will update the example notebooks accordingly.

petr-lanl commented 1 year ago

Thank you, I am using gpt.lattice definition now. I am still having issues running your multiple_runs.ipynb example:

  1. cell 5 has , workdir='temp' option that would stop execution if user does not have 'temp' folder locally. I have created the folder and managed to move to the next issue.
  2. cell 7 does not run image the reason is that Error occured: True Cause: gpt: lume-gpt/examples/temp/gpt.temp.in(37): Error: Too many outputs
ColwynGulliford commented 1 year ago

Yeah, I think the track1_to_z function hasn't been used in many years by anyone, so it probably needs some careful work. I would suggest not using it.

For now, I've removed the workdir = "temp" lines and just deleted cell 7, as this wasn't relevant to that notebook anyways.

ColwynGulliford commented 1 year ago

I'm running through the example notebooks and updating those as well and will make a new release when they check out.