Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ on:
- cron: "0 5 * * *"

env:
GAMS_VERSION: 25.1.1
# See description in lint.yml
depth: 100

Expand Down Expand Up @@ -55,10 +54,10 @@ jobs:
~/appdata/local/pip/cache
key: gams${{ env.GAMS_VERSION }}

- name: Install GAMS
env:
CI_OS: ubuntu
run: ixmp/ci/install-gams.sh
- uses: iiasa/actions/setup-gams@main
with:
version: 25.1.1
license: ${{ secrets.GAMS_LICENSE }}

- name: Install Python packages and dependencies
run: |
Expand Down
20 changes: 7 additions & 13 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ on:
branches: [ master ]

env:
GAMS_VERSION: 25.1.1
# See description in lint.yml
depth: 100

Expand All @@ -18,7 +17,8 @@ jobs:
os:
- macos-latest
- ubuntu-latest
- windows-latest
# Temporary excluded; see https://github.com/iiasa/message_ix/pull/452
# - windows-latest
python-version:
- "3.6" # Earliest version supported by ixmp
- "3.8" # Latest version testable on GitHub Actions
Expand Down Expand Up @@ -107,18 +107,12 @@ jobs:
${{ matrix.os }}-gams${{ env.GAMS_VERSION }}-
${{ matrix.os }}-

- name: Install GAMS and Graphviz
# Use the scripts from the checked-out ixmp repo
env:
CI_OS: ${{ matrix.os }}
run: |
ixmp/ci/install-gams.sh
ixmp/ci/install-graphviz.sh
shell: bash
- uses: iiasa/actions/setup-gams@main
with:
version: 25.1.1
license: ${{ secrets.GAMS_LICENSE }}

- name: Check GAMS
run: gams
shell: bash
- uses: ts-graphviz/setup-graphviz@v1

- name: Upgrade pip, wheel, setuptools-scm
run: python -m pip install --upgrade pip wheel setuptools-scm
Expand Down
1 change: 0 additions & 1 deletion ci/nightly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ path: continuous_integration/scenario_db/

filename:
data: db.tar.gz
license: gamslice.txt
32 changes: 5 additions & 27 deletions message_ix/testing/nightly.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import tarfile
from asyncio import get_event_loop
from pathlib import Path
from subprocess import check_output

import click
import ixmp
Expand Down Expand Up @@ -46,23 +45,6 @@ def download(path, cli=False):
with tarfile.open(data_path, "r:gz") as tf:
tf.extractall(path)

# Download license
if cli:
gams_dir = path
log.info("Downloading GAMS license to {}".format(gams_dir))
else:
which_gams = check_output(["which", "gams"], universal_newlines=True)
gams_dir = Path(which_gams.strip()).parent
log.info("Located GAMS executable in {}".format(gams_dir))

fn = cfg["filename"]["license"]
url = cfg["http base"] + cfg["path"] + fn
log.info("Downloading from {}".format(url))

r = requests.get(url, auth=auth)
r.raise_for_status()
(gams_dir / fn).write_text(r.text)


def fetch_scenarios(path, dbprops):
mp = ixmp.Platform(dbprops=dbprops)
Expand All @@ -75,13 +57,11 @@ def iter_scenarios():
try:
with open(HERE.parent / "tests" / "data" / "scenarios.yaml", "r") as f:
scenarios = yaml.safe_load(f)

except FileNotFoundError as e:
msg = (
"Caught error: {}. Did you install message_ix using `$ pip "
"install --editable`?".format(str(e))
raise FileNotFoundError(
f"Caught error: {e}. Did you install message_ix using `pip install "
"--editable`?"
)
raise FileNotFoundError(msg)

for id, data in scenarios.items():
yield id, (
Expand Down Expand Up @@ -120,7 +100,6 @@ async def _upload(path, username, password):
) as conn:
target = (conn, cfg["ssh"]["base"] + cfg["path"])
await scp(path / cfg["filename"]["data"], target)
await scp(path / cfg["filename"]["license"], target)


@click.group("nightly")
Expand Down Expand Up @@ -189,9 +168,8 @@ def make(context):
def upload_cmd(context, username, password):
"""Upload the test database and license file.

The two files are uploaded using SCP to a location that is also accessible
via HTTP. You must provide your SSH USERNAME; and will be prompted for your
password.
The two files are uploaded using SCP to a location that is also accessible via HTTP.
You must provide your SSH USERNAME; and will be prompted for your password.
"""
upload(context["path"], username, password)

Expand Down
2 changes: 1 addition & 1 deletion message_ix/tests/reporting/test_computations.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
def test_as_pyam(message_test_mp):
scen = Scenario(message_test_mp, **SCENARIO["dantzig"])
if not scen.has_solution():
scen.solve()
scen.solve(quiet=True)
rep = Reporter.from_scenario(scen)

# Quantities for 'ACT' variable at full resolution
Expand Down
6 changes: 3 additions & 3 deletions message_ix/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ def test_rename_technology(dantzig_message_scenario):
clone.rename("technology", {"canning_plant": "foo_bar"})
assert not clone.par("output")["technology"].isin(["canning_plant"]).any()
assert clone.par("output")["technology"].isin(["foo_bar"]).any()
clone.solve()
clone.solve(quiet=True)
assert np.isclose(clone.var("OBJ")["lvl"], 153.675)


Expand Down Expand Up @@ -463,7 +463,7 @@ def test_excel_read_write(message_test_mp, tmp_path):
scen1.to_excel(fname)

# Writing to Excel when scenario has a solution
scen1.solve()
scen1.solve(quiet=True)
scen1.to_excel(fname)

scen2 = Scenario(message_test_mp, model="foo", scenario="bar", version="new")
Expand All @@ -482,7 +482,7 @@ def test_excel_read_write(message_test_mp, tmp_path):
assert scen2.has_par("new_par")
assert float(scen2.par("new_par")["value"]) == 2

scen2.solve()
scen2.solve(quiet=True)
assert np.isclose(scen2.var("OBJ")["lvl"], scen1.var("OBJ")["lvl"])


Expand Down
6 changes: 3 additions & 3 deletions message_ix/tests/test_feature_addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def test_addon_tec(message_test_mp):
scen.add_par("bound_activity_up", bda)
scen.commit("changing output and bounds")

scen.solve()
scen.solve(quiet=True)

exp = scen.var("ACT", f)["lvl"]
obs = scen.var("ACT", g)["lvl"]
Expand All @@ -105,7 +105,7 @@ def test_addon_up(message_test_mp):
scen.add_par("addon_up", addon_share)
scen.commit("adding upper bound on addon technology")

scen.solve()
scen.solve(quiet=True)

exp = scen.var("ACT", f)["lvl"] * 0.5
obs = scen.var("ACT", g)["lvl"]
Expand All @@ -124,7 +124,7 @@ def test_addon_lo(message_test_mp):
scen.add_par("addon_lo", addon_share)

scen.commit("adding lower bound on addon technology")
scen.solve()
scen.solve(quiet=True)

exp = scen.var("ACT", f)["lvl"] * 0.5
obs = scen.var("ACT", g)["lvl"]
Expand Down
16 changes: 8 additions & 8 deletions message_ix/tests/test_feature_bound_activity_shares.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_add_bound_activity_up(message_test_mp):
clone.check_out()
clone.add_par("bound_activity_up", data)
clone.commit("foo")
clone.solve()
clone.solve(quiet=True)
obs = calculate_activity(clone).loc["to_chicago"]
assert np.isclose(obs, exp)

Expand Down Expand Up @@ -69,7 +69,7 @@ def test_add_bound_activity_up_all_modes(message_test_mp):
clone.check_out()
clone.add_par("bound_activity_up", data)
clone.commit("foo")
clone.solve()
clone.solve(quiet=True)
obs = calculate_activity(clone).sum()
assert np.isclose(obs, exp)

Expand Down Expand Up @@ -169,7 +169,7 @@ def add_data(s, map_df):
clone.check_out()
add_data(clone, map_df)
clone.commit("foo")
clone.solve()
clone.solve(quiet=True)

# check shares new, should be lower than expected bound
obs = calc_share(clone)
Expand Down Expand Up @@ -197,7 +197,7 @@ def add_data(s, map_df):
clone2.check_out()
add_data(clone2, map_df2)
clone2.commit("foo")
clone2.solve()
clone2.solve(quiet=True)

# check shares new, should be lower than expected bound
obs2 = calc_share(clone2)
Expand All @@ -214,7 +214,7 @@ def add_data(s, map_df):

def test_share_commodity_lo(message_test_mp):
scen = Scenario(message_test_mp, **SCENARIO["dantzig"]).clone()
scen.solve()
scen.solve(quiet=True)

# data for share bound
def calc_share(s):
Expand Down Expand Up @@ -277,7 +277,7 @@ def calc_share(s):
),
)
clone.commit("foo")
clone.solve()
clone.solve(quiet=True)
obs = calc_share(clone)
assert np.isclose(obs, exp)

Expand Down Expand Up @@ -319,7 +319,7 @@ def calc_share(s):
),
)
clone.commit("foo")
clone.solve()
clone.solve(quiet=True)
obs = calc_share(clone)
assert np.isclose(obs, exp)

Expand Down Expand Up @@ -361,7 +361,7 @@ def calc_share(s):
),
)
clone.commit("foo")
clone.solve()
clone.solve(quiet=True)

obs = calc_share(clone)
assert np.isclose(obs, exp)
Expand Down
6 changes: 3 additions & 3 deletions message_ix/tests/test_feature_bound_emission.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_bound_emission_year(test_mp):
model_setup(scen, [2020, 2030])
scen.commit("initialize test model")
add_bound_emission(scen, bound=1.250, year=2020)
scen.solve(case="bound_emission_year")
scen.solve(case="bound_emission_year", quiet=True)
assert_function(scen, year=2020)


Expand All @@ -62,7 +62,7 @@ def test_bound_emission_10y(test_mp):
model_setup(scen, [2020, 2030, 2040, 2050])
scen.commit("initialize test model")
add_bound_emission(scen, bound=1.250)
scen.solve(case="bound_emission_10y")
scen.solve(case="bound_emission_10y", quiet=True)
assert_function(scen, year="cumulative")


Expand All @@ -72,5 +72,5 @@ def test_bound_emission_5y(test_mp):
model_setup(scen, [2020, 2025, 2030, 2040])
scen.commit("initialize test model")
add_bound_emission(scen, bound=1.250)
scen.solve(case="bound_emission_5y")
scen.solve(case="bound_emission_5y", quiet=True)
assert_function(scen, year="cumulative")
4 changes: 2 additions & 2 deletions message_ix/tests/test_feature_price_commodity.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_commodity_price(test_mp):
scen = Scenario(test_mp, "test_commodity_price", "standard", version="new")
model_setup(scen)
scen.commit("initialize test model")
scen.solve(case="price_commodity_standard")
scen.solve(case="price_commodity_standard", quiet=True)

assert scen.var("OBJ")["lvl"] == 1
assert scen.var("PRICE_COMMODITY")["lvl"][0] == 1
Expand All @@ -42,7 +42,7 @@ def test_commodity_price_equality(test_mp):
scen.check_out()
scen.add_set("balance_equality", ["comm", "level"])
scen.commit("set commodity-balance for `[comm, level]` as equality")
scen.solve(case="price_commodity_equality")
scen.solve(case="price_commodity_equality", quiet=True)

assert scen.var("OBJ")["lvl"] == -1
assert scen.var("PRICE_COMMODITY")["lvl"][0] == -1
14 changes: 7 additions & 7 deletions message_ix/tests/test_feature_price_emission.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def test_cumulative_equidistant(test_mp):
scen.add_cat("year", "cumulative", years)
scen.add_par("bound_emission", ["World", "ghg", "all", "cumulative"], 0, "tCO2")
scen.commit("initialize test scenario")
scen.solve()
scen.solve(quiet=True)

# with emissions constraint, the technology with costs satisfies demand
assert scen.var("OBJ")["lvl"] > 0
Expand All @@ -101,7 +101,7 @@ def test_per_period_equidistant(test_mp):
scen.add_cat("year", y, y)
scen.add_par("bound_emission", ["World", "ghg", "all", y], 0, "tCO2")
scen.commit("initialize test scenario")
scen.solve()
scen.solve(quiet=True)

# with emissions constraint, the technology with costs satisfies demand
assert scen.var("OBJ")["lvl"] > 0
Expand All @@ -118,7 +118,7 @@ def test_cumulative_variable_periodlength(test_mp):
scen.add_cat("year", "cumulative", years)
scen.add_par("bound_emission", ["World", "ghg", "all", "cumulative"], 0, "tCO2")
scen.commit("initialize test scenario")
scen.solve()
scen.solve(quiet=True)

# with an emissions constraint, the technology with costs satisfies demand
assert scen.var("OBJ")["lvl"] > 0
Expand All @@ -137,7 +137,7 @@ def test_per_period_variable_periodlength(test_mp):
scen.add_cat("year", y, y)
scen.add_par("bound_emission", ["World", "ghg", "all", y], 0, "tCO2")
scen.commit("initialize test scenario")
scen.solve()
scen.solve(quiet=True)

# with an emissions constraint, the technology with costs satisfies demand
assert scen.var("OBJ")["lvl"] > 0
Expand All @@ -156,7 +156,7 @@ def test_custom_type_variable_periodlength(test_mp):
scen.add_par("bound_emission", ["World", "ghg", "all", "custom"], 0, "tCO2")

scen.commit("initialize test scenario")
scen.solve()
scen.solve(quiet=True)

# with an emissions constraint, the technology with costs satisfies demand
assert scen.var("OBJ")["lvl"] > 0
Expand All @@ -177,7 +177,7 @@ def test_price_duality(test_mp):
"bound_emission", ["World", "ghg", "all", "cumulative"], 0.5, "tCO2"
)
scen.commit("initialize test scenario")
scen.solve()
scen.solve(quiet=True)

# set up a new scenario with emissions taxes
tax_scen = Scenario(test_mp, MODEL, "tax_many_tecs", version="new")
Expand All @@ -192,7 +192,7 @@ def test_price_duality(test_mp):
taxes["unit"] = "USD/tCO2"
tax_scen.add_par("tax_emission", taxes)
tax_scen.commit("initialize test scenario for taxes")
tax_scen.solve()
tax_scen.solve(quiet=True)

# check that emissions are close between cumulative and tax scenario
filters = {"node": "World"}
Expand Down
Loading