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

Update test #82

Merged
merged 9 commits into from
Oct 11, 2022
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
9 changes: 7 additions & 2 deletions pylammpsmpi/lammps_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ class LammpsLibrary:
Top level class which manages the lammps library provided by LammpsBase
"""

def __init__(self, cores=1, working_directory=".", client=None, mode="local"):
def __init__(
self, cores=1, working_directory=".", client=None, mode="local", cmdargs=None
):
self.cores = cores
self.working_directory = working_directory
self.client = client
Expand All @@ -33,6 +35,7 @@ def __init__(self, cores=1, working_directory=".", client=None, mode="local"):
LammpsBase,
cores=self.cores,
working_directory=self.working_directory,
cmdargs=cmdargs,
actor=True,
)
self.lmp = fut.result()
Expand All @@ -42,7 +45,9 @@ def __init__(self, cores=1, working_directory=".", client=None, mode="local"):

elif self.mode == "local":
self.lmp = LammpsBase(
cores=self.cores, working_directory=self.working_directory
cores=self.cores,
working_directory=self.working_directory,
cmdargs=cmdargs,
)
self.lmp.start_process()

Expand Down
5 changes: 4 additions & 1 deletion pylammpsmpi/mpi/lmpmpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@
}

# Lammps executable
job = lammps(cmdargs=["-screen", "none"])
args = ["-screen", "none"]
if len(sys.argv) > 1:
args.extend(sys.argv[1:])
job = lammps(cmdargs=args)


def extract_compute(funct_args):
Expand Down
15 changes: 13 additions & 2 deletions pylammpsmpi/utils/lammps.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,28 @@


class LammpsBase:
def __init__(self, cores=8, working_directory="."):
def __init__(self, cores=8, working_directory=".", cmdargs=None):
self.cores = cores
self.working_directory = working_directory
self._process = None
self._cmdargs = cmdargs

def start_process(self):
executable = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "../mpi", "lmpmpi.py"
)
cmds = [
"mpiexec",
"--oversubscribe",
"-n",
str(self.cores),
"python",
executable,
]
if self._cmdargs is not None:
cmds.extend(self._cmdargs)
self._process = subprocess.Popen(
["mpiexec", "--oversubscribe", "-n", str(self.cores), "python", executable],
cmds,
stdout=subprocess.PIPE,
stderr=None,
stdin=subprocess.PIPE,
Expand Down
29 changes: 21 additions & 8 deletions tests/test_pylammpsmpi_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,20 @@ class TestLocalLammpsLibrary(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.execution_path = os.path.dirname(os.path.abspath(__file__))
cluster = LocalCluster(n_workers=1, threads_per_worker=2)
cls.citation_file = os.path.join(cls.execution_path, "citations.txt")
cls.lammps_file = os.path.join(cls.execution_path, "in.simple")
cluster = LocalCluster(
n_workers=1,
threads_per_worker=2
)
client = Client(cluster)
cls.lmp = LammpsLibrary(cores=2, mode='dask', client=client)
cls.lmp.file(os.path.join(cls.execution_path, "in.simple"))
cls.lmp = LammpsLibrary(
cores=2,
mode='dask',
cmdargs=["-cite", cls.citation_file],
client=client
)
cls.lmp.file(cls.lammps_file)

@classmethod
def tearDownClass(cls):
Expand Down Expand Up @@ -60,11 +70,11 @@ def test_scatter_atoms(self):
f1 = self.lmp.gather_atoms("f")
self.assertEqual(f1[1][0], val)

f = self.lmp.gather_atoms("f", ids=[1,2])
f = self.lmp.gather_atoms("f", ids=[1, 2])
val = np.random.randint(0, 100)
f[1][1] = val
self.lmp.scatter_atoms("f", f, ids=[1,2])
f1 = self.lmp.gather_atoms("f", ids=[1,2])
self.lmp.scatter_atoms("f", f, ids=[1, 2])
f1 = self.lmp.gather_atoms("f", ids=[1, 2])
self.assertEqual(f1[1][1], val)

def test_extract_box(self):
Expand All @@ -75,12 +85,15 @@ def test_extract_box(self):
self.assertEqual(np.round(box[1][0], 2), 6.72)

self.lmp.delete_atoms("group", "all")
self.lmp.reset_box([0.0,0.0,0.0], [8.0,8.0,8.0], 0.0,0.0,0.0)
self.lmp.reset_box([0.0, 0.0, 0.0], [8.0, 8.0, 8.0], 0.0, 0.0, 0.0)
box = self.lmp.extract_box()
self.assertEqual(box[0][0], 0.0)
self.assertEqual(np.round(box[1][0], 2), 8.0)
self.lmp.clear()
self.lmp.file(os.path.join(self.execution_path, "in.simple"))
self.lmp.file(self.lammps_file)

def test_cmdarg_options(self):
self.assertTrue(os.path.isfile(self.citation_file))


if __name__ == "__main__":
Expand Down
11 changes: 8 additions & 3 deletions tests/test_pylammpsmpi_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ class TestLocalLammpsLibrary(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.execution_path = os.path.dirname(os.path.abspath(__file__))
cls.lmp = LammpsLibrary(cores=2, mode='local')
cls.lmp.file(os.path.join(cls.execution_path, "in.simple"))
cls.citation_file = os.path.join(cls.execution_path, "citations.txt")
cls.lammps_file = os.path.join(cls.execution_path, "in.simple")
cls.lmp = LammpsLibrary(cores=2, mode='local', cmdargs=["-cite", cls.citation_file])
cls.lmp.file(cls.lammps_file)

@classmethod
def tearDownClass(cls):
Expand Down Expand Up @@ -78,7 +80,10 @@ def test_extract_box(self):
self.assertEqual(box[0][0], 0.0)
self.assertEqual(np.round(box[1][0], 2), 8.0)
self.lmp.clear()
self.lmp.file(os.path.join(self.execution_path, "in.simple"))
self.lmp.file(self.lammps_file)

def test_cmdarg_options(self):
self.assertTrue(os.path.isfile(self.citation_file))


if __name__ == "__main__":
Expand Down