Skip to content
This repository has been archived by the owner on Apr 23, 2021. It is now read-only.

Add benchmarking and do some optimizations #100

Merged
merged 9 commits into from
Sep 29, 2015
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
13 changes: 10 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,18 @@ Directory structure
-------------------

- simlammps -- hold the lammps-md wrapper implementation

- bench - benchmarking
- common - contains general global files
- config - holds configuration related files
- internal - internal library communication with LAMMPS
- io -- file-io related communication with LAMMPS
- testing -- testing related utilities
- examples -- holds different examples
- doc -- Documentation related files

- source -- Sphinx rst source files
- build -- Documentation build directory, if documentation has been generated
using the ``make`` script in the ``doc`` directory.
- source -- Sphinx rst source files
- build -- Documentation build directory, if documentation has been generated
using the ``make`` script in the ``doc`` directory.

.. _simphony-common: https://github.com/simphony/simphony-common
23 changes: 16 additions & 7 deletions simlammps/abc_data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,29 +199,38 @@ def get_particle(self, uid, uname):
"""

@abc.abstractmethod
def update_particle(self, particle, uname):
def update_particles(self, iterable, uname):
"""Update particle

Parameters
----------
uid :
uid of particle
iterable : iterable of Particle objects
the particles that will be updated.
uname : string
non-changing unique name of particles

Raises
------
ValueError :
If any particle inside the iterable does not exist.

"""

@abc.abstractmethod
def add_particle(self, particle, uname):
"""Add particle
def add_particles(self, iterable, uname):
"""Add particles

Parameters
----------
uid :
uid of particle
iterable : iterable of Particle objects
the particles that will be added.
uname : string
non-changing unique name of particles

ValueError :
when there is a particle with an uids that already exists
in the container.

"""

@abc.abstractmethod
Expand Down
Empty file added simlammps/bench/__init__.py
Empty file.
78 changes: 78 additions & 0 deletions simlammps/bench/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
from __future__ import print_function

import subprocess
import os
import tempfile
import shutil

from simlammps import read_data_file


def get_particles(y_range):
""" get particles for benchmarking

Parameters
----------
y_range : float
range of particle domain in y

Returns
-------
particle_list : iterable of ABCParticles

"""
particles_list = None

temp_dir = tempfile.mkdtemp()
script_name = os.path.join(temp_dir, "script")
data_name = os.path.join(temp_dir, "output")
try:
with open(script_name, "w") as script_file:
script_file.write(lammps_script.format(y_range=y_range,
data_name=data_name))
cmd = ("lammps -screen none"
" -log none -echo none"
" < {}").format(script_name)
subprocess.check_call(cmd, shell=True)
particles_list = read_data_file(data_name)
finally:
shutil.rmtree(temp_dir)
return particles_list


lammps_script = """# create particles"
dimension 2
atom_style atomic

# create geometry
lattice hex .7
region box block 0 {y_range} 0 10 -0.25 0.25
create_box 3 box
create_atoms 1 box

mass 1 1.0
mass 2 1.0
mass 3 1.0

# LJ potentials
pair_style lj/cut 1.12246
pair_coeff * * 1.0 1.0 1.12246

# define groups
region 1 block INF INF INF 1.25 INF INF
group lower region 1
region 2 block INF INF 8.75 INF INF INF
group upper region 2
group boundary union lower upper
group flow subtract all boundary

set group lower type 2
set group upper type 3

# initial velocities
compute mobile flow temp
velocity flow create 1.0 482748 temp mobile
velocity boundary set 0.0 0.0 0.0

# write atoms to a lammps data file
write_data {data_name}"""
115 changes: 115 additions & 0 deletions simlammps/bench/wrapper_bench.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
from collections import namedtuple

_Tests = namedtuple(
'_Tests', ['method', 'name'])

from simphony.engine import lammps
from simphony.bench.util import bench
from simphony.core.cuba import CUBA
from simphony.core.cuds_item import CUDSItem

from simlammps.bench.util import get_particles
from simlammps.testing.md_example_configurator import MDExampleConfigurator


def configure_wrapper(wrapper, particles, number_time_steps):
""" Configure wrapper

Parameters:
-----------
wrapper : ABCModelingEngine
wrapper to be configured
particles : iterable of ABCParticles
particles to use
number_time_steps : int
number of time steps to run
"""
material_types = []
for dataset in particles:
material_types.append(dataset.data[CUBA.MATERIAL_TYPE])
wrapper.add_dataset(dataset)

MDExampleConfigurator.set_configuration(wrapper,
material_types,
number_time_steps)


def run(wrapper):
wrapper.run()


def run_iterate(wrapper):
wrapper.run()
for particles_dataset in wrapper.iter_datasets():
for particle in particles_dataset.iter_particles():
pass


def run_update_run(wrapper):
wrapper.run()
for particles_dataset in wrapper.iter_datasets():
for particle in particles_dataset.iter_particles():
particles_dataset.update_particles([particle])
wrapper.run()


def describe(name, number_particles, number_steps, is_internal):
wrapper_type = "INTERNAL" if is_internal else "FILE-IO"
result = "{}__{}_particles_{}_steps_{}:".format(name,
number_particles,
number_steps,
wrapper_type)
return result


def run_test(func, wrapper):
func(wrapper)

if __name__ == '__main__':

run_wrapper_tests = [_Tests(method=run,
name="run"),
_Tests(method=run_iterate,
name="run_iterate"),
_Tests(method=run_update_run,
name="run_update_run")]

for is_internal in [True, False]:
for y_range in [3000, 8000]:

# test different run scenarios
particles = get_particles(y_range)
number_particles = sum(p.count_of(
CUDSItem.PARTICLE) for p in particles)
number_time_steps = 10

for test in run_wrapper_tests:
lammps_wrapper = lammps.LammpsWrapper(
use_internal_interface=is_internal)
configure_wrapper(lammps_wrapper,
particles,
number_time_steps=number_time_steps)

results = bench(lambda: run_test(test.method, lammps_wrapper),
repeat=1,
adjust_runs=False)

print(describe(test.name,
number_particles,
number_time_steps,
is_internal), results)

# test configuration
lammps_wrapper = lammps.LammpsWrapper(
use_internal_interface=is_internal)

results = bench(lambda: configure_wrapper(lammps_wrapper,
particles,
number_time_steps),
repeat=1,
adjust_runs=False)

print(describe("configure_wrapper",
number_particles,
number_time_steps,
is_internal), results)
Loading