From b9f9532e6714d6a8907a935fadb4d4b3a9f6a682 Mon Sep 17 00:00:00 2001 From: Natalie Weires Date: Mon, 11 Dec 2023 15:09:15 +0000 Subject: [PATCH 1/2] Two small fixes --- buildstockbatch/aws/aws.py | 2 +- buildstockbatch/cloud/docker_base.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/buildstockbatch/aws/aws.py b/buildstockbatch/aws/aws.py index 83f6d8fe..29501610 100644 --- a/buildstockbatch/aws/aws.py +++ b/buildstockbatch/aws/aws.py @@ -1723,7 +1723,7 @@ def run_job(cls, job_id, bucket, prefix, job_name, region): logger.debug("Extracting {}".format(epw_filename)) f_out.write(gzip.decompress(f_gz.getvalue())) - cls.run_simulations(cfg, jobs_d, job_id, sim_dir, S3FileSystem(), bucket, prefix) + cls.run_simulations(cfg, jobs_d, job_id, sim_dir, S3FileSystem(), f"{bucket}/{prefix}") @log_error_details() diff --git a/buildstockbatch/cloud/docker_base.py b/buildstockbatch/cloud/docker_base.py index 5cdd0117..ee3b16fc 100644 --- a/buildstockbatch/cloud/docker_base.py +++ b/buildstockbatch/cloud/docker_base.py @@ -252,7 +252,7 @@ def run_simulations(cls, cfg, job_id, jobs_d, sim_dir, fs, output_path): dpouts = [] simulation_output_tar_filename = sim_dir.parent / "simulation_outputs.tar.gz" asset_dirs = os.listdir(sim_dir) - ts_output_dir = (f"{output_path}/results/simulation_output/timeseries",) + ts_output_dir = f"{output_path}/results/simulation_output/timeseries" with tarfile.open(str(simulation_output_tar_filename), "w:gz") as simout_tar: for building_id, upgrade_idx in jobs_d["batch"]: From 1b60710b7e4345944dc2928b0f2afaf554c08b0b Mon Sep 17 00:00:00 2001 From: Natalie Weires Date: Tue, 12 Dec 2023 21:35:13 +0000 Subject: [PATCH 2/2] Update test --- buildstockbatch/test/test_docker_base.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/buildstockbatch/test/test_docker_base.py b/buildstockbatch/test/test_docker_base.py index 6164c8c9..6ecffcff 100644 --- a/buildstockbatch/test/test_docker_base.py +++ b/buildstockbatch/test/test_docker_base.py @@ -1,5 +1,6 @@ """Tests for the DockerBatchBase class.""" from fsspec.implementations.local import LocalFileSystem +import gzip import json import os import pathlib @@ -97,6 +98,12 @@ def test_get_epws_to_download(): def test_run_simulations(basic_residential_project_file): + """ + Test running a single batch of simulation. + + This doesn't provide all the necessary inputs for the simulations to succeed, but it confirms that they are + attempted, that the output files are produced, and that intermediate files are cleaned up. + """ jobs_d = { "job_num": 0, "n_datapoints": 10, @@ -124,6 +131,14 @@ def test_run_simulations(basic_residential_project_file): output_dir = bucket / "test_prefix" / "results" / "simulation_output" assert sorted(os.listdir(output_dir)) == ["results_job0.json.gz", "simulations_job0.tar.gz"] + + # Check that buildings 1 and 5 (specified in jobs_d) are in the results + with gzip.open(output_dir / "results_job0.json.gz", "r") as f: + results = json.load(f) + assert len(results) == 2 + for building in results: + assert building["building_id"] in (1, 5) + # Check that files were cleaned up correctly assert not os.listdir(sim_dir) os.chdir(old_cwd)