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

Improve benchmark scripts #4753

Merged
merged 1 commit into from
Jul 18, 2023
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
22 changes: 14 additions & 8 deletions maintainer/benchmarks/lb.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
"particles (range: [0.01-0.74], default: 0.50)")
parser.add_argument("--single_precision", action="store_true", required=False,
help="Using single-precision floating point accuracy")
parser.add_argument("--gpu", action=argparse.BooleanOptionalAction,
default=False, required=False, help="Use GPU implementation")
parser.add_argument("--output", metavar="FILEPATH", action="store",
type=str, required=False, default="benchmarks.csv",
help="Output file (default: benchmarks.csv)")
Expand All @@ -58,6 +60,8 @@
"Argument box_l requires particles_per_core=0"

required_features = ["LENNARD_JONES", "WALBERLA"]
if args.gpu:
required_features.append("CUDA")
espressomd.assert_features(required_features)

# make simulation deterministic
Expand Down Expand Up @@ -103,14 +107,12 @@
#############################################################
system.time_step = 0.01
system.cell_system.skin = 0.5
system.thermostat.turn_off()

# Interaction setup
# Interaction and particle setup
#############################################################
system.non_bonded_inter[0, 0].lennard_jones.set_params(
epsilon=lj_eps, sigma=lj_sig, cutoff=lj_cut, shift="auto")

if n_part:
system.non_bonded_inter[0, 0].lennard_jones.set_params(
epsilon=lj_eps, sigma=lj_sig, cutoff=lj_cut, shift="auto")
system.part.add(pos=np.random.random((n_part, 3)) * system.box_l)
benchmarks.minimize(system, n_part / 2.)
system.integrator.set_vv()
Expand All @@ -129,9 +131,13 @@
system.integrator.run(500)
system.thermostat.turn_off()

lbf = espressomd.lb.LBFluidWalberla(agrid=agrid, tau=system.time_step,
density=1., kinematic_viscosity=1.,
single_precision=args.single_precision)
# LB fluid setup
#############################################################
lb_class = espressomd.lb.LBFluidWalberla
if args.gpu:
lb_class = espressomd.lb.LBFluidWalberlaGPU
lbf = lb_class(agrid=agrid, tau=system.time_step, kinematic_viscosity=1.,
density=1., single_precision=args.single_precision)
system.actors.add(lbf)


Expand Down
4 changes: 1 addition & 3 deletions maintainer/benchmarks/lj.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@

# System parameters
#############################################################

n_proc = system.cell_system.get_state()['n_nodes']
n_proc = system.cell_system.get_state()["n_nodes"]
n_part = n_proc * args.particles_per_core
# volume of N spheres with radius r: N * (4/3*pi*r^3)
box_l = (n_part * 4. / 3. * np.pi * (lj_sig / 2.)**3
Expand All @@ -88,7 +87,6 @@
#############################################################
system.time_step = 0.01
system.cell_system.skin = 0.5
system.thermostat.turn_off()

# Interaction setup
#############################################################
Expand Down
34 changes: 19 additions & 15 deletions maintainer/benchmarks/p3m.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@
help="Fraction of the simulation box volume occupied by "
"particles (range: [0.01-0.74], default: 0.25)")
parser.add_argument("--prefactor", metavar="PREFACTOR", action="store",
type=float, default=4., required=False,
type=float, default=1., required=False,
help="P3M prefactor (default: 4)")
parser.add_argument("--gpu", action=argparse.BooleanOptionalAction,
default=False, required=False, help="Use GPU implementation")
group = parser.add_mutually_exclusive_group()
group.add_argument("--output", metavar="FILEPATH", action="store",
type=str, required=False, default="benchmarks.csv",
Expand All @@ -55,7 +57,9 @@
assert measurement_steps >= 50, \
f"{measurement_steps} steps per tick are too short"

required_features = ["P3M", "LENNARD_JONES", "MASS"]
required_features = ["P3M", "LENNARD_JONES"]
if args.gpu:
required_features.append("CUDA")
espressomd.assert_features(required_features)

# make simulation deterministic
Expand All @@ -67,7 +71,6 @@

# Interaction parameters (Lennard-Jones, Coulomb)
#############################################################

species = ["anion", "cation"]
types = {"anion": 0, "cation": 0}
charges = {"anion": -1.0, "cation": 1.0}
Expand All @@ -76,12 +79,10 @@
WCA_cut = 2.**(1. / 6.)
lj_cuts = {"anion": WCA_cut * lj_sigmas["anion"],
"cation": WCA_cut * lj_sigmas["cation"]}
masses = {"anion": 1.0, "cation": 1.0}

# System parameters
#############################################################

n_proc = system.cell_system.get_state()['n_nodes']
n_proc = system.cell_system.get_state()["n_nodes"]
n_part = n_proc * args.particles_per_core
# volume of N spheres with radius r: N * (4/3*pi*r^3)
lj_sig = (lj_sigmas["cation"] + lj_sigmas["anion"]) / 2
Expand All @@ -96,12 +97,10 @@
# Integration parameters
#############################################################
system.time_step = 0.01
system.cell_system.skin = .4
system.thermostat.turn_off()
system.cell_system.skin = 0.5

# Interaction setup
#############################################################

for i in range(len(species)):
ion1 = species[i]
for j in range(i, len(species)):
Expand All @@ -115,34 +114,39 @@

# Particle setup
#############################################################

pid = 0
for i in range(0, n_part, len(species)):
for t in species:
system.part.add(pos=np.random.random(3) * system.box_l,
q=charges[t], type=types[t], mass=masses[t])
id=pid, q=charges[t], type=types[t])
pid += 1

# Warmup Integration
#############################################################

# warmup
benchmarks.minimize(system, n_part / 10.)
benchmarks.minimize(system, n_part / 2.)

system.integrator.set_vv()
system.thermostat.set_langevin(kT=1.0, gamma=1.0, seed=42)

p3m_class = espressomd.electrostatics.P3M
if args.gpu:
p3m_class = espressomd.electrostatics.P3MGPU

# tuning and equilibration
min_skin = 0.2
max_skin = 1.6
p3m_params = {'prefactor': args.prefactor, 'accuracy': 1e-4}
print("Equilibration")
p3m_params = {"prefactor": args.prefactor, "accuracy": 1e-3}
p3m = p3m_class(**p3m_params)
print("Quick equilibration")
system.integrator.run(min(3 * measurement_steps, 1000))
print("Tune skin: {:.3f}".format(system.cell_system.tune_skin(
min_skin=min_skin, max_skin=max_skin, tol=0.05, int_steps=100,
adjust_max_skin=True)))
print("Equilibration")
system.integrator.run(min(3 * measurement_steps, 3000))
print("Tune p3m")
p3m = espressomd.electrostatics.P3M(**p3m_params)
system.electrostatics.solver = p3m
print("Equilibration")
system.integrator.run(min(3 * measurement_steps, 3000))
Expand Down
6 changes: 4 additions & 2 deletions testsuite/scripts/benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ add_custom_target(
${CMAKE_SOURCE_DIR}/maintainer/benchmarks ${BENCHMARKS_DIR})

benchmark_test(FILE test_lj.py)
benchmark_test(FILE test_lb.py)
benchmark_test(FILE test_p3m.py)
benchmark_test(FILE test_lb.py SUFFIX cpu)
# benchmark_test(FILE test_lb.py SUFFIX gpu LABELS "gpu") # TODO WALBERLA
benchmark_test(FILE test_p3m.py SUFFIX cpu)
benchmark_test(FILE test_p3m.py SUFFIX gpu LABELS "gpu")
benchmark_test(FILE test_ferrofluid.py)
benchmark_test(FILE test_mc_acid_base_reservoir.py)

Expand Down
2 changes: 2 additions & 0 deletions testsuite/scripts/benchmarks/test_ferrofluid.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#
# Copyright (C) 2019-2022 The ESPResSo project
#
# This file is part of ESPResSo.
Expand All @@ -14,6 +15,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

import unittest as ut
import importlib_wrapper
Expand Down
8 changes: 6 additions & 2 deletions testsuite/scripts/benchmarks/test_lb.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#
# Copyright (C) 2019-2022 The ESPResSo project
#
# This file is part of ESPResSo.
Expand All @@ -14,6 +15,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

import unittest as ut
import importlib_wrapper
Expand All @@ -22,9 +24,11 @@
# make simulation deterministic
np.random.seed(42)

gpu = "gpu" in "@TEST_LABELS@".split(";")
cmd_arguments = ["--particles_per_core", "80", "--gpu" if gpu else "--no-gpu"]
benchmark, skipIfMissingFeatures = importlib_wrapper.configure_and_import(
"@BENCHMARKS_DIR@/lb.py", cmd_arguments=["--particles_per_core", "80"],
measurement_steps=200, n_iterations=2)
"@BENCHMARKS_DIR@/lb.py", gpu=gpu, measurement_steps=200, n_iterations=2,
cmd_arguments=cmd_arguments, script_suffix="@TEST_SUFFIX@")


@skipIfMissingFeatures
Expand Down
2 changes: 2 additions & 0 deletions testsuite/scripts/benchmarks/test_lj.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#
# Copyright (C) 2019-2022 The ESPResSo project
#
# This file is part of ESPResSo.
Expand All @@ -14,6 +15,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

import unittest as ut
import importlib_wrapper
Expand Down
9 changes: 7 additions & 2 deletions testsuite/scripts/benchmarks/test_p3m.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#
# Copyright (C) 2019-2022 The ESPResSo project
#
# This file is part of ESPResSo.
Expand All @@ -14,6 +15,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

import unittest as ut
import importlib_wrapper
Expand All @@ -22,9 +24,12 @@
# make simulation deterministic
np.random.seed(42)

gpu = "gpu" in "@TEST_LABELS@".split(";")
cmd_arguments = ["--particles_per_core", "400", "--gpu" if gpu else "--no-gpu"]
benchmark, skipIfMissingFeatures = importlib_wrapper.configure_and_import(
"@BENCHMARKS_DIR@/p3m.py", cmd_arguments=["--particles_per_core", "400"],
measurement_steps=100, n_iterations=2, min_skin=0.262, max_skin=0.262,
"@BENCHMARKS_DIR@/p3m.py", gpu=gpu, measurement_steps=100, n_iterations=2,
cmd_arguments=cmd_arguments, script_suffix="@TEST_SUFFIX@",
min_skin=0.262, max_skin=0.262,
p3m_params={'prefactor': 4, 'accuracy': 1e-4, 'cao': 7, 'r_cut': 3.182,
'mesh': [24, 24, 24], 'alpha': 1.02742, 'tune': False})

Expand Down