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

Removing /tmp/scratch files at end of array job #406

Merged
merged 7 commits into from Nov 7, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 18 additions & 1 deletion buildstockbatch/eagle.py
Expand Up @@ -61,7 +61,6 @@ class EagleBatch(BuildStockBatchBase):
min_sims_per_job = 36 * 2

local_scratch = pathlib.Path(os.environ.get("LOCAL_SCRATCH", "/tmp/scratch"))
local_project_dir = local_scratch / "project"
local_buildstock_dir = local_scratch / "buildstock"
local_weather_dir = local_scratch / "weather"
local_output_dir = local_scratch / "output"
Expand Down Expand Up @@ -312,6 +311,24 @@ def run_building_d(i, upgrade_idx):

logger.info("batch complete")

# Remove local scratch files
dirs_to_remove = [
self.local_buildstock_dir,
self.local_weather_dir,
self.local_output_dir,
self.local_housing_characteristics_dir,
]

logger.info(f"Cleaning up {self.local_scratch}")
for dir in dirs_to_remove:
logger.debug(f"Removing {dir}")
if dir.exists():
shutil.rmtree(dir)
else:
logger.warning(f"Directory does not exist {dir}")
logger.debug(f"Removing {self.local_singularity_img}")
self.local_singularity_img.unlink(missing_ok=True)

@classmethod
def run_building(cls, output_dir, cfg, n_datapoints, i, upgrade_idx=None):
fs = LocalFileSystem()
Expand Down
6 changes: 6 additions & 0 deletions buildstockbatch/test/test_eagle.py
Expand Up @@ -256,6 +256,7 @@ def sequential_parallel(**kwargs):
return joblib.Parallel(**kw2)

mocker.patch("buildstockbatch.eagle.shutil.copy2")
rmtree_mock = mocker.patch("buildstockbatch.eagle.shutil.rmtree")
mocker.patch("buildstockbatch.eagle.Parallel", sequential_parallel)
mocker.patch("buildstockbatch.eagle.subprocess")

Expand Down Expand Up @@ -287,6 +288,10 @@ def make_sim_dir_mock(building_id, upgrade_idx, base_dir, overwrite_existing=Fal
b.run_batch(sampling_only=True) # so the directories can be created
sampler_mock.run_sampling.assert_called_once()
b.run_job_batch(1)
rmtree_mock.assert_any_call(b.local_buildstock_dir)
rmtree_mock.assert_any_call(b.local_weather_dir)
rmtree_mock.assert_any_call(b.local_output_dir)
rmtree_mock.assert_any_call(b.local_housing_characteristics_dir)

# check results job-json
refrence_path = pathlib.Path(__file__).resolve().parent / "test_results" / "reference_files"
Expand Down Expand Up @@ -341,6 +346,7 @@ def sequential_parallel(**kwargs):
return joblib.Parallel(**kw2)

mocker.patch("buildstockbatch.eagle.shutil.copy2")
mocker.patch("buildstockbatch.eagle.shutil.rmtree")
mocker.patch("buildstockbatch.eagle.Parallel", sequential_parallel)
mocker.patch("buildstockbatch.eagle.subprocess")

Expand Down
2 changes: 1 addition & 1 deletion create_eagle_env.sh
Expand Up @@ -32,7 +32,7 @@ conda activate "$MY_CONDA_PREFIX"
which pip
if [ $DEV -eq 1 ]
then
pip install --no-cache-dir -e .
pip install --no-cache-dir -e ".[dev]"
else
pip install --no-cache-dir .
fi
7 changes: 7 additions & 0 deletions docs/changelog/changelog_dev.rst
Expand Up @@ -14,3 +14,10 @@ Development Changelog
This is an example change. Please copy and paste it - for valid tags please refer to ``conf.py`` in the docs
directory. ``pullreq`` should be set to the appropriate pull request number and ``tickets`` to any related
github issues. These will be automatically linked in the documentation.

.. change::
:tags: eagle, bugfix
:pullreq: 406
:tickets: 404

Cleans out the ``/tmp/scratch`` folder on Eagle at the end of each array job.