-
Notifications
You must be signed in to change notification settings - Fork 6
Test with SLURM #726
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
Merged
Merged
Test with SLURM #726
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0d83164
Test with SLURM
jan-janssen a9b89ad
if CI
jan-janssen 25a06b8
fixes
jan-janssen b4e38ba
tests
jan-janssen 58ff933
update tests
jan-janssen 7aa952d
check for h5py
jan-janssen 6961e16
remove openmpi tests
jan-janssen 6e35422
add time out
jan-janssen 464517c
remove blockallocation
jan-janssen 6d1ab10
remove threads test
jan-janssen 01a115c
reduce to a single test
jan-janssen b2b57c1
remove unused import
jan-janssen fc211a2
remove unused functions
jan-janssen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| import os | ||
| import importlib | ||
| import unittest | ||
| import shutil | ||
|
|
||
| from executorlib import SlurmClusterExecutor | ||
| from executorlib.standalone.serialize import cloudpickle_register | ||
|
|
||
| if shutil.which("srun") is not None: | ||
| skip_slurm_test = False | ||
| else: | ||
| skip_slurm_test = True | ||
|
|
||
| skip_mpi4py_test = importlib.util.find_spec("mpi4py") is None | ||
|
|
||
| try: | ||
| from executorlib.task_scheduler.file.hdf import dump | ||
|
|
||
| skip_h5py_test = False | ||
| except ImportError: | ||
| skip_h5py_test = True | ||
|
|
||
| submission_template = """\ | ||
| #!/bin/bash | ||
| #SBATCH --output=time.out | ||
| #SBATCH --job-name={{job_name}} | ||
| #SBATCH --chdir={{working_directory}} | ||
| #SBATCH --get-user-env=L | ||
| #SBATCH --cpus-per-task={{cores}} | ||
|
|
||
| {{command}} | ||
| """ | ||
|
|
||
|
|
||
| def mpi_funct(i): | ||
| from mpi4py import MPI | ||
|
|
||
| size = MPI.COMM_WORLD.Get_size() | ||
| rank = MPI.COMM_WORLD.Get_rank() | ||
| return i, size, rank | ||
|
|
||
|
|
||
| @unittest.skipIf( | ||
| skip_slurm_test or skip_mpi4py_test or skip_h5py_test, | ||
| "h5py or mpi4py or SLRUM are not installed, so the h5py, slurm and mpi4py tests are skipped.", | ||
| ) | ||
| class TestCacheExecutorPysqa(unittest.TestCase): | ||
| def test_executor(self): | ||
| with SlurmClusterExecutor( | ||
| resource_dict={"cores": 2, "cwd": "executorlib_cache", "submission_template": submission_template}, | ||
liamhuber marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| block_allocation=False, | ||
| cache_directory="executorlib_cache", | ||
| terminate_tasks_on_shutdown=False, | ||
| ) as exe: | ||
| cloudpickle_register(ind=1) | ||
| fs1 = exe.submit(mpi_funct, 1) | ||
| self.assertFalse(fs1.done()) | ||
| self.assertEqual(fs1.result(), [(1, 2, 0), (1, 2, 1)]) | ||
| self.assertEqual(len(os.listdir("executorlib_cache")), 3) | ||
| self.assertTrue(fs1.done()) | ||
|
|
||
| def test_executor_no_cwd(self): | ||
| with SlurmClusterExecutor( | ||
| resource_dict={"cores": 2, "submission_template": submission_template}, | ||
| block_allocation=False, | ||
| cache_directory="executorlib_cache", | ||
| terminate_tasks_on_shutdown=True, | ||
| ) as exe: | ||
| cloudpickle_register(ind=1) | ||
| fs1 = exe.submit(mpi_funct, 1) | ||
| self.assertFalse(fs1.done()) | ||
| self.assertEqual(fs1.result(), [(1, 2, 0), (1, 2, 1)]) | ||
| self.assertEqual(len(os.listdir("executorlib_cache")), 2) | ||
| self.assertTrue(fs1.done()) | ||
|
|
||
| def test_executor_existing_files(self): | ||
| with SlurmClusterExecutor( | ||
| resource_dict={"cores": 2, "cwd": "executorlib_cache", "submission_template": submission_template}, | ||
| block_allocation=False, | ||
| cache_directory="executorlib_cache", | ||
| ) as exe: | ||
| cloudpickle_register(ind=1) | ||
| fs1 = exe.submit(mpi_funct, 1) | ||
| self.assertFalse(fs1.done()) | ||
| self.assertEqual(fs1.result(), [(1, 2, 0), (1, 2, 1)]) | ||
| self.assertTrue(fs1.done()) | ||
| self.assertEqual(len(os.listdir("executorlib_cache")), 3) | ||
| for file_name in os.listdir("executorlib_cache"): | ||
| file_path = os.path.join("executorlib_cache", file_name ) | ||
| os.remove(file_path) | ||
| if ".h5" in file_path: | ||
| task_key = file_path[:-5] + "_i.h5" | ||
| dump(file_name=task_key, data_dict={"a": 1}) | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| with SlurmClusterExecutor( | ||
| resource_dict={"cores": 2, "cwd": "executorlib_cache", "submission_template": submission_template}, | ||
| block_allocation=False, | ||
| cache_directory="executorlib_cache", | ||
| ) as exe: | ||
| cloudpickle_register(ind=1) | ||
| fs1 = exe.submit(mpi_funct, 1) | ||
| self.assertFalse(fs1.done()) | ||
| self.assertEqual(fs1.result(), [(1, 2, 0), (1, 2, 1)]) | ||
| self.assertTrue(fs1.done()) | ||
| self.assertEqual(len(os.listdir("executorlib_cache")), 3) | ||
|
|
||
| def tearDown(self): | ||
| shutil.rmtree("executorlib_cache", ignore_errors=True) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import shutil | ||
| import unittest | ||
|
|
||
| from executorlib import SlurmJobExecutor | ||
|
|
||
|
|
||
| if shutil.which("srun") is not None: | ||
| skip_slurm_test = False | ||
| else: | ||
| skip_slurm_test = True | ||
|
|
||
|
|
||
| def calc(i): | ||
| return i | ||
|
|
||
|
|
||
| @unittest.skipIf( | ||
| skip_slurm_test, "Slurm is not installed, so the Slurm tests are skipped." | ||
| ) | ||
| class TestSlurmBackend(unittest.TestCase): | ||
| def test_slurm_executor_serial(self): | ||
| with SlurmJobExecutor() as exe: | ||
| fs_1 = exe.submit(calc, 1) | ||
| fs_2 = exe.submit(calc, 2) | ||
| self.assertEqual(fs_1.result(), 1) | ||
| self.assertEqual(fs_2.result(), 2) | ||
| self.assertTrue(fs_1.done()) | ||
| self.assertTrue(fs_2.done()) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.