Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import sys
import yt
import numpy as np
import os
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be PEP8 compliant, the import os should be before the imports of numpy and yt.

Copy link
Member Author

@ax3l ax3l Dec 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting PEP8 style choice, because contrary to C/C++ includes, this has no real influence ^^
(besides global behavior, like where mpi4py is placed).
https://www.python.org/dev/peps/pep-0008/#imports

I think we need a bot for this, maybe we can add this to .pre-commit-config.yaml.

I would not change it in the current PR, since already existing sys imports are mostly off. Let's do style fixes to existing code in separate style-only/cleanup PRs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clarified on Slack: separate, we are looking for tools that can do it :)

Maybe autopep8 or flake8.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried autopep8 --select E401,E402 --in-place --aggressive --aggressive <filename> and all it does is sort alphabetically.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tool isort does the trick: #2686
https://github.com/PyCQA/isort

yt.funcs.mylog.setLevel(0)
sys.path.insert(1, '../../../../warpx/Regression/Checksum/')
import checksumAPI
Expand Down Expand Up @@ -82,5 +83,5 @@ def remove_rigid_lines(plotfile, nlines_if_rigid):

assert( error_rel < tolerance_rel )

test_name = filename[:-9] # Could also be os.path.split(os.getcwd())[1]
test_name = os.path.split(os.getcwd())[1]
checksumAPI.evaluate_checksum(test_name, filename)
3 changes: 2 additions & 1 deletion Examples/Modules/ionization/analysis_ionization.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import sys
import yt
import numpy as np
import os
yt.funcs.mylog.setLevel(0)
sys.path.insert(1, '../../../../warpx/Regression/Checksum/')
import checksumAPI
Expand Down Expand Up @@ -90,5 +91,5 @@

assert( error_rel < tolerance_rel )

test_name = filename[:-9] # Could also be os.path.split(os.getcwd())[1]
test_name = os.path.split(os.getcwd())[1]
checksumAPI.evaluate_checksum(test_name, filename)
3 changes: 2 additions & 1 deletion Examples/Modules/laser_injection/analysis_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
import os
from scipy.signal import hilbert
from mpl_toolkits.axes_grid1 import make_axes_locatable
sys.path.insert(1, '../../../../warpx/Regression/Checksum/')
Expand Down Expand Up @@ -198,7 +199,7 @@ def main():

check_laser(filename_end)

test_name = filename_end[:-9] # Could also be os.path.split(os.getcwd())[1]
test_name = os.path.split(os.getcwd())[1]
checksumAPI.evaluate_checksum(test_name, filename_end)

if __name__ == "__main__":
Expand Down
3 changes: 2 additions & 1 deletion Examples/Modules/laser_injection/analysis_laser.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
import os
sys.path.insert(1, '../../../../warpx/Regression/Checksum/')
import checksumAPI

Expand All @@ -25,5 +26,5 @@
plt.plot(t, s)
plt.savefig("laser_analysis.png")

test_name = fn[:-9] # Could also be os.path.split(os.getcwd())[1]
test_name = os.path.split(os.getcwd())[1]
checksumAPI.evaluate_checksum(test_name, fn)
3 changes: 1 addition & 2 deletions Examples/Modules/qed/breit_wheeler/analysis_opmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

# -*- coding: utf-8 -*-


import sys
import openpmd_api as io
#sys.path.insert(1, '../../../../warpx/Regression/Checksum/')
Expand Down Expand Up @@ -64,7 +63,7 @@ def main():

ac.check(dt, particle_data)

#test_name = filename_end[:-9] # Could also be os.path.split(os.getcwd())[1]
#test_name = os.path.split(os.getcwd())[1]
#checksumAPI.evaluate_checksum(test_name, filename_end)

if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions Examples/Modules/qed/breit_wheeler/analysis_yt.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

# -*- coding: utf-8 -*-


import os
import sys
import yt
sys.path.insert(1, '../../../../warpx/Regression/Checksum/')
Expand Down Expand Up @@ -55,7 +55,7 @@ def main():

ac.check(dt, particle_data)

test_name = filename_end[:-9] # Could also be os.path.split(os.getcwd())[1]
test_name = os.path.split(os.getcwd())[1]
checksumAPI.evaluate_checksum(test_name, filename_end)

if __name__ == "__main__":
Expand Down
3 changes: 2 additions & 1 deletion Examples/Modules/qed/quantum_synchrotron/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import yt
import numpy as np
import os
import sys
import scipy.special as spe
import scipy.integrate as integ
Expand Down Expand Up @@ -297,7 +298,7 @@ def check():

print("*************\n")

test_name = filename_end[:-9] # Could also be os.path.split(os.getcwd())[1]
test_name = os.path.split(os.getcwd())[1]
checksumAPI.evaluate_checksum(test_name, filename_end)

def main():
Expand Down
3 changes: 2 additions & 1 deletion Examples/Modules/qed/schwinger/analysis_schwinger.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import yt
import numpy as np
import os
import sys
import re
sys.path.insert(1, '../../../../warpx/Regression/Checksum/')
Expand Down Expand Up @@ -120,5 +121,5 @@ def do_analysis(Ex,Ey,Ez,Bx,By,Bz):

do_analysis(Ex_test, Ey_test, Ez_test, Bx_test, By_test, Bz_test)

test_name = filename[:-9] # Could also be os.path.split(os.getcwd())[1]
test_name = os.path.split(os.getcwd())[1]
checksumAPI.evaluate_checksum(test_name, filename)
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import matplotlib.pyplot as plt
import yt
import numpy as np
import os
import scipy.constants as scc
yt.funcs.mylog.setLevel(0)
sys.path.insert(1, '../../../../warpx/Regression/Checksum/')
Expand Down Expand Up @@ -84,5 +85,5 @@ def check(E, E_th, label):

check( Ex_array, Ex_th, 'Ex' )

test_name = filename[:-9] # Could also be os.path.split(os.getcwd())[1]
test_name = os.path.split(os.getcwd())[1]
checksumAPI.evaluate_checksum(test_name, filename, do_particles=False)
3 changes: 2 additions & 1 deletion Examples/Modules/resampling/analysis_leveling_thinning.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import yt
import numpy as np
import os
import sys
from scipy.special import erf
sys.path.insert(1, '../../../../warpx/Regression/Checksum/')
Expand Down Expand Up @@ -134,5 +135,5 @@
# Check that particles with weight higher than level weight are unaffected by resampling.
assert(np.all(w[-numparts_unaffected:] == w0[-numparts_unaffected:]))

test_name = fn_final[:-9] # Could also be os.path.split(os.getcwd())[1]
test_name = os.path.split(os.getcwd())[1]
checksumAPI.evaluate_checksum(test_name, fn_final)
3 changes: 2 additions & 1 deletion Examples/Modules/space_charge_initialization/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import matplotlib.pyplot as plt
import yt
import numpy as np
import os
import scipy.constants as scc
from scipy.special import gammainc
yt.funcs.mylog.setLevel(0)
Expand Down Expand Up @@ -106,5 +107,5 @@ def check(E, E_th, label):
if ds.dimensionality == 3:
check( Ez_array, Ez_th, 'Ez' )

test_name = filename[:-9] # Could also be os.path.split(os.getcwd())[1]
test_name = os.path.split(os.getcwd())[1]
checksumAPI.evaluate_checksum(test_name, filename, do_particles=0)
3 changes: 2 additions & 1 deletion Examples/Tests/Langmuir/analysis_langmuir_multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import yt
yt.funcs.mylog.setLevel(50)
import numpy as np
import os
from scipy.constants import e, m_e, epsilon_0, c
sys.path.insert(1, '../../../../warpx/Regression/Checksum/')
import checksumAPI
Expand Down Expand Up @@ -171,7 +172,7 @@ def get_theoretical_field( field, t ):
print("tolerance = {}".format(tolerance))
assert(error_rel < tolerance)

test_name = fn[:-9] # Could also be os.path.split(os.getcwd())[1]
test_name = os.path.split(os.getcwd())[1]

if re.search( 'single_precision', fn ):
checksumAPI.evaluate_checksum(test_name, fn, rtol=1.e-3)
Expand Down
3 changes: 2 additions & 1 deletion Examples/Tests/Langmuir/analysis_langmuir_multi_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import yt
yt.funcs.mylog.setLevel(50)
import numpy as np
import os
from scipy.constants import e, m_e, epsilon_0, c
sys.path.insert(1, '../../../../warpx/Regression/Checksum/')
import checksumAPI
Expand Down Expand Up @@ -118,5 +119,5 @@ def get_theoretical_field( field, t ):
print("tolerance = {}".format(tolerance))
assert( error_rel < tolerance )

test_name = fn[:-9] # Could also be os.path.split(os.getcwd())[1]
test_name = os.path.split(os.getcwd())[1]
checksumAPI.evaluate_checksum(test_name, fn)
3 changes: 2 additions & 1 deletion Examples/Tests/Langmuir/analysis_langmuir_multi_rz.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import yt
yt.funcs.mylog.setLevel(50)
import numpy as np
import os
from scipy.constants import e, m_e, epsilon_0, c
import post_processing_utils
sys.path.insert(1, '../../../../warpx/Regression/Checksum/')
Expand All @@ -30,7 +31,7 @@
# this will be the name of the plot file
fn = sys.argv[1]

test_name = fn[:-9] # Could also be os.path.split(os.getcwd())[1]
test_name = os.path.split(os.getcwd())[1]

# Parse test name and check if current correction (psatd.current_correction) is applied
current_correction = True if re.search('current_correction', fn) else False
Expand Down
3 changes: 2 additions & 1 deletion Examples/Tests/PEC/analysis_pec.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import yt
yt.funcs.mylog.setLevel(50)
import numpy as np
import os
sys.path.insert(1, '../../../../warpx/Regression/Checksum/')
import checksumAPI

Expand Down Expand Up @@ -75,7 +76,7 @@
assert( max_Ey_error_rel < tolerance_rel )
assert( min_Ey_error_rel < tolerance_rel )

test_name = fn[:-9] # Could also be os.path.split(os.getcwd())[1]
test_name = os.path.split(os.getcwd())[1]

if re.search( 'single_precision', fn ):
checksumAPI.evaluate_checksum(test_name, fn, rtol=1.e-3)
Expand Down
3 changes: 2 additions & 1 deletion Examples/Tests/PEC/analysis_pec_mr.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import yt
yt.funcs.mylog.setLevel(50)
import numpy as np
import os
sys.path.insert(1, '../../../../warpx/Regression/Checksum/')
import checksumAPI

Expand Down Expand Up @@ -75,7 +76,7 @@
assert( max_Ey_error_rel < tolerance_rel )
assert( min_Ey_error_rel < tolerance_rel )

test_name = fn[:-9] # Could also be os.path.split(os.getcwd())[1]
test_name = os.path.split(os.getcwd())[1]

if re.search( 'single_precision', fn ):
checksumAPI.evaluate_checksum(test_name, fn, rtol=1.e-3)
Expand Down
3 changes: 2 additions & 1 deletion Examples/Tests/PML/analysis_pml_ckc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import sys
import yt ; yt.funcs.mylog.setLevel(0)
import numpy as np
import os
import scipy.constants as scc
sys.path.insert(1, '../../../../warpx/Regression/Checksum/')
import checksumAPI
Expand Down Expand Up @@ -51,5 +52,5 @@

assert( error_rel < tolerance_rel )

test_name = filename[:-9] # Could also be os.path.split(os.getcwd())[1]
test_name = os.path.split(os.getcwd())[1]
checksumAPI.evaluate_checksum(test_name, filename)
3 changes: 2 additions & 1 deletion Examples/Tests/PML/analysis_pml_psatd.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import sys
import yt ; yt.funcs.mylog.setLevel(0)
import numpy as np
import os
import scipy.constants as scc
sys.path.insert(1, '../../../../warpx/Regression/Checksum/')
import checksumAPI
Expand Down Expand Up @@ -68,5 +69,5 @@
from analysis_default_restart import check_restart
check_restart(filename)

test_name = filename[:-9] # Could also be os.path.split(os.getcwd())[1]
test_name = os.path.split(os.getcwd())[1]
checksumAPI.evaluate_checksum(test_name, filename)
3 changes: 2 additions & 1 deletion Examples/Tests/PML/analysis_pml_yee.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import sys
import yt ; yt.funcs.mylog.setLevel(0)
import numpy as np
import os
import scipy.constants as scc
sys.path.insert(1, '../../../../warpx/Regression/Checksum/')
import checksumAPI
Expand Down Expand Up @@ -56,5 +57,5 @@
from analysis_default_restart import check_restart
check_restart(filename)

test_name = filename[:-9] # Could also be os.path.split(os.getcwd())[1]
test_name = os.path.split(os.getcwd())[1]
checksumAPI.evaluate_checksum(test_name, filename)
4 changes: 2 additions & 2 deletions Examples/Tests/RepellingParticles/analysis_repelling.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"""
import numpy as np
from scipy.constants import m_e, c, physical_constants
import sys, re
import sys, re, os
import yt
import glob
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -74,5 +74,5 @@
# Run checksum regression test
sys.path.insert(1, '../../../../warpx/Regression/Checksum/')
import checksumAPI
test_name = last_filename[:-9]
test_name = os.path.split(os.getcwd())[1]
checksumAPI.evaluate_checksum(test_name, last_filename)
3 changes: 2 additions & 1 deletion Examples/Tests/SilverMueller/analysis_silver_mueller.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import sys
import yt ; yt.funcs.mylog.setLevel(0)
import numpy as np
import os
sys.path.insert(1, '../../../../warpx/Regression/Checksum/')
import checksumAPI

Expand All @@ -31,5 +32,5 @@
assert np.all( abs(Ey) < max_reflection_amplitude )
assert np.all( abs(Ez) < max_reflection_amplitude )

test_name = filename[:-9] # Could also be os.path.split(os.getcwd())[1]
test_name = os.path.split(os.getcwd())[1]
checksumAPI.evaluate_checksum(test_name, filename)
3 changes: 2 additions & 1 deletion Examples/Tests/SingleParticle/analysis_bilinear_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import sys
import yt ; yt.funcs.mylog.setLevel(0)
import numpy as np
import os
from scipy import signal
sys.path.insert(1, '../../../../warpx/Regression/Checksum/')
import checksumAPI
Expand Down Expand Up @@ -58,5 +59,5 @@

assert( error_rel < tolerance_rel )

test_name = filename[:-9] # Could also be os.path.split(os.getcwd())[1]
test_name = os.path.split(os.getcwd())[1]
checksumAPI.evaluate_checksum(test_name, filename)
3 changes: 2 additions & 1 deletion Examples/Tests/boundaries/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import sys
import yt
import numpy as np
import os
from scipy.constants import m_e, c
yt.funcs.mylog.setLevel(0)
sys.path.insert(1, '../../../../warpx/Regression/Checksum/')
Expand Down Expand Up @@ -101,5 +102,5 @@ def do_periodic(x):
assert (np.all(np.abs((xx - xxa)/xx) < 1.e-15)), 'Reflecting particle position not correct'
assert (np.all(np.abs((zz - zza)/zz) < 1.e-15)), 'Periodic particle position not correct'

test_name = filename[:-9] # Could also be os.path.split(os.getcwd())[1]
test_name = os.path.split(os.getcwd())[1]
checksumAPI.evaluate_checksum(test_name, filename)
Loading