Picmi integration
Adds experimental PICMI integration.
Please refer to the (automatically built) docs for details.
Breaks: Moved existing python modules.
Python 3.9 is required (is checked on include)
Does assigning PRs work now? It used to cause CI issues iirc (and assigning to review worked fine)
We are checking all python code with flake8. https://gitlab.com/hzdr/crp/picongpu/-/jobs/2396283842#L2142
It looks like the code must be reformated to pass the CI.
We are checking all python code with
flake8. https://gitlab.com/hzdr/crp/picongpu/-/jobs/2396283842#L2142 It looks like the code must be reformated to pass the CI.
This is not a formatting issue, this is an issue with pyflakes.
The alternative is naming all (test-) classes explicitly, which makes sense for modules to be reused (see the __init__.pys in the actual python modules), however for the tests it is just boilerplate.
There is a discussion to be had if the usage of `from . import *' is valid.
The issue lies in pyflakes: All these files contain the # flake8: noqa comment to indicate that checks should be skipped in the __init__.pys of the tests. flake8 actually correctly ignores these files (see CI, flake8 has no output), but AFAIK pyflakes is not able to skip checks for entire files after reading a comment.
@sbastrakov Sorry - I actually wanted to request your reviews and not assign it to you. Did it still work (again)?
@sbastrakov Sorry - I actually wanted to request your reviews and not assign it to you. Did it still work (again)?
I changed to requesting reviews, and included a few more people. @PrometheusPi: You have a student working w/ this, so you should be the first who is not involved in the development but sees issues
@BrianMarre You have the deepest insight into the code. Pls review.
@BeyondEspresso You wanted to have it in, pls test functionality. :stuck_out_tongue:
I will do my best, to do a review in a timely manner.
Installing the documentation did not work out-of-the box. Please add the dependencies:
typeguard
sympy
chevron
jsonschema
picmistandard
openpmd-api
imageio
to requirements.txt, so that setting up a new virtual python environment for building the docs is straightforward.
Unexpected usage behavior:
sim.write_input_file(OUTDIR) cannot be excexuted twice without re-doing all PICMI initializations before.
Throws error:
~/src/picongpu/lib/python/picongpu/picmi/species.py in __maybe_apply_particle_type(self)
103
104 # particle type is set -> retrieve mass & charge
--> 105 assert self.charge is None, \
106 "charge is specify implicitly via particle type, " \
107 "do NOT set charge explictly"
AssertionError: charge is specify implicitly via particle type, do NOT set charge explictly
Reproducer:
#First notebook cell
from picongpu import picmi
import shutil
import math
#Second notebook cell
cst = picmi.constants
laser_injection_loc = 0.0e-6
simulationBox = [3.40992e-5, 9.07264e-5, 2.1312e-6]
grid = picmi.Cartesian3DGrid(number_of_cells=[192, 2048, 12],
lower_bound=[0, 0, 0],
upper_bound=simulationBox,
lower_boundary_conditions=["open", "open", "open"],
upper_boundary_conditions=["open", "open", "open"])
solver = picmi.ElectromagneticSolver(method="Yee", grid=grid)
profile = picmi.UniformDistribution(
density=1e20,
# most probable E_kin = 5 mc^2
# approx. 9000 keV for electrons
# must be equal for all three components
rms_velocity=[4.18 * picmi.constants.c] * 3,
)
electron = picmi.Species(
name="e",
# openPMD particle type
particle_type="electron",
initial_distribution=profile,
)
laser = picmi.GaussianLaser(0.8e-6, 5.0e-6 / 1.17741, 5.0e-15,
a0=4.5,
centroid_position = [simulationBox[0]/2, laser_injection_loc, \
simulationBox[2]/2 ],
propagation_direction=[0, 1, 0],
focal_position=[ simulationBox[0]/2, simulationBox[1]/4 , simulationBox[2]/2 ],
polarization_direction=[1.0, 0.0, 0.0],
picongpu_laguerre_modes=[0.8,0.2,0.03],
picongpu_laguerre_phases=[0.0,math.pi/2,0.0]
)
sim = picmi.Simulation(time_step_size=1.39e-16, max_steps=int(2048), solver=solver)
sim.add_laser(laser, None)
layout = picmi.PseudoRandomLayout(n_macroparticles_per_cell=25)
sim.add_species(electron, layout)
#Third notebook cell (excecuted twice)
# sim initialized ...
OUTDIR="<my simulation output directory>"
shutil.rmtree(OUTDIR) # comment out in first execution
sim.write_input_file(OUTDIR)
Installing the documentation did not work out-of-the box. Please add the dependencies:
typeguard sympy chevron jsonschema picmistandard openpmd-api imageioto
requirements.txt, so that setting up a new virtual python environment for building the docs is straightforward.
We already have a $PIC_SRC/lib/python/piconpgu/requirements.txt
typeguard >= 2.12
sympy >= 1.9
chevron >= 0.13.1
jsonschema >= 4.4.0
scipy >= 1.7.1
picmistandard >= 0.0.18
-r extra/requirements.txt
which is also linked in the overall requirements.txt : -r lib/python/picongpu/requirements.txt, which I have used and which did work, using pip.
I am therefore not sure whether you simply missed it or something was not working as intended, or whether it was uncomfortable to use.
P.S.: We do not need to add openPMD-api as requirement since PyPIConGPU is supposed to be run in a picongpu environment we already included openPMD-api by default (Discussion point: piconpgu does not require openpmd-api to run, so it could be considered optional)
Unexpected usage behavior:
sim.write_input_file(OUTDIR)cannot be excexuted twice without re-doing all PICMI initializations before. Throws error:~/src/picongpu/lib/python/picongpu/picmi/species.py in __maybe_apply_particle_type(self) 103 104 # particle type is set -> retrieve mass & charge --> 105 assert self.charge is None, \ 106 "charge is specify implicitly via particle type, " \ 107 "do NOT set charge explictly" AssertionError: charge is specify implicitly via particle type, do NOT set charge explictlyReproducer:
#First notebook cell from picongpu import picmi import shutil import math #Second notebook cell cst = picmi.constants laser_injection_loc = 0.0e-6 simulationBox = [3.40992e-5, 9.07264e-5, 2.1312e-6] grid = picmi.Cartesian3DGrid(number_of_cells=[192, 2048, 12], lower_bound=[0, 0, 0], upper_bound=simulationBox, lower_boundary_conditions=["open", "open", "open"], upper_boundary_conditions=["open", "open", "open"]) solver = picmi.ElectromagneticSolver(method="Yee", grid=grid) profile = picmi.UniformDistribution( density=1e20, # most probable E_kin = 5 mc^2 # approx. 9000 keV for electrons # must be equal for all three components rms_velocity=[4.18 * picmi.constants.c] * 3, ) electron = picmi.Species( name="e", # openPMD particle type particle_type="electron", initial_distribution=profile, ) laser = picmi.GaussianLaser(0.8e-6, 5.0e-6 / 1.17741, 5.0e-15, a0=4.5, centroid_position = [simulationBox[0]/2, laser_injection_loc, \ simulationBox[2]/2 ], propagation_direction=[0, 1, 0], focal_position=[ simulationBox[0]/2, simulationBox[1]/4 , simulationBox[2]/2 ], polarization_direction=[1.0, 0.0, 0.0], picongpu_laguerre_modes=[0.8,0.2,0.03], picongpu_laguerre_phases=[0.0,math.pi/2,0.0] ) sim = picmi.Simulation(time_step_size=1.39e-16, max_steps=int(2048), solver=solver) sim.add_laser(laser, None) layout = picmi.PseudoRandomLayout(n_macroparticles_per_cell=25) sim.add_species(electron, layout) #Third notebook cell (excecuted twice) # sim initialized ... OUTDIR="<my simulation output directory>" shutil.rmtree(OUTDIR) # comment out in first execution sim.write_input_file(OUTDIR)
Will have a look at it, but not today, earliest tomorrow, but probably thursday.
@BrianMarre I have installed the documentation as described by the documentation using the $PIC_SRC/docs/picongpu-docs.env.yml for an anaconda-environment, which refers to $PIC_SRC/docs/requirements.txt, but not $PIC_SRC/lib/python/piconpgu/requirements.txt.
The openPMD-dependency was required when building the documentation.
@BrianMarre I have installed the documentation as described by the documentation using the
$PIC_SRC/docs/picongpu-docs.env.ymlfor an anaconda-environment, which refers to$PIC_SRC/docs/requirements.txt, but not$PIC_SRC/lib/python/piconpgu/requirements.txt.The openPMD-dependency was required when building the documentation.
Ah, you were talking about a separate doc requirements.txt, that makes more sense. Probably simply copy and paste?
@BrianMarre I suggest to add only the necessary dependencies to the documentation-requirements to decrease the potential for compatibility issues when setting up the python-environment. Hence add:
typeguard
sympy
chevron
jsonschema
picmistandard
openpmd-api
imageio
~10%(by file count) done with review [24.06.2022]: 35% [27.06.2022]: 41%
whats is the status of this PR?
in addition, I have a private branch that resolves the merge conflict
but we still have to decide what to do about the pyflake warnings, Note: has been resolved and implemented
for future reference, this pull request is no longer current
@BrianMarre so shall we close it? It will still be available on github but "it is no longer current" would be more clear.
Yes