Skip to content

Commit

Permalink
Merge pull request #27 from blnicho/fix-tests
Browse files Browse the repository at this point in the history
Get tests running and enable PR/branch testing on GHA
  • Loading branch information
blnicho authored Jan 15, 2025
2 parents b700338 + d7a014f commit 4c662ac
Show file tree
Hide file tree
Showing 15 changed files with 387 additions and 218 deletions.
89 changes: 89 additions & 0 deletions .github/workflows/test_branches.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: GitHub Branch CI

on:
push:
branches-ignore:
- main
workflow_dispatch:
inputs:
git-ref:
description: Git Hash (Optional)
required: false

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

defaults:
run:
# -l: login shell, needed when using Conda run:
shell: bash -l {0}

jobs:
code-formatting:
name: Check code formatting (Black)
# OS and/or Python version don't make a difference, so we choose ubuntu and 3.10 for performance
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install Black
run: |
pip install black
- name: Run Black to verify that the committed code is formatted
run: |
black --check --diff .
spell-check:
name: Check Spelling
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v4
- name: Run Spell Checker
uses: crate-ci/typos@master
with:
config: ./.github/workflows/typos.toml

build:
name: ${{ matrix.os }}/${{ matrix.python }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
python: [3.9, '3.10', '3.11', '3.12']
steps:
- name: Checkout source
uses: actions/checkout@v4

- name: Set up Miniconda Python
uses: conda-incubator/setup-miniconda@v3
with:
python-version: ${{ matrix.python }}

- name: Install Python packages (conda)
run: |
# Set up environment
conda config --set always_yes yes
conda config --set auto_update_conda false
conda config --remove channels defaults
conda config --append channels nodefaults
conda config --append channels conda-forge
echo "Install Python packages"
conda install --yes --quiet pip setuptools wheel
conda install --yes --quiet scipy pyomo pytest highspy
echo "Final conda environment:"
conda list | sed 's/^/ /'
- name: Install idaes-gtep
run: |
pip install -e .
- name: Run Tests
run: |
pytest -v gtep
44 changes: 30 additions & 14 deletions .github/workflows/test_pr_and_main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ on:
pull_request:
branches:
- main
types:
- opened
- reopened
- synchronize
- ready_for_review
workflow_dispatch:
inputs:
git-ref:
Expand All @@ -29,18 +34,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install Black
# unlike the other jobs, we don't need to install IDAES and/or all the dev dependencies,
# but we still want to specify the Black version to use in requirements-dev.txt for local development
# so we extract the relevant line and pass it to a simple `pip install`
run: |
pip install black
- name: Run Black to verify that the committed code is formatted
run: |
black --check .
black --check --diff .
spell-check:
name: Check Spelling
Expand All @@ -58,25 +60,39 @@ jobs:
needs: [code-formatting, spell-check]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
python: [3.9, '3.10', '3.11']
python: [3.9, '3.10', '3.11', '3.12']
steps:
- name: Checkout source
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v4

- name: Set up Miniconda Python
uses: conda-incubator/setup-miniconda@v3
with:
python-version: ${{ matrix.python }}
- name: Install Pyomo

- name: Install Python packages (conda)
run: |
pip install git+https://github.com/Pyomo/pyomo.git
# Set up environment
conda config --set always_yes yes
conda config --set auto_update_conda false
conda config --remove channels defaults
conda config --append channels nodefaults
conda config --append channels conda-forge
echo "Install Python packages"
conda install --yes --quiet pip setuptools wheel
conda install --yes --quiet scipy pyomo pytest highspy
echo "Final conda environment:"
conda list | sed 's/^/ /'
- name: Install idaes-gtep
run: |
python setup.py develop
pip install -e .
- name: Run Tests
run: |
pip install pytest
pip install highspy
pytest -v gtep
5 changes: 5 additions & 0 deletions .github/workflows/typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ extend-exclude = ["*.eps"]
# Ignore IDAES
IDAES = "IDAES"
idaes = "idaes"
# Ignore ND
ND = "ND"
nd = "nd"
# Ignore opf
opf = "opf"
54 changes: 49 additions & 5 deletions gtep/config_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,34 @@

def _get_model_config():
CONFIG = ConfigBlock("GTEPModelConfig")

CONFIG.declare(
"include_planning",
ConfigValue(
default=True,
domain=Bool,
description="Enable inclusion of any investment options.",
),
)

CONFIG.declare(
"include_commitment",
ConfigValue(
default=True,
domain=Bool,
description="Include unit commitment formulation.",
),
)

CONFIG.declare(
"include_dispatch",
ConfigValue(
default=True,
domain=Bool,
description="Include economic dispatch formulation (i.e., OPF).",
),
)

CONFIG.declare(
"flow_model",
ConfigValue(
Expand All @@ -27,25 +55,42 @@ def _get_model_config():
description="Power flow approximation to use.",
),
)

CONFIG.declare(
"time_period_subsets",
ConfigList(
description="Time period counts for fixed-length and fixed-subset periods."
),
)

CONFIG.declare(
"time_period_dict",
ConfigDict(
description="Time period dict, specified as \{(investment period #, length): \{(commitment period #, length): \{dispatch period #: length\}\}\}"
description=r"Time period dict, specified as \{(investment period #, length): \{(commitment period #, length): \{dispatch period #: length\}\}\}"
),
)

CONFIG.declare(
"dispatch_randomizations",
"dispatch_randomization",
ConfigValue(
default=True,
domain=Bool,
description="Introduces random dispatch information rather than having fixed values per-commitment period.",
description="Introduces random dispatch information rather than having fixed values per commitment period.",
),
)
return CONFIG


def _add_common_configs(CONFIG):
pass

CONFIG.declare(
"scale_loads",
ConfigValue(
default=False,
domain=Bool,
description="Allow scaling of load values into future years; i.e., load scaling is represented in the model but not the data.",
),
)


def _add_investment_configs(CONFIG):
Expand Down Expand Up @@ -79,7 +124,6 @@ def _add_investment_configs(CONFIG):
description="Include transmission investment options",
),
)
pass


def _add_solver_configs(CONFIG):
Expand Down
7 changes: 1 addition & 6 deletions gtep/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@
data_object.load_prescient(data_path)

mod_object = ExpansionPlanningModel(
stages=2,
data=data_object.md,
num_reps=2,
len_reps=1,
num_commit=6,
num_dispatch=4,
stages=2, data=data_object.md, num_reps=2, len_reps=1, num_commit=6, num_dispatch=4
)
mod_object.create_model()
TransformationFactory("gdp.bound_pretransformation").apply_to(mod_object.model)
Expand Down
15 changes: 5 additions & 10 deletions gtep/driver_config_test.py → gtep/driver_config_work.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,15 @@
data_object.load_prescient(data_path)



mod_object = ExpansionPlanningModel(
stages=1,
data=data_object.md,
num_reps=1,
len_reps=1,
num_commit=24,
num_dispatch=4,
stages=1, data=data_object.md, num_reps=1, len_reps=1, num_commit=24, num_dispatch=4
)

for k,v in mod_object.config.items():
ic(k,v)
for k, v in mod_object.config.items():
print(f"k: {k}", f"v: {v}")

quit()

exit()

mod_object.create_model()

Expand Down
6 changes: 2 additions & 4 deletions gtep/driver_jsc.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
opt = Highs()
# opt = SolverFactory("gurobi", solver_io="python")
# opt = Gurobi()
#mod_object.results = opt.solve(mod_object.model, tee=True)
# mod_object.results = opt.solve(mod_object.model, tee=True)
mod_object.results = opt.solve(mod_object.model)


Expand All @@ -48,9 +48,7 @@
if load_numerical_results:
sol_object.read_json("./gtep_solution_jscTest.json")
# sol_object.read_json("./gtep_solution.json")
#sol_object.read_json("./bigger_longer_wigglier_gtep_solution.json")
# sol_object.read_json("./bigger_longer_wigglier_gtep_solution.json")
plot_results = True
if plot_results:
sol_object.plot_levels(save_dir="./plots/")

pass
Loading

0 comments on commit 4c662ac

Please sign in to comment.