-
Notifications
You must be signed in to change notification settings - Fork 14
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
ResStock-HPXML: HES Workflow Generator #252
Closed
Closed
Changes from all commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
45ee2f9
make copy of residential_hpxml workflow generator to get started on h…
aspeake a1efb5a
first pass at connecting OS-HEScore using filepath yml argument
aspeake a270ff6
try to pull local Docker image first
aspeake d8cd306
update yml field name; some updates to HES workflow generator
aspeake 7483a12
fix a couple of osw arguments; temporary changes for testing
aspeake a748763
mount OS-HEScore weather directory; update hardcoded workflow generat…
aspeake 570d5cd
new argument passed to BuildExistingModel
aspeake 633ae54
style fixes
aspeake bd2ba32
fix check for OS_HEScore directory path
aspeake 21a74ef
Merge remote-tracking branch 'origin/restructure-v3' into restructure…
aspeake ced0abc
output timeseries for hes workflow generator
aspeake 0b5324e
change opestudio docker image
aspeake 553d5fe
apply defaults in BuildExistingModel
aspeake 20317ea
updated HEScoreHPXML arguments
aspeake ed499b4
unit test for hes workflow generator
aspeake 110742e
use bool types in argument dict
aspeake 708b8ca
inherit residential_hpxml in residential_hpxml_hes workflow generator
aspeake f81e138
specify OS-HEScore measure path to use the correct reporting measure
aspeake a209fe6
update test for hpxml hes workflow generator
aspeake 54f7f22
style fixes
aspeake c001c97
Merge remote-tracking branch 'origin/restructure-v3' into restructure…
aspeake 26efc6f
Merge remote-tracking branch 'origin/restructure-v3' into restructure…
aspeake 30ba6f5
Merge branch 'restructure-v3' into restructure-v3-hes
joseph-robertson bccc0c1
Fix syntax.
joseph-robertson 837098e
bind OS-HEScore/hescore-hpxml to local docker image
aspeake c0539c0
Merge branch 'restructure-v3-hes' of github.com:NREL/buildstockbatch …
aspeake 947df50
address pytest errors
aspeake 8bc4b4f
temporary yml for hes workflow testing
aspeake a22e02c
fix relative path for OS-HEScore directory
aspeake 5bdb4e5
mounting into /opt/hescore-hpxml
nmerket 955f610
keeping the whole batch from failing on a single simulation failure
nmerket 0a91a21
Merge branch 'develop' into restructure-v3-hes
nmerket 21fcba0
Merge remote-tracking branch 'origin/develop' into restructure-v3-hes
nmerket 5a141be
minor formatting change
nmerket 2a00232
building hescore image on the fly
nmerket 0ac675a
adding resstock hescore reporting measure
nmerket 82f4c7f
Revert "adding resstock hescore reporting measure"
shorowit afeaa40
Merge remote-tracking branch 'origin/develop' into restructure-v3-hes
aspeake 35ba146
add buildarg to hes docker image, minor updates to hes workflow yml
aspeake 7cd801c
break up yml validation method in order to edit schema in child class
aspeake e256c7e
Merge remote-tracking branch 'origin/develop' into restructure-v3-hes
aspeake 653f6d2
style fixes
aspeake 7bc8030
more style fixes
aspeake 50125e3
update hes workflow generator test
aspeake 0af1325
Fix missing os_hes_dir variable in some cases
aspeake d8fa15f
remove debug statement
aspeake 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 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 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 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 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 |
---|---|---|
|
@@ -31,6 +31,7 @@ | |
from buildstockbatch.base import BuildStockBatchBase, SimulationExists | ||
from buildstockbatch import postprocessing | ||
from .utils import log_error_details, ContainerRuntime | ||
from docker.errors import ImageNotFound | ||
from buildstockbatch.__version__ import __version__ as bsb_version | ||
|
||
logger = logging.getLogger(__name__) | ||
|
@@ -52,22 +53,41 @@ def __init__(self, project_filename): | |
|
||
self._weather_dir = None | ||
|
||
# FIXME: something better and more general than os_hescore_dir | ||
if self.os_hescore_dir: | ||
logger.debug("Building HEScore docker image") | ||
self.docker_client.images.build( | ||
path=self.os_hescore_dir, | ||
tag=self.docker_image, | ||
dockerfile="resstock/Dockerfile", | ||
rm=True, | ||
buildargs={'os_version': self.os_version} | ||
) | ||
logger.debug("Docker image built") | ||
else: | ||
try: | ||
self.docker_client.images.get(self.docker_image) | ||
except ImageNotFound: | ||
self.docker_client.images.pull(self.docker_image) | ||
|
||
@staticmethod | ||
def validate_project(project_file): | ||
super(DockerBatchBase, DockerBatchBase).validate_project(project_file) | ||
# LocalDocker specific code goes here | ||
|
||
@property | ||
def docker_image(self): | ||
return 'nrel/openstudio:{}'.format(self.os_version) | ||
if self.os_hescore_dir: | ||
return 'nrel/hescore-hpxml-openstudio' | ||
else: | ||
return 'nrel/openstudio:{}'.format(self.os_version) | ||
|
||
|
||
class LocalDockerBatch(DockerBatchBase): | ||
|
||
def __init__(self, project_filename): | ||
super().__init__(project_filename) | ||
logger.debug(f'Pulling docker image: {self.docker_image}') | ||
self.docker_client.images.pull(self.docker_image) | ||
|
||
# Create simulation_output dir | ||
sim_out_ts_dir = os.path.join(self.results_dir, 'simulation_output', 'timeseries') | ||
|
@@ -149,28 +169,44 @@ def weather_dir(self): | |
return self._weather_dir.name | ||
|
||
@classmethod | ||
def run_building(cls, project_dir, buildstock_dir, weather_dir, docker_image, results_dir, measures_only, | ||
n_datapoints, cfg, i, upgrade_idx=None): | ||
def run_building(cls, project_dir, buildstock_dir, weather_dir, os_hescore_dir, docker_image, results_dir, | ||
measures_only, n_datapoints, cfg, i, upgrade_idx=None): | ||
Comment on lines
-152
to
+173
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see this was necessary to get it working, but I don't like it. |
||
|
||
upgrade_id = 0 if upgrade_idx is None else upgrade_idx + 1 | ||
|
||
try: | ||
sim_id, sim_dir = cls.make_sim_dir(i, upgrade_idx, os.path.join(results_dir, 'simulation_output')) | ||
except SimulationExists: | ||
return | ||
|
||
bind_mounts = [ | ||
(sim_dir, '', 'rw'), | ||
(os.path.join(buildstock_dir, 'measures'), 'measures', 'ro'), | ||
(os.path.join(buildstock_dir, 'resources'), 'lib/resources', 'ro'), | ||
(os.path.join(project_dir, 'housing_characteristics'), 'lib/housing_characteristics', 'ro'), | ||
(weather_dir, 'weather', 'ro') | ||
] | ||
|
||
# ResStock-hpxml measure directory | ||
if os.path.exists(os.path.join(buildstock_dir, 'resources', 'hpxml-measures')): | ||
bind_mounts += [(os.path.join(buildstock_dir, 'resources', 'hpxml-measures'), | ||
'resources/hpxml-measures', 'ro')] | ||
docker_volume_mounts = dict([(key, {'bind': f'/var/simdata/openstudio/{bind}', 'mode': mode}) for key, bind, mode in bind_mounts]) # noqa E501 | ||
bind_mounts.append( | ||
(os.path.join(buildstock_dir, 'resources', 'hpxml-measures'), 'resources/hpxml-measures', 'ro') | ||
) | ||
|
||
# OS-HEScore weather directory | ||
if os_hescore_dir and os.path.exists(os_hescore_dir): | ||
bind_mounts.append((os.path.join(os_hescore_dir, 'weather'), '/opt/OpenStudio-HEScore/weather', 'ro')) | ||
|
||
docker_volume_mounts = { | ||
key: { | ||
'bind': bind if bind.startswith('/') else f'/var/simdata/openstudio/{bind}', | ||
'mode': mode | ||
} | ||
for key, bind, mode in bind_mounts | ||
} | ||
|
||
for bind in bind_mounts: | ||
if bind[1].startswith('/'): | ||
continue | ||
dir_to_make = os.path.join(sim_dir, *bind[1].split('/')) | ||
if not os.path.exists(dir_to_make): | ||
os.makedirs(dir_to_make) | ||
|
@@ -211,17 +247,20 @@ def run_building(cls, project_dir, buildstock_dir, weather_dir, docker_image, re | |
extra_kws = {} | ||
if sys.platform.startswith('linux'): | ||
extra_kws['user'] = f'{os.getuid()}:{os.getgid()}' | ||
container_output = docker_client.containers.run( | ||
|
||
container = docker_client.containers.run( | ||
docker_image, | ||
run_cmd, | ||
remove=True, | ||
detach=True, | ||
volumes=docker_volume_mounts, | ||
name=sim_id, | ||
environment=env_vars, | ||
**extra_kws | ||
) | ||
with open(os.path.join(sim_dir, 'docker_output.log'), 'wb') as f_out: | ||
f_out.write(container_output) | ||
for x in container.logs(stream=True): | ||
f_out.write(x) | ||
|
||
# Clean up directories created with the docker mounts | ||
for dirname in ('lib', 'measures', 'weather'): | ||
|
@@ -255,6 +294,7 @@ def run_batch(self, n_jobs=None, measures_only=False, sampling_only=False): | |
self.project_dir, | ||
self.buildstock_dir, | ||
self.weather_dir, | ||
self.os_hescore_dir, | ||
self.docker_image, | ||
self.results_dir, | ||
measures_only, | ||
|
@@ -281,6 +321,7 @@ def run_batch(self, n_jobs=None, measures_only=False, sampling_only=False): | |
json.dump(dpouts, f) | ||
del dpouts | ||
|
||
# FIXME temporarily comment out for testing | ||
sim_out_tarfile_name = os.path.join(sim_out_dir, 'simulations_job0.tar.gz') | ||
logger.debug(f'Compressing simulation outputs to {sim_out_tarfile_name}') | ||
with tarfile.open(sim_out_tarfile_name, 'w:gz') as tarf: | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I learned something today that you can search for a substring using
in
.