diff --git a/Examples/Physics_applications/capacitive_discharge/analysis_1d.py b/Examples/Physics_applications/capacitive_discharge/analysis_1d.py index 82d98c38210..48f7f98a4c0 100755 --- a/Examples/Physics_applications/capacitive_discharge/analysis_1d.py +++ b/Examples/Physics_applications/capacitive_discharge/analysis_1d.py @@ -2,8 +2,14 @@ # Copyright 2022 Modern Electron, David Grote +import os +import sys + import numpy as np +sys.path.append("../../../../warpx/Regression/Checksum/") +from checksumAPI import evaluate_checksum + # fmt: off ref_density = np.array([ 1.27989677e+14, 2.23601330e+14, 2.55400265e+14, 2.55664972e+14, @@ -45,3 +51,9 @@ density_data = np.load("ion_density_case_1.npy") print(repr(density_data)) assert np.allclose(density_data, ref_density) + +# compare checksums +evaluate_checksum( + test_name=os.path.split(os.getcwd())[1], + output_file=sys.argv[1], +) diff --git a/Examples/Physics_applications/capacitive_discharge/analysis_2d.py b/Examples/Physics_applications/capacitive_discharge/analysis_2d.py index e9e053cb6a4..74f40e557a5 100755 --- a/Examples/Physics_applications/capacitive_discharge/analysis_2d.py +++ b/Examples/Physics_applications/capacitive_discharge/analysis_2d.py @@ -11,12 +11,11 @@ import sys sys.path.append("../../../../warpx/Regression/Checksum/") +from checksumAPI import evaluate_checksum -import checksumAPI - -my_check = checksumAPI.evaluate_checksum( +# compare checksums +evaluate_checksum( test_name=os.path.split(os.getcwd())[1], output_file=sys.argv[1], rtol=5e-3, - do_particles=True, ) diff --git a/Examples/Physics_applications/capacitive_discharge/analysis_dsmc.py b/Examples/Physics_applications/capacitive_discharge/analysis_dsmc.py index 505521fc1ca..56d86980d72 100755 --- a/Examples/Physics_applications/capacitive_discharge/analysis_dsmc.py +++ b/Examples/Physics_applications/capacitive_discharge/analysis_dsmc.py @@ -8,14 +8,7 @@ import numpy as np sys.path.append("../../../../warpx/Regression/Checksum/") - -import checksumAPI - -# this will be the name of the plot file -fn = sys.argv[1] -test_name = os.path.split(os.getcwd())[1] - -my_check = checksumAPI.evaluate_checksum(test_name, fn, do_particles=True) +from checksumAPI import evaluate_checksum # fmt: off ref_density = np.array([ @@ -58,3 +51,9 @@ density_data = np.load("ion_density_case_1.npy") print(repr(density_data)) assert np.allclose(density_data, ref_density) + +# compare checksums +evaluate_checksum( + test_name=os.path.split(os.getcwd())[1], + output_file=sys.argv[1], +) diff --git a/Examples/Physics_applications/laser_acceleration/analysis_1d_fluid_boosted.py b/Examples/Physics_applications/laser_acceleration/analysis_1d_fluid_boosted.py index 934d298c6b7..b7b1d57566e 100755 --- a/Examples/Physics_applications/laser_acceleration/analysis_1d_fluid_boosted.py +++ b/Examples/Physics_applications/laser_acceleration/analysis_1d_fluid_boosted.py @@ -24,8 +24,8 @@ import numpy as np from scipy.constants import c, e, epsilon_0, m_e -sys.path.insert(1, "../../../../warpx/Regression/Checksum/") -import checksumAPI +sys.path.append("../../../../warpx/Regression/Checksum/") +from checksumAPI import evaluate_checksum # this will be the name of the plot file fn = sys.argv[1] @@ -188,5 +188,8 @@ def odefcn(phi, xi, kp, a0, c, tau, xi_0, lambda_laser): assert error_rel < tolerance_rel -test_name = os.path.split(os.getcwd())[1] -checksumAPI.evaluate_checksum(test_name, fn) +# compare checksums +evaluate_checksum( + test_name=os.path.split(os.getcwd())[1], + output_file=sys.argv[1], +) diff --git a/Examples/analysis_default_openpmd_regression.py b/Examples/analysis_default_openpmd_regression.py index 03a0f1ede1f..6f38693f820 100755 --- a/Examples/analysis_default_openpmd_regression.py +++ b/Examples/analysis_default_openpmd_regression.py @@ -5,16 +5,22 @@ import sys sys.path.insert(1, "../../../../warpx/Regression/Checksum/") -import checksumAPI +from checksumAPI import evaluate_checksum -# this will be the name of the plot file -fn = sys.argv[1] - -# Get name of the test test_name = os.path.split(os.getcwd())[1] +output_file = sys.argv[1] # Run checksum regression test -if re.search("single_precision", fn): - checksumAPI.evaluate_checksum(test_name, fn, output_format="openpmd", rtol=2.0e-6) +if re.search("single_precision", output_file): + evaluate_checksum( + test_name=test_name, + output_file=output_file, + output_format="openpmd", + rtol=2e-6, + ) else: - checksumAPI.evaluate_checksum(test_name, fn, output_format="openpmd") + evaluate_checksum( + test_name=test_name, + output_file=output_file, + output_format="openpmd", + ) diff --git a/Examples/analysis_default_regression.py b/Examples/analysis_default_regression.py index 519bbeeea64..7c02f6904b2 100755 --- a/Examples/analysis_default_regression.py +++ b/Examples/analysis_default_regression.py @@ -5,17 +5,21 @@ import sys sys.path.insert(1, "../../../../warpx/Regression/Checksum/") -import checksumAPI +from checksumAPI import evaluate_checksum -# this will be the name of the plot file -fn = sys.argv[1] - -# Get name of the test test_name = os.path.split(os.getcwd())[1] +output_file = sys.argv[1] # Run checksum regression test -if re.search("single_precision", fn): - checksumAPI.evaluate_checksum(test_name, fn, rtol=2.0e-6) +if re.search("single_precision", output_file): + evaluate_checksum( + test_name=test_name, + output_file=output_file, + rtol=2e-6, + ) else: # using default relative tolerance - checksumAPI.evaluate_checksum(test_name, fn) + evaluate_checksum( + test_name=test_name, + output_file=output_file, + ) diff --git a/Examples/analysis_default_restart.py b/Examples/analysis_default_restart.py index 55bab253dbc..c019a0b5945 100755 --- a/Examples/analysis_default_restart.py +++ b/Examples/analysis_default_restart.py @@ -7,7 +7,7 @@ import yt sys.path.insert(1, "../../../../warpx/Regression/Checksum/") -import checksumAPI +from checksumAPI import evaluate_checksum def check_restart(filename, tolerance=1e-12): @@ -67,12 +67,17 @@ def check_restart(filename, tolerance=1e-12): print() -filename = sys.argv[1] +# test name (for checksums, remove "_restart") and output file name +test_name = os.path.split(os.getcwd())[1] +test_name = test_name.replace("_restart", "") +output_file = sys.argv[1] # compare restart results against original results -check_restart(filename) +check_restart(output_file) # compare restart checksums against original checksums -testname = os.path.split(os.getcwd())[1] -testname = testname.replace("_restart", "") -checksumAPI.evaluate_checksum(testname, filename, rtol=1e-12) +evaluate_checksum( + test_name=test_name, + output_file=output_file, + rtol=1e-12, +) diff --git a/Regression/Checksum/benchmarks_json/test_1d_background_mcc_picmi.json b/Regression/Checksum/benchmarks_json/test_1d_background_mcc_picmi.json new file mode 100644 index 00000000000..029294deb66 --- /dev/null +++ b/Regression/Checksum/benchmarks_json/test_1d_background_mcc_picmi.json @@ -0,0 +1,20 @@ +{ + "lev=0": { + "rho_electrons": 0.0044328572492614605, + "rho_he_ions": 0.005198609403474849 + }, + "electrons": { + "particle_momentum_x": 3.5020450942268976e-20, + "particle_momentum_y": 3.5342700024993965e-20, + "particle_momentum_z": 1.2596017960675146e-19, + "particle_position_x": 2139.5967568101983, + "particle_weight": 14577210937500.002 + }, + "he_ions": { + "particle_momentum_x": 2.770046913680294e-19, + "particle_momentum_y": 2.755651798947783e-19, + "particle_momentum_z": 3.619494241595636e-19, + "particle_position_x": 2200.218124999781, + "particle_weight": 17184714843750.002 + } +} diff --git a/Regression/Checksum/checksum.py b/Regression/Checksum/checksum.py index 4133d882a41..b2f327e36e3 100644 --- a/Regression/Checksum/checksum.py +++ b/Regression/Checksum/checksum.py @@ -243,9 +243,8 @@ def evaluate(self, rtol=1.0e-9, atol=1.0e-40): ) print("Benchmark: %s" % ref_benchmark.data.keys()) print("Test file: %s" % self.data.keys()) - print("\n----------------\nNew file for " + self.test_name + ":") + print(f"\nNew checksums file {self.test_name}.json:") print(json.dumps(self.data, indent=2)) - print("----------------") sys.exit(1) # Dictionaries have same inner keys (field and particle quantities)? @@ -261,9 +260,8 @@ def evaluate(self, rtol=1.0e-9, atol=1.0e-40): % (key1, ref_benchmark.data[key1].keys()) ) print("Test file inner keys in %s: %s" % (key1, self.data[key1].keys())) - print("\n----------------\nNew file for " + self.test_name + ":") + print(f"\nNew checksums file {self.test_name}.json:") print(json.dumps(self.data, indent=2)) - print("----------------") sys.exit(1) # Dictionaries have same values? @@ -298,7 +296,6 @@ def evaluate(self, rtol=1.0e-9, atol=1.0e-40): rel_err = abs_err / np.abs(x) print("Relative error: {:.2e}".format(rel_err)) if checksums_differ: - print("\n----------------\nNew file for " + self.test_name + ":") + print(f"\nNew checksums file {self.test_name}.json:") print(json.dumps(self.data, indent=2)) - print("----------------") sys.exit(1)