-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from danyoungday/deployment
Setting up app for deployment
- Loading branch information
Showing
51 changed files
with
642 additions
and
855 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
en-roads-sdk-v24.6.0-beta1 | ||
*.zip | ||
__pycache__ | ||
.DS_Store | ||
*.pt | ||
temp/ | ||
.vscode | ||
results/ | ||
|
||
*.ipynb |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# This runs the unit tests for the En-ROADS use case | ||
|
||
name: enroads Use Case | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python 3.10 | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: "3.10" | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install pylint flake8 | ||
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | ||
- name: Download En-ROADS sdk | ||
env: | ||
ENROADS_ID: ${{ secrets.ENROADS_ID }} | ||
ENROADS_PASSWORD: ${{ secrets.ENROADS_PASSWORD }} | ||
ENROADS_URL: ${{ secrets.ENROADS_URL }} | ||
run: python -m enroadspy.download_sdk | ||
- name: Lint with PyLint | ||
run: pylint . | ||
- name: Lint with Flake8 | ||
run: flake8 | ||
- name: Run unit tests | ||
run: python -m unittest | ||
|
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 |
---|---|---|
|
@@ -5,4 +5,6 @@ __pycache__ | |
*.pt | ||
temp/ | ||
.vscode | ||
results/ | ||
results/ | ||
|
||
!app/results |
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 |
---|---|---|
@@ -1,7 +1,13 @@ | ||
[MASTER] | ||
|
||
ignore=inputSpecs.py | ||
|
||
recursive=y | ||
|
||
max-line-length=120 | ||
|
||
suggestion-mode=yes | ||
|
||
good-names=X,F | ||
good-names=X,F,X0 | ||
|
||
fail-under=9.8 |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
FROM python:3.10-slim | ||
|
||
ARG ENROADS_URL | ||
ARG ENROADS_ID | ||
ARG ENROADS_PASSWORD | ||
|
||
WORKDIR /en-roads-py | ||
|
||
# Debian basics and cleaning up in one RUN statement to reduce image size | ||
RUN apt-get update -y && \ | ||
apt-get install --no-install-recommends curl git gcc g++ make clang -y && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
# Dependencies | ||
COPY requirements.txt . | ||
RUN pip install --no-cache-dir --upgrade pip && \ | ||
pip install --no-cache-dir -r requirements.txt | ||
|
||
# Copy source files over | ||
COPY . . | ||
|
||
# Download En-ROADS SDK and extract it | ||
ENV ENROADS_URL=$ENROADS_URL | ||
ENV ENROADS_ID=$ENROADS_ID | ||
ENV ENROADS_PASSWORD=$ENROADS_PASSWORD | ||
RUN python -m enroadspy.download_sdk | ||
|
||
# Expose Flask (Dash) port | ||
EXPOSE 4057 | ||
|
||
# Run main UI | ||
ENTRYPOINT ["gunicorn", "-b", "0.0.0.0:4057", "--timeout", "45", "app.app:server"] |
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
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
Binary file not shown.
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
{"n_generations": 100, "pop_size": 100, "crowding_func": "mnn", "actions": ["_source_subsidy_delivered_coal_tce", "_source_subsidy_start_time_delivered_coal", "_source_subsidy_stop_time_delivered_coal", "_no_new_coal", "_year_of_no_new_capacity_coal", "_utilization_adjustment_factor_delivered_coal", "_utilization_policy_start_time_delivered_coal", "_utilization_policy_stop_time_delivered_coal", "_target_accelerated_retirement_rate_electric_coal", "_source_subsidy_delivered_oil_boe", "_source_subsidy_start_time_delivered_oil", "_source_subsidy_stop_time_delivered_oil", "_no_new_oil", "_year_of_no_new_capacity_oil", "_utilization_adjustment_factor_delivered_oil", "_utilization_policy_start_time_delivered_oil", "_utilization_policy_stop_time_delivered_oil", "_source_subsidy_delivered_gas_mcf", "_source_subsidy_start_time_delivered_gas", "_source_subsidy_stop_time_delivered_gas", "_no_new_gas", "_year_of_no_new_capacity_gas", "_utilization_adjustment_factor_delivered_gas", "_utilization_policy_start_time_delivered_gas", "_utilization_policy_stop_time_delivered_gas", "_source_subsidy_renewables_kwh", "_source_subsidy_start_time_renewables", "_source_subsidy_stop_time_renewables", "_use_subsidies_by_feedstock", "_source_subsidy_delivered_bio_boe", "_source_subsidy_start_time_delivered_bio", "_source_subsidy_stop_time_delivered_bio", "_no_new_bio", "_year_of_no_new_capacity_bio", "_wood_feedstock_subsidy_boe", "_crop_feedstock_subsidy_boe", "_other_feedstock_subsidy_boe", "_source_subsidy_nuclear_kwh", "_source_subsidy_start_time_nuclear", "_source_subsidy_stop_time_nuclear", "_carbon_tax_initial_target", "_carbon_tax_phase_1_start", "_carbon_tax_time_to_achieve_initial_target", "_carbon_tax_final_target", "_carbon_tax_phase_3_start", "_carbon_tax_time_to_achieve_final_target", "_apply_carbon_tax_to_biofuels", "_ccs_carbon_tax_qualifier", "_qualifying_path_renewables", "_qualifying_path_nuclear", "_qualifying_path_new_zero_carbon", "_qualifying_path_beccs", "_qualifying_path_bioenergy", "_qualifying_path_fossil_ccs", "_qualifying_path_gas", "_electric_standard_active", "_electric_standard_target", "_electric_standard_start_year", "_electric_standard_target_time", "_emissions_performance_standard", "_performance_standard_time"], "outcomes": {"Temperature above 1.5C": true, "Max cost of energy": true, "Government net revenue below zero": false, "Total energy below baseline": false}, "save_path": "results/pymoo/context-updated"} |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
""" | ||
Universal way to gain access to the input specs for the enroads model. | ||
""" | ||
from pathlib import Path | ||
|
||
import pandas as pd | ||
|
||
|
||
def load_input_specs() -> pd.DataFrame: | ||
""" | ||
Loads the input specs for the En-ROADS model from the inputSpecs.jsonl file. | ||
We make sure precise_float=True so that we get exact floats like 15 instead of 15.00001. | ||
""" | ||
return pd.read_json(Path("enroadspy/inputSpecs.jsonl"), lines=True, precise_float=True) |
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
""" | ||
Setup script to download the En-ROADS SDK. This is used for app deployment and testing. | ||
""" | ||
import os | ||
import zipfile | ||
|
||
import requests | ||
|
||
|
||
def main(): | ||
""" | ||
Downloads en-roads sdk and extracts it. | ||
If the sdk already exists, we do nothing. | ||
If we already have the zip file but no SDK, we just extract the zip file. | ||
""" | ||
zip_path = "enroadspy/en-roads-sdk-v24.6.0-beta1.zip" | ||
sdk_path = "enroadspy/" | ||
|
||
if os.path.exists(sdk_path + "en-roads-sdk-v24.6.0-beta1"): | ||
print("SDK already exists.") | ||
return | ||
|
||
if not os.path.exists(zip_path): | ||
url = os.getenv("ENROADS_URL") | ||
username = os.getenv("ENROADS_ID") | ||
password = os.getenv("ENROADS_PASSWORD") | ||
assert username is not None and password is not None, \ | ||
"Please set the ENROADS_ID and ENROADS_PASSWORD environment variables. \ | ||
To get access to them go to https://en-roads.climateinteractive.org/ and sign up." | ||
|
||
r = requests.get(url, auth=(username, password), timeout=60) | ||
|
||
if r.status_code == 200: | ||
with open(zip_path, "wb") as out: | ||
for bits in r.iter_content(): | ||
out.write(bits) | ||
|
||
with zipfile.ZipFile(zip_path, "r") as zip_ref: | ||
zip_ref.extractall(sdk_path) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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
Oops, something went wrong.