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

Miscellaneous enhancements for 2023-W44 #137

Merged
merged 64 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
dc3e339
Add .workflow.make_click_command()
khaeru Oct 30, 2023
0cacda5
Add .util.click.exec_cb for --nodes, --regions CLI options
khaeru Oct 30, 2023
4e48613
Add expose_value=False to some .click.PARAMS
khaeru Oct 30, 2023
4d6eecd
Remove XFAIL after #131 resolution
glatterf42 Oct 31, 2023
148952e
Adjust .model.cli
khaeru Oct 31, 2023
d2401fc
Defer importing the wf_callback in make_click_command()
khaeru Nov 2, 2023
160eb2d
Test make_click_command()
khaeru Nov 2, 2023
e38c5a9
Include .util.add_par_data in .report.computations
khaeru Nov 2, 2023
a37ffcc
Ignore verbose DEBUG logging from graphviz._tools
khaeru Nov 2, 2023
44e188d
Append a random string to scenario name of .testing.bare_res()
khaeru Nov 2, 2023
4c99c0c
Increase verbosity of CliRunner.assert_exit_0()
khaeru Nov 2, 2023
ac88663
Adjust fixtures in test_cli_export_test_data()
khaeru Nov 2, 2023
64a86d6
Improve test_make_click_command()
khaeru Nov 2, 2023
d63740c
Improve `wf` test fixture
khaeru Nov 2, 2023
edf7715
Add setup-graphviz to "pytest" CI workflow
khaeru Nov 2, 2023
be4bbb5
Set defaults for --nodes and --years
khaeru Nov 2, 2023
4120c4c
Quiet logging in process_units_anno()
khaeru Nov 2, 2023
a61e15d
Use silence_log() in report()
khaeru Nov 2, 2023
78dd01d
Test deprecated signature for report()
khaeru Nov 2, 2023
8bc6b3f
Also store 2+-D indexed sets in ScenarioInfo(scenario)
khaeru Nov 2, 2023
846bb4a
Add ExoDataSource.{name,extra_dims,transform}
khaeru Nov 3, 2023
97a3160
Document .add_par_data in .report.computations
khaeru Nov 3, 2023
f29bd91
Rename .report.computations → .report.operator
khaeru Nov 3, 2023
9082335
Add DeprecationWarning in .report.computations
khaeru Nov 3, 2023
96757b8
Adjust imports from .report.operator
khaeru Nov 3, 2023
6780bd2
Add archive_member, non_iso_3166 args
khaeru Nov 3, 2023
07ac8e4
Add .project.advance.data and tests
khaeru Nov 3, 2023
cf0311c
Expand docs of ADVANCE data source
khaeru Nov 3, 2023
37812cc
Add .tools.iamc.describe()
khaeru Nov 3, 2023
e65ed3a
Handle complete StructureMessage in .util.sdmx.write()
khaeru Nov 3, 2023
01bb5aa
Fix "clean-autosummary" rule in doc/Makefile
khaeru Nov 3, 2023
960624b
Test .iamc.describe()
khaeru Nov 3, 2023
e5229ff
Add data/sdmx/ADVANCE.xml
khaeru Nov 3, 2023
aa18a4e
Add .testing.cli
khaeru Nov 3, 2023
e03363d
Move "ssp make-test-data" CLI to "testing fuzz-private-data"
khaeru Nov 3, 2023
3922542
Expand "testing fuzz-private-data" for ADVANCE"
khaeru Nov 3, 2023
c19b848
Remove .tools.advance._fuzz_data
khaeru Nov 3, 2023
b600c29
Update ADVANCE data for testing; exclude from packaging
khaeru Nov 3, 2023
4682f42
Use package data in test_iamc.test_describe()
khaeru Nov 3, 2023
ff98668
Remove use of message_data.tools.gdp_pop in .report
khaeru Nov 3, 2023
d59e66d
Add .project.{gea,shape} placeholders
khaeru Nov 3, 2023
8357463
Add "fetch" CLI command; .util.pooch.{SOURCES,Unzip}
khaeru Nov 3, 2023
3d45cd2
Add archive of water data files
khaeru Nov 3, 2023
3405bcf
Add water.tar.xz to .pooch.SOURCE
khaeru Nov 4, 2023
848efbb
Temporarily use branch for #137 in .pooch.SOURCE
khaeru Nov 4, 2023
25acb07
Consolidate snapshot info with .pooch.SOURCE
khaeru Nov 4, 2023
0047523
Exclude data/water/ subdirectories from packaging
khaeru Nov 5, 2023
bf2fb9e
Remove outdated type exclusion in bare.get_spec()
khaeru Nov 5, 2023
40c7331
Handle basic sets first in build.apply_spec()
khaeru Nov 17, 2023
e174a64
Adjust doc/docstring refs to {ixmp,message_ix}.reporting
khaeru Nov 21, 2023
21598a2
Adjust imports from genno, {ixmp,message_ix}.report
khaeru Nov 21, 2023
9e135b0
Deprecate .util.iter_parameters()
khaeru Nov 21, 2023
6f4d2bb
Update .report.sim for iiasa/ixmp#500, iiasa/message_ix#761
khaeru Nov 22, 2023
924ee1c
Add and use .util.minimum_version()
khaeru Nov 22, 2023
5556533
Add minimum_version to .util.__all__
khaeru Nov 22, 2023
1a5e6cb
Improve local inventory finder for message_data
khaeru Nov 22, 2023
8edfc7e
Add config for ixmp.util.sphinx_linkcode_github
khaeru Nov 22, 2023
4b963b7
Update Sphinx configuration
khaeru Nov 22, 2023
9a296c5
Update test marks, satisfy mypy
khaeru Nov 22, 2023
4d3a5bb
Add ADVANCE.transform(), .util.iter_keys()
khaeru Nov 22, 2023
39b9c1a
Update deprecated imports
khaeru Nov 22, 2023
272e03f
Remove Sphinx built step from "pytest" CI workflow
khaeru Nov 23, 2023
e337cfe
Add #137 and contents to doc/whatsnew
khaeru Nov 23, 2023
5b52a7b
Satisfy mypy 1.7.0
khaeru Nov 23, 2023
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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ doc/whatsnew.rst merge=union
# Git LFS
*.gz filter=lfs diff=lfs merge=lfs -text
*.xlsx filter=lfs diff=lfs merge=lfs -text
*.xz filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
10 changes: 4 additions & 6 deletions .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ jobs:
version: 25.1.1
license: ${{ secrets.GAMS_LICENSE }}

- uses: ts-graphviz/setup-graphviz@v1
with:
macos-skip-brew-update: true

- name: Install packages and dependencies
# By default, install:
# - ixmp, message_ix: from GitHub branches/tags per matrix.upstream-version (above)
Expand Down Expand Up @@ -93,12 +97,6 @@ jobs:
--local-cache --jvmargs="-Xmx6G"
shell: bash

- name: Test documentation build using Sphinx
if: startsWith(matrix.version.os, 'ubuntu')
env:
RTD_TOKEN_MESSAGE_DATA: ${{ secrets.RTD_TOKEN_MESSAGE_DATA }}
run: make --directory=doc SPHINXOPTS="-n --color" html

- name: Upload test coverage to Codecov.io
uses: codecov/codecov-action@v3

Expand Down
3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
prune message_ix_models/data/test/advance
prune message_ix_models/data/test/MESSAGEix-GLOBIOM_1.1_R11_no-policy_baseline
prune message_ix_models/data/test/ssp
prune message_ix_models/data/water/*
exclude message_ix_models/data/water/*.tar.xz
2 changes: 1 addition & 1 deletion doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

clean-autosummary:
find . -name "$(BUILDDIR)" -prune -o -iname _autosummary -print0 | xargs -0 rmdir
find . -name "$(BUILDDIR)" -prune -o -iname _autosummary -print0 | xargs -0 rm -rf

.PHONY: help clean-autosummary Makefile

Expand Down
2 changes: 1 addition & 1 deletion doc/api/model-snapshot.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Usage

From the command line, download data for a single snapshot::

$ mix-models snapshot fetch 0
$ mix-models fetch snapshot-0

…where :program:`0` is the ID of a snapshot; see :data:`.SNAPSHOTS`.

Expand Down
19 changes: 18 additions & 1 deletion doc/api/project.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,23 @@ Specific research projects (:mod:`~message_ix_models.project`)
.. automodule:: message_ix_models.project
:members:

.. currentmodule:: message_ix_models.project.advance

ADVANCE (:mod:`.project.advance`)
=================================

.. automodule:: message_ix_models.project.advance

.. automodule:: message_ix_models.project.advance.data
:members:

Although free of charge, the ADVANCE data can not be downloaded automatically.
This source requires that users first submit personal information to register before being able to retrieve the data.
:mod:`message_ix_models` does not circumvent this requirement.
Thus:

- A copy of the data are stored in :mod:`message_data`.
- :mod:`message_ix_models` contains only a ‘fuzzed’ version of the data (same structure, random values) for testing purposes.

.. currentmodule:: message_ix_models.project.ssp

Expand Down Expand Up @@ -41,7 +58,7 @@ Data
.. automodule:: message_ix_models.project.ssp.data
:members:

Although free, neither the 2017 or 2024 SSP data can be downloaded automatically.
Although free of charge, neither the 2017 or 2024 SSP data can be downloaded automatically.
Both sources require that users first submit personal information to register before being able to retrieve the data.
:mod:`message_ix_models` does not circumvent this requirement.
Thus:
Expand Down
19 changes: 13 additions & 6 deletions doc/api/report/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ On this page:
Elsewhere:

- ``global.yaml``, the :doc:`default-config`.
- Documentation for :mod:`genno` (:doc:`genno:index`), :mod:`ixmp.reporting`, and :mod:`message_ix.reporting`.
- Documentation for :mod:`genno` (:doc:`genno:index`), :mod:`ixmp.report`, and :mod:`message_ix.report`.
- Reporting of specific model variants:

- :mod:`.water.reporting`
Expand Down Expand Up @@ -105,15 +105,16 @@ Plots
.. automodule:: message_ix_models.report.plot
:members:

.. currentmodule:: message_ix_models.report.computations
.. currentmodule:: message_ix_models.report.operator

Operators
---------

.. automodule:: message_ix_models.report.computations
.. automodule:: message_ix_models.report.operator
:members:
:exclude-members: add_par_data

:mod:`message_ix_models.report.computations` provides the following:
:mod:`message_ix_models.report.operator` provides the following:

.. autosummary::

Expand All @@ -129,12 +130,18 @@ Operators
remove_ts
share_curtailment

The following functions, defined elsewhere, are exposed through :mod:`.operator` and so can also be referenced by name:

.. autosummary::

message_ix_models.util.add_par_data

Other operators or genno-compatible functions are provided by:

- Upstream packages:

- :mod:`message_ix.reporting.computations`
- :mod:`ixmp.reporting.computations`
- :mod:`message_ix.report.operator`
- :mod:`ixmp.report.operator`
- :mod:`genno.computations`

- Other submodules:
Expand Down
11 changes: 11 additions & 0 deletions doc/api/tools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ Exogenous data (:mod:`.tools.exo_data`)
ADVANCE data (:mod:`.tools.advance`)
====================================

.. deprecated:: 2023.11
Use :mod:`.project.advance` instead.

.. autosummary::
get_advance_data
advance_data
Expand All @@ -86,3 +89,11 @@ With :mod:`message_data`:
:members:
:exclude-members: LOCATION
:private-members:

.. currentmodule:: message_ix_models.tools.iamc

IAMC data structures (:mod:`.tools.iamc`)
=========================================

.. automodule:: message_ix_models.tools.iamc
:members:
2 changes: 2 additions & 0 deletions doc/api/util.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Commonly used:
copy_column
ffill
identify_nodes
iter_keys
load_package_data
load_private_data
local_data_path
Expand All @@ -44,6 +45,7 @@ Commonly used:
make_source_tech
maybe_query
merge_data
minimum_version
~node.nodes_ex_world
package_data_path
private_data_path
Expand Down
2 changes: 1 addition & 1 deletion doc/api/workflow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ The generic pattern for workflows is:
- The same precursor scenario can be used as the basis for multiple target scenarios.
- A workflow is :meth:`.Workflow.run` starting with the earliest precursor scenario, ending with 1 or many target scenarios.

The implementation is based on the observation that these form a graph (specifically, a directed, acyclic graph, or DAG) of nodes (= scenarios) and edges (= steps), in the same way that :mod:`message_ix.reporting` calculations do; and so the :mod:`dask` DAG features (via :mod:`genno`) can be used to organize the workflow.
The implementation is based on the observation that these form a graph (specifically, a directed, acyclic graph, or DAG) of nodes (= scenarios) and edges (= steps), in the same way that :mod:`message_ix.report` calculations do; and so the :mod:`dask` DAG features (via :mod:`genno`) can be used to organize the workflow.

Usage
=====
Expand Down
26 changes: 24 additions & 2 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
# the documentation: https://www.sphinx-doc.org/en/master/usage/configuration.html

import os
from typing import TYPE_CHECKING
from pathlib import Path
from typing import TYPE_CHECKING, Optional

if TYPE_CHECKING:
import sphinx.application
Expand All @@ -21,6 +22,7 @@
# Add any Sphinx extension module names here, as strings. They can be extensions coming
# with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = [
# "ixmp.util.sphinx_linkcode_github",
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.extlinks",
Expand All @@ -39,6 +41,7 @@
# html_extra_path.
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

nitpicky = True
nitpick_ignore_regex = {
# These occur because there is no .. py:module:: directive for the *top-level*
# module or package in the respective documentation and inventories.
Expand Down Expand Up @@ -109,18 +112,32 @@ def setup(app: "sphinx.application.Sphinx") -> None:

# -- Options for sphinx.ext.intersphinx ------------------------------------------------


def local_inv(name: str, *parts: str) -> Optional[str]:
"""Construct the path to a local intersphinx inventory."""
if 0 == len(parts):
parts = ("doc", "_build", "html")

from importlib.util import find_spec

spec = find_spec(name)
if spec and spec.origin:
return str(Path(spec.origin).parents[1].joinpath(*parts, "objects.inv"))


# For message-data, see: https://docs.readthedocs.io/en/stable/guides
# /intersphinx.html#intersphinx-with-private-projects
_token = os.environ.get("RTD_TOKEN_MESSAGE_DATA", "")

intersphinx_mapping = {
"click": ("https://click.palletsprojects.com/en/8.1.x/", None),
"genno": ("https://genno.readthedocs.io/en/stable", None),
"ixmp": ("https://docs.messageix.org/projects/ixmp/en/latest/", None),
"message-ix": ("https://docs.messageix.org/en/latest/", None),
"m-data": (
f"https://{_token}:@docs.messageix.org/projects/models-internal/en/latest/",
# Use a local copy of objects.inv, if the user has one
(None, "message_data.inv"),
(local_inv("message_data"), None),
),
"pandas": ("https://pandas.pydata.org/pandas-docs/stable/", None),
"pint": ("https://pint.readthedocs.io/en/stable/", None),
Expand All @@ -130,8 +147,13 @@ def setup(app: "sphinx.application.Sphinx") -> None:
"sdmx": ("https://sdmx1.readthedocs.io/en/stable/", None),
}

# -- Options for sphinx.ext.linkcode / ixmp.util.sphinx_linkcode_github ----------------

linkcode_github_repo_slug = "iiasa/message-ix-models"

# -- Options for sphinx.ext.napoleon ---------------------------------------------------

napoleon_preprocess_types = True
napoleon_type_aliases = {
"Code": ":class:`~sdmx.model.common.Code`",
"Path": ":class:`~pathlib.Path`",
Expand Down
40 changes: 39 additions & 1 deletion doc/whatsnew.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,45 @@ What's new
Next release
============

Migration notes
---------------
Update code that imports from the following modules:

- :py:`message_ix_models.report.computations` → use :py:`message_ix_models.report.operator`.

Code that imports from the old locations will continue to work, but will raise :class:`DeprecationWarning`.

Data for :doc:`water` is no longer included in the PyPI distributions for :mod:`message_ix_models`.
This reduces the package size from >20 MB to <5 MB.
To automatically download and unpack these data into a local directory, use :program:`mix-models fetch MESSAGEix-Nexus`.

All changes
-----------

- Improve :class:`.ExoDataSource` (:pull:`137`):

- New attributes :attr:`~.ExoDataSource.name`, :attr:`~.ExoDataSource.extra_dims`.
- New method :meth:`~.ExoDataSource.transform` that can be overridden by subclasses.
- New arguments :py:`archive_member`, :py:`non_iso_3166` to :func:`.iamc_like_data_for_query`.

- New provider for exogenous data from the :class:`.ADVANCE` project (:pull:`137`).
This module, :mod:`.project.advance`, supersedes :mod:`.tools.advance` and its idiosyncratic API, which are deprecated.
- New CLI commands (:pull:`137`):

- :program:`mix-models testing fuzz-private-data`, superseding :program:`mix-models ssp make-test-data`.
- :program:`mix-models fetch`, superseding :program:`mix-models snapshot fetch`.

- New utility functions (:pull:`137`).

- :func:`.tools.iamc.describe` to generate SDMX code lists that describe the structure of particular IAMC-format data (:pull:`137`).
- :func:`.workflow.make_click_command` to generate :mod:`click` commands for any :class:`.Workflow`.
- :func:`.util.minimum_version` to ensure compatibility with upstream packages and aid test writing.
- :func:`.util.iter_keys` to generate keys for chains of :mod:`genno` computations.

- Add :mod:`message_ix_models.report.compat` :ref:`for emulating legacy reporting <report-legacy>` (:pull:`134`).
- Rename :mod:`message_ix_models.report.operator` (:pull:`137`).
- Deprecate :py:`iter_parameters()` in favour of :meth:`ixmp.Scenario.par_list` with :py:`indexed_by=...` argument from ixmp v3.8.0 (:pull:`137`).


v2023.10.16
===========
Expand Down Expand Up @@ -218,7 +256,7 @@ Earlier releases
---------

- Migrate :mod:`.model.bare`, :mod:`.model.build`, :mod:`.model.cli`, and associated documentation (:pull:`9`)
- Migrate utilities: :class:`.ScenarioInfo`, :func:`.add_par_data`, :func:`.eval_anno`, :func:`.iter_parameters`, and :func:`.strip_par_data`.
- Migrate utilities: :class:`.ScenarioInfo`, :func:`.add_par_data`, :func:`.eval_anno`, :py:`iter_parameters()`, and :func:`.strip_par_data`.

2021.3.3
--------
Expand Down
3 changes: 2 additions & 1 deletion message_ix_models/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,12 @@ def debug(ctx):
#: or @click.group.
submodules = [
"message_ix_models.model.cli",
"message_ix_models.model.snapshot",
"message_ix_models.model.structure",
"message_ix_models.model.water.cli",
"message_ix_models.project.ssp",
"message_ix_models.report.cli",
"message_ix_models.testing.cli",
"message_ix_models.util.pooch",
]

try:
Expand Down
2 changes: 1 addition & 1 deletion message_ix_models/data/report/global.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ units:

# Filters
#
# These limit the data that is retrieved from the backend by ixmp.reporting;
# These limit the data that is retrieved from the backend by ixmp.report;
# so ALL quantities in the Reporter are limited to these values. Use these for
# debugging.

Expand Down
Loading