Skip to content

Commit

Permalink
Replace bucket and prefix params with a single path
Browse files Browse the repository at this point in the history
  • Loading branch information
nweires committed Dec 5, 2023
1 parent bc66dd5 commit d826e51
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
11 changes: 5 additions & 6 deletions buildstockbatch/cloud/docker_base.py
Expand Up @@ -234,7 +234,7 @@ def get_epws_to_download(cls, sim_dir, jobs_d):
return epws_to_download

@classmethod
def run_simulations(cls, cfg, job_id, jobs_d, sim_dir, fs, bucket, prefix):
def run_simulations(cls, cfg, job_id, jobs_d, sim_dir, fs, output_path):
"""
Run one batch of simulations.
Expand All @@ -245,15 +245,14 @@ def run_simulations(cls, cfg, job_id, jobs_d, sim_dir, fs, bucket, prefix):
:param jobs_d: Contents of a single job JSON file; contains the list of buildings to simulate in this job.
:param sim_dir: Path to the (local) directory where job files are stored.
:param fs: Filesystem to use when writing outputs to storage bucket
:param bucket: Name of the storage bucket to upload results to.
:param prefix: File prefix to use when writing to storage bucket.
:param output_path: File path (typically `bucket/prefix`) to write outputs to.
"""
local_fs = LocalFileSystem()
reporting_measures = cls.get_reporting_measures(cfg)
dpouts = []
simulation_output_tar_filename = sim_dir.parent / "simulation_outputs.tar.gz"
asset_dirs = os.listdir(sim_dir)
ts_output_dir = (f"{bucket}/{prefix}/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"]:
Expand Down Expand Up @@ -316,12 +315,12 @@ def run_simulations(cls, cfg, job_id, jobs_d, sim_dir, fs, bucket, prefix):
# Upload simulation outputs tarfile to s3
fs.put(
str(simulation_output_tar_filename),
f"{bucket}/{prefix}/results/simulation_output/simulations_job{job_id}.tar.gz",
f"{output_path}/results/simulation_output/simulations_job{job_id}.tar.gz",
)

# Upload aggregated dpouts as a json file
with fs.open(
f"{bucket}/{prefix}/results/simulation_output/results_job{job_id}.json.gz",
f"{output_path}/results/simulation_output/results_job{job_id}.json.gz",
"wb",
) as f1:
with gzip.open(f1, "wt", encoding="utf-8") as f2:
Expand Down
2 changes: 1 addition & 1 deletion buildstockbatch/test/test_docker_base.py
Expand Up @@ -120,7 +120,7 @@ def test_run_simulations(basic_residential_project_file):
bucket = temp_path / "bucket"
os.makedirs(bucket / "test_prefix" / "results" / "simulation_output")

DockerBatchBase.run_simulations(cfg, 0, jobs_d, sim_dir, fs, bucket, "test_prefix")
DockerBatchBase.run_simulations(cfg, 0, jobs_d, sim_dir, fs, f"{bucket}/test_prefix")

output_dir = bucket / "test_prefix" / "results" / "simulation_output"
assert sorted(os.listdir(output_dir)) == ["results_job0.json.gz", "simulations_job0.tar.gz"]
Expand Down

0 comments on commit d826e51

Please sign in to comment.