Can't extract energy from .dst file  [SOLVED]

https://www.dacm-logiciels.fr/tracewin
Chinalihaipeng
Beginner
Beginner
Posts: 6
Joined: Thu 15 Sep 2022 10:45
Country:
China (cn)
China

Can't extract energy from .dst file  [SOLVED]

Post by Chinalihaipeng »

OS : win10 (64-bit)
ProductName: Tracewin.exe and TraceW64.exe
Tracewin version: 2.18.2
User :lihaipeng
Computer :lihaipeng

I'm sorry to bother you, but I have no choice. I am now trying to optimize the beam with Deep Reinforcement Learning. So I need to use Python to call Tracewin to load the part_ dtl1.dst file and run it (there are relevant operations in the manual). I tried many times but failed.

It seems that Tracewin is loaded part_ dtl1.dst file, But the input beam parameters (emittances and twin parameters) are not automatically extracted from the specified file and used for computation.

This is my python code:
path=r'C:\Users\HaoLuo\TraceWin.exe C:\Users\HaoLuo\QD_DTL.ini dst_file1=C:\Users\HaoLuo\part_dtl1.dst’
#tracewin software,ini file,and dst file
os.system(path)

There are relevant operations on page 15 of the Tracewin manual:
page 15 in tracewin manual.jpeg_recompress.jpg
page 15 in tracewin manual.jpeg_recompress.jpg (95.11 KiB) Viewed 15349 times
There are files I used:
QD_DTL.ini
(43.77 KiB) Downloaded 208 times
Phase2tank2.dat
(983 Bytes) Downloaded 211 times
part_dtl1.dst
(441.78 KiB) Downloaded 209 times
Last edited by Chinalihaipeng on Fri 4 Nov 2022 17:50, edited 1 time in total.
FranceNicolasChauvin
Global moderators
Global moderators
Posts: 8
Joined: Fri 2 Sep 2022 11:39
Country:
France (fr)
France

Re: A bug in Tracewin? i need help

Post by FranceNicolasChauvin »

Dear lihaipeng,

I think you forgot something when you saved your "QD_DTL.ini" file: if you click on the "Multiparticle" tab and you go to "Input distribution type", "6 dimensional ellipse" was selected. So, the input beam distribution of your simulation was randomly generated in 6D (gaussian), considering the Twiss parameters that were on the "Main" tab.

You have to select "use distribution from input particle file (*.dst)", and save again your project(to save the correct "ini" file). That way, the input distribution you have specified in your command line will be taken into account and loaded by the code before the run.

I hope it helped,

Regards,

Nicolas.
Chinalihaipeng
Beginner
Beginner
Posts: 6
Joined: Thu 15 Sep 2022 10:45
Country:
China (cn)
China

Re: A bug in Tracewin? i need help

Post by Chinalihaipeng »

Dear Nicolas

Thanks,This is very helpful!

Regards
Lihaipeng
Chinalihaipeng
Beginner
Beginner
Posts: 6
Joined: Thu 15 Sep 2022 10:45
Country:
China (cn)
China

Re: A bug in Tracewin? i need help

Post by Chinalihaipeng »

Dear Nicolas

I tried your method, but when I run it in batch mode, it seems that tracewin still cannot read the particle energy from the dst file. (The particle energy in each of my dst files is different)

But When I manually operate, when I click Import all beam parameters from file ,Kinetic Energy parameters can be loaded normally.
tracewin.jpg
tracewin.jpg (70.65 KiB) Viewed 15304 times
FranceNicolasChauvin
Global moderators
Global moderators
Posts: 8
Joined: Fri 2 Sep 2022 11:39
Country:
France (fr)
France

Re: A bug in Tracewin? i need help

Post by FranceNicolasChauvin »

Dear lihaipeng,

Indeed, I was able to reproduce this bug and it will be addressed by Didier as soon as possible.
In the meantime, you can use the following workaround:
1) You read the dst file you want to use and you compute the mean energy of the particles: MeanEnergyCalculated (see the 'GetMeanEnergy' function in the attached python script but I had to change the file extension to ".dat", please replace it by ".py")
2) You change the initial energy of your Tracewin simulation by adding in the command line your are using: "energy1=MeanEnergyCalculated'

Let me know if it works for you.

Regards,

Nicolas.
Attachments
Test_CommandLine_MeanEnergy.dat
(1.11 KiB) Downloaded 218 times
User avatar
FranceDidier
Administrator
Administrator
Posts: 976
Joined: Wed 26 Aug 2020 14:40
Country:
France (fr)
France

Re: A bug in Tracewin? i need help

Post by FranceDidier »

Dear lihaipeng,

In fact, this is not a bug, the behaviour was defined as such for practical reasons. Considering your remarks, I changed the behaviour of the code as follows:

If the dst_filex input is specified, the input beam parameters (number of particle, emittances, Twiss parameters, beam centroid, beam current and energy) are automatically extracted from the specified file and used for the calculation. The emittances and Twiss parameters cannot be modified by the corresponding input commands, but it is still possible for the beam centroid, current, energy, number of particles.

The corresponding new TraceWin version is available.

Regards,

Didier
Chinalihaipeng
Beginner
Beginner
Posts: 6
Joined: Thu 15 Sep 2022 10:45
Country:
China (cn)
China

Re: A bug in Tracewin? i need help

Post by Chinalihaipeng »

Dear Didier:

You said If the dst_filex input is specified, the input beam parameters (number of particle, emittances, Twiss parameters, beam centroid, beam current and energy) are automatically extracted from the specified file and used for the calculation。


But in fact, The number of particle, emittances , Twiss parameters, beam centroid and beam current are automatically extracted from the specified file (dst_file)and used for the calculation , but energy not. :shock:

Regards,

Lihaipeng
Chinalihaipeng
Beginner
Beginner
Posts: 6
Joined: Thu 15 Sep 2022 10:45
Country:
China (cn)
China

Re: A bug in Tracewin? i need help

Post by Chinalihaipeng »

Dear Nicolas

Thank you for your help, your method is very helpful!

In addition, I found that after each run, the normalized emittance in partran.out file and the normalized emittance extracted from the part_dtl1.dst file is a little different. For example, the normalized emittance(x direction,y direction ,z direction) in partran.out file are( 0.3730797, 0.3323209 ,0.358912), But the normalized emittance extracted from the part_dtl1.dst are (0.3724123 ,0.3317265, 0.3623556),

Why is it different and Which is the true value ?(Since I divide the whole structure into many parts for calculation, and The Deep Reinforcement Learning algorithm has low tolerance for errors)
tracewin.jpg
tracewin.jpg (236.67 KiB) Viewed 15286 times
My English is not very good. If you feel uncomfortable reading and don't understand anything, please let me know in time. I will ask for help and rewrite it.
Your help was very much appreciated!
User avatar
FranceDidier
Administrator
Administrator
Posts: 976
Joined: Wed 26 Aug 2020 14:40
Country:
France (fr)
France

Re: A bug in Tracewin? i need help

Post by FranceDidier »

Dear Lihaipeng,

About energy extraction:
I maintain that in the latest version of TraceWin (2.18.5.3) the energy used is the one extracted from the dst file when it is specified as an argument with "dst_file1=xxx. This is true unless you also have as argument "energy=xxxx", in which case this latter value will be used.

About Emittance values:
I don't observe any differences as you mention in your example between the part_dtl1.dst and partran.out. Now using the file "part_dtl1.dst" as an input file as you do is extremely ambiguous and dangerous because it is also the output file of the simulation and there the behaviour is difficult to understand. You have to rename "part_dtl1.dst" before injecting it as input.

Regards,

Didier
Chinalihaipeng
Beginner
Beginner
Posts: 6
Joined: Thu 15 Sep 2022 10:45
Country:
China (cn)
China

Re: A bug in Tracewin? i need help

Post by Chinalihaipeng »

Dear Didier

About energy extraction:
First of all, thank you very much for your help. My English is not good enough to understand your meaning in time. i 'm sorry. I will download the latest version in time.

About Emittance values:
Normalized emittance is really different. In my previous example, Emit Xx is 0.3730797 in partran1.out, but in the dst file,the Emit Xx is 0.3724123
发射度.jpg
发射度.jpg (210.27 KiB) Viewed 15279 times
Besides, I know exactly what I'm doing. When I use the Deep Reinforcement Learning algorithm to explore the structure of the beam transmission line (what structure should be put in front and which part should be put behind), I use part_ dtl1.dst file as input are very efficient and fast.
Post Reply