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

Add Integration Tests #326

Merged
merged 13 commits into from Nov 10, 2022
Merged

Add Integration Tests #326

merged 13 commits into from Nov 10, 2022

Conversation

nmerket
Copy link
Member

@nmerket nmerket commented Nov 2, 2022

Fixes #318

Pull Request Description

This adds some integration tests where we checkout the lastest ResStock and run small versions of each of the testing projects in ResStock.

Checklist

Not all may apply

  • Code changes (must work)
  • Tests exercising your feature/bug fix (check coverage report on Checks -> BuildStockBatch Tests -> Artifacts)
  • Coverage has increased or at least not decreased. Update minimum_coverage in .github/workflows/ci.yml as necessary.
  • All other unit tests passing
  • Update validation for project config yaml file changes
  • Update existing documentation
  • Run a small batch run to make sure it all works (local is fine, unless an Eagle specific feature)
  • Add to the changelog_dev.rst file and propose migration text in the pull request

@github-actions
Copy link

github-actions bot commented Nov 2, 2022

File Coverage
All files 86%
base.py 88%
eagle.py 74%
exc.py 57%
localdocker.py 63%
postprocessing.py 84%
utils.py 96%
sampler/base.py 79%
sampler/downselect.py 33%
sampler/precomputed.py 93%
sampler/residential_quota.py 83%
test/test_validation.py 96%
workflow_generator/base.py 90%
workflow_generator/commercial.py 53%
workflow_generator/residential.py 96%
workflow_generator/residential_hpxml.py 70%

Minimum allowed coverage is 33%

Generated by 🐒 cobertura-action against 563b9e7

Copy link
Member Author

@nmerket nmerket left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My comments on what I did below. Merge #323 before this one.

Comment on lines +19 to +26
- uses: actions/checkout@v3
with:
path: buildstockbatch
- uses: actions/checkout@v3
with:
repository: NREL/resstock
path: resstock
ref: develop
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking out both repos

repository: NREL/resstock
path: resstock
ref: develop
- uses: actions/setup-python@v4
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I generally tried to update to the latest versions of all the actions.

Comment on lines -2 to +9
on: [pull_request]
on:
push:
branches:
- develop
pull_request:
types:
- synchronize
- opened
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing these checks on merge into develop as well on @shorowit's recommendation.

Comment on lines +30 to +34
- name: Download weather
run: |
mkdir weather
cd weather
wget --quiet https://data.nrel.gov/system/files/156/BuildStock_TMY3_FIPS.zip
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the testing files use the same batch of weather files. This keeps it from being downloaded 4 times.

Comment on lines +17 to +22
@pytest.mark.parametrize("project_filename", [
resstock_directory / "project_national" / "national_baseline.yml",
resstock_directory / "project_national" / "national_upgrades.yml",
resstock_directory / "project_testing" / "testing_baseline.yml",
resstock_directory / "project_testing" / "testing_upgrades.yml",
], ids=lambda x: x.stem)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm testing each of the project yaml files in resstock.

Comment on lines +28 to +40
# Get the number of upgrades
n_upgrades = len(batch.cfg.get("upgrades", []))
# Limit the number of upgrades to 2 to reduce simulation time
if n_upgrades > 2:
batch.cfg["upgrades"] = batch.cfg["upgrades"][0:2]
n_upgrades = 2

# Modify the number of datapoints so we're not here all day.
if n_upgrades == 0:
n_datapoints = 4
else:
n_datapoints = 2
batch.cfg["sampler"]["args"]["n_datapoints"] = n_datapoints
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to spend forever running these ResStock runs. I just want to make sure the machinery works, so I'm limiting the number of upgrades and datapoints to keep the CI running quickly.

Comment on lines +43 to +46
local_weather_file = resstock_directory.parent / "weather" / batch.cfg["weather_files_url"].split("/")[-1]
if local_weather_file.exists():
del batch.cfg["weather_files_url"]
batch.cfg["weather_files_path"] = str(local_weather_file)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'll check if the weather is found locally and swap that in instead. Since we downloaded it earlier to the appropriate place it should just be able to unzip it.

Comment on lines 29 to 37
conda create -y --prefix "$MY_CONDA_PREFIX" -c conda-forge "pyarrow>=7.0.0" "python=3.9" "numpy>=1.20.0" "pandas>=1.0.0,!=1.0.4" "dask>=2022.10.0" "distributed>=2021.5" ruby
source deactivate
source activate "$MY_CONDA_PREFIX"
mamba create -y --prefix "$MY_CONDA_PREFIX" -c conda-forge "python=3.10" "pyarrow" "numpy" "pandas" "dask>=2022.10.0" "distributed" "ruby"
conda deactivate
conda activate "$MY_CONDA_PREFIX"
which pip
if [ $DEV -eq 1 ]
then
pip install --ignore-installed -e .
pip install --no-cache-dir --ignore-installed -e .
else
pip install --ignore-installed .
pip install --no-cache-dir --ignore-installed .
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are changes from #323. I branched from that branch for this work. They will disappear once that is merged.

@nmerket nmerket marked this pull request as ready for review November 2, 2022 20:16
assert (out_path / "results_csvs" / f"results_up{upgrade_id:02d}.csv.gz").exists()
assert (ts_pq_path / "_common_metadata").exists()
assert (ts_pq_path / "_metadata").exists()

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do all these asserts check to see if all the simulations failed? The machinery might work, but there should be some real results.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. It does check that timeseries files exist for each simulation, but I will also add something to open the results parquet file and ensure they all succeeded.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking to see "all" succeeded seems robust, but we might accidentally sample a building that will fail in OpenStudio-HPXML. The current failure rate seems low (~0.1%) enough. At least 1 successful run might be okay.

@joseph-robertson
Copy link
Contributor

CI time goes from about 3 min to 15 min here?

@nmerket
Copy link
Member Author

nmerket commented Nov 4, 2022

CI time goes from about 3 min to 15 min here?

That's what happens when you actually start running simulations. I'm doing this for all versions of python we support. I may consider just doing it for the latest version, but it all happens in parallel so I don't see a problem with it.

df.to_csv(gf, index=True, line_terminator='\n')
df.to_csv(gf, index=True, lineterminator='\n')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@afontani afontani self-requested a review November 8, 2022 23:49
Copy link
Collaborator

@afontani afontani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nmerket : It looks like the tests are working. It makes sense that the CI time increased a little. I do like the parallelization. Unless you want to do anything else with this PR, I am happy with the functionality.

@nmerket nmerket merged commit 2757065 into develop Nov 10, 2022
@nmerket nmerket deleted the integration-tests branch November 10, 2022 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Integration Tests for ResStock
3 participants