Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jumps in output data of plugins (in moving window simulations) #2703

Closed
steindev opened this issue Sep 18, 2018 · 13 comments
Closed

Jumps in output data of plugins (in moving window simulations) #2703

steindev opened this issue Sep 18, 2018 · 13 comments
Labels
component: plugin in PIConGPU plugin duplicate duplicate issue or pull-request (link main issue!) question

Comments

@steindev
Copy link
Member

steindev commented Sep 18, 2018

I recognized in two different kind of simulations with two different plugins jumps in output data of longitudinal (y) quantities. I suspect these are related to calculations of output data within the moving window.

The two cases are:

Resetting of electron bunch longitudinal position in phase space output of LWFA sims

  • picongpu version: 0.4.0rc2
  • plugin: e_phaseSpace y-py

The electron position in y-direction (laser propagation and moving window direction) is repeatedly reset at a period of about twice the simulation box size in y-direction. Here, electron position resets take place every 3k to 4k (mostly) time steps. The simulation box is 2304 cells in y direction, with 8 gpus along this direction. The ratio of y cell size to time step is DY / ( cspeed * DT ) = 1.5275. That is, it seems like a reset occurs when the moving window moved once over the simulation box, i.e. every n_reset = 2304 * DY / ( cspeed * DT ) = 2304 * 1.5275 = 3519 time steps. This value fits to the observed reset period.
phasespace_ypy

Increase in longitudinal E- and B-field energy in field energy plugin

  • picongpu version: 0.3.0
  • plugin: fields_energy

The longitudinal field energy jumps with a period of 20kDT. This time the simulation volume is 8192 cells in y-direction distributed over 16 gpus. The ratio of y cell size to time step is DY / ( cspeed * DT ) = 0.99976.
image
Zoom in to Ey data. Note that the sampling rate is high compared to period length of jumps.
image
As this second appearance of jumps does not really match the first one I will start a primitive bunch acceleration with piconpu-0.4.0 and see how the fields develop and if this behavior is reproduced.

Still it is funny that these jumps appear at a time the window needs to pass about twice the simbox.

@ax3l ax3l added bug a bug in the project's code component: plugin in PIConGPU plugin affects latest release a bug that affects the latest stable release labels Sep 18, 2018
@psychocoderHPC
Copy link
Member

@steindev I checked the phase space plugin and it looks like sliding window is not supported from the plugin.

@ax3l
Copy link
Member

ax3l commented Sep 24, 2018

Afair, the plugin dumps the whole box but also adds the meta information to slice out the window accordingly. Our Python plugin should do this reliably, so users don't need to fiddle with the HDF5 attributes and the cutting: https://picongpu.readthedocs.io/en/0.4.0-rc2/usage/plugins/phaseSpace.html#analysis

@PrometheusPi
Copy link
Member

offline discussion with @psychocoderHPC:
The field energy plugin provides an output every 1k time step. The sliding occurs every 8192 (#cells) / 16 (# y-GPUs) = 512 ~0.5k time steps. Assuming the plugin wrote out the field energy just right before a GPU slide. The total field energy is thus at a (local) maximum. For the next plugin output, the energy is slightly lower (because 100ß%512 until the plugin output reaches a point, right before sliding, where the energy is at a local minimum. The next output contains a rapid increase in energy.

The effect seen is thus a aliasing effect due to the low sampling rate of the field energy plugin compared to the sliding rate.

A visualization of this effect is shown below.
The field energy is given by E(t) = 1.0 + sin(t/10000) + 0.5 t%512.
The energy thus fluctuates with the sliding every 512 time steps by 0.5 arb.u..

The result is a rapid increase and a slow decrease as seen by @steindev:

grafik

@PrometheusPi
Copy link
Member

PrometheusPi commented Sep 24, 2018

The effect can be resolved if the field energy plugin output occurs more frequently (at least every ~200 time steps (~512/2 = Nyquist sampling rate)) or can be avoided if the plugin only works on the moving window.

@PrometheusPi
Copy link
Member

Or with an energy increase:

N = 100000
delta_plugin = 1000
delta_slide = 512

t = np.arange(N)

E = 1.0 + np.exp(t/50000.) + 0.5 * (t%delta_slide)/delta_slide

grafik

@ax3l
Copy link
Member

ax3l commented Sep 24, 2018

Yep, many plugins need that filter still: #89 and it is now easy to implement with our filters: #2131 #2582 (note: not as a user option; I mean default-filtered)

Nevertheless, the phase space plugin has this implemented in simple post-processing. @steindev Can you please show the Python snippet used for PS visualization? I want to see if there is a bug hidden or if this is just not processing the data correctly.

@ax3l ax3l added the duplicate duplicate issue or pull-request (link main issue!) label Sep 24, 2018
@PrometheusPi
Copy link
Member

PrometheusPi commented Sep 24, 2018

@steindev or for comparison a "forward (green) and backward (orange) in time propagating" aliasing:
grafik

@ax3l ax3l removed affects latest release a bug that affects the latest stable release bug a bug in the project's code labels Sep 24, 2018
@ax3l ax3l added this to the Future milestone Sep 24, 2018
@steindev
Copy link
Member Author

@ax3l: I used my own script for visualization of the phase space data:

tstep = 130000
ps = "ypy"

## Read data
f = h5py.File(path + "phaseSpace/PhaseSpace_e_all_%s_%i.h5"%(ps,tstep), "r")

# Unit data
Dr_SI = f["/data/%i/%s"%(tstep,ps)].attrs['dr_unit'] # position unit
Dp_SI = f["/data/%i/%s"%(tstep,ps)].attrs['p_unit'] / m_e / cspeed # momentum unit in gamma*beta

# Grid data 
p_min = f["/data/%i/%s"%(tstep,ps)].attrs['p_min'] * Dp_SI 
p_max = f["/data/%i/%s"%(tstep,ps)].attrs['p_max'] * Dp_SI 
N_r, N_p = f["/data/%i/%s"%(tstep,ps)].shape

# Data
rp = f["/data/%i/%s"%(tstep,ps)][...]

f.close()

## Plot data
figure(figsize=(8,6))
imshow(abs(rp).T, cmap = mpl.cm.cubehelix_r#, vmax = 2, vmin = 0
       , origin='lower', interpolation='none', aspect='auto'
       , extent=(0, N_r, p_min, p_max)
       , norm = matplotlib.colors.LogNorm())

# Plot setup
colorbar()
grid()
xticks(arange(0,N_r,200))
xlabel(r"position [cells]")
ylabel(r"momentum [$\gamma\beta_{komp}$]")
title(r"%s space @ %ikDt"%(ps,tstep*1.e-3))

show()

That is, I plot the complete data set stored in the phase space hdf5 file as is shown in the phaseSpace plugin docs. If there is a script for analysis provided by picongpu, I would wish there is a link or comment about it on this page. Further, the documentation page could list under known limitations the observed behavior and/or link to #89.

@ax3l
Copy link
Member

ax3l commented Sep 24, 2018

Ah, that's the reason it jumps. Older versions (dev between 0.3.X and 0.4 - lol) of PIConGPU had an explanation on how to manually crop & visualize the phase-space output. Check this out: https://github.com/ComputationalRadiationPhysics/picongpu/blob/60506f84c0268ec8cd2fb92d1ce896fca02116c5/docs/source/usage/plugins/phaseSpace.rst#spatial-offset

But you should not do this anymore. Use the new python lib that you can add to your PYTHONPATH and which is in the latest manual. It will remove these nasty details from your sight :)

documentation page could list under known limitations the observed behavior

No, it now documents how to read the data. That's not a limitation for users: you are currently hacking the recommended workflow ;-) I don't recommend to anyone to parse HDF5 files by hand, it's verbose and error-prune.

@ax3l
Copy link
Member

ax3l commented Sep 24, 2018

If you are in the mood to be extra-lazy (tm), which I can only recommend to be, then you could also replace the documented

from picongpu.plugins.phase_space import PhaseSpace

with an even lazier

from picongpu.plugins.plot_mpl.phase_space_visualizer import Visualizer

That object has the same arguments as the data reader API, but generates you immediately an MPL plot :D

fig, ax = plt.subplots(1, 1)
Visualizer(path).visualize(ax, iteration=iteration, species=species,
species_filter=filtr, ps=momentum)
plt.show()

I am recommending you the undocumented feature, since you seem to skip the recommended, documented ones ;-p

@steindev
Copy link
Member Author

My apologies. I remember seeing the script which loads the python lib. I simply did not know where to find it... :-(
Simply loading the hdf5 data as I have done before seemed faster than searching for the lib. I think by doing so I already qualified for lazy (tm), at least.

@ax3l
Copy link
Member

ax3l commented Sep 24, 2018

Nothing to be sorry for, we just moved all the plugin docs from the wiki to the mainline docs during the last year. They were hard to find. Everything is more shiny now! ✨

But really, switch to the new Python imports. It's just one line in your picongpu.profile (or postprocessing.profile or whatever you use for jupyter) but will declutter your analysis notebooks so you can focus on the relevant things :)

@ax3l ax3l closed this as completed Sep 24, 2018
@ax3l
Copy link
Member

ax3l commented Sep 24, 2018

(Feel free to comment further if I missed something. The other issue is a duplicate of the energy plugin not yet implementing a moving window filter, cross-linked above.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: plugin in PIConGPU plugin duplicate duplicate issue or pull-request (link main issue!) question
Projects
None yet
Development

No branches or pull requests

4 participants