Skip to content

Commit

Permalink
Merge pull request #416 from iiasa/issue/415
Browse files Browse the repository at this point in the history
Improve testing for v3.3; misc cleanup
  • Loading branch information
khaeru authored May 26, 2021
2 parents 0188de0 + 1bfdbdd commit ef075f8
Show file tree
Hide file tree
Showing 39 changed files with 2,001 additions and 1,968 deletions.
32 changes: 8 additions & 24 deletions .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,41 +99,25 @@ jobs:
- name: Install Python package and dependencies
run: pip install .[tests]

- name: Install R package and dependencies
- name: Install R dependencies and tutorial requirements
run: |
install.packages("remotes")
remotes::install_cran(c("rcmdcheck", "IRkernel"))
remotes::install_deps("rixmp", upgrade = "never", dependencies = TRUE)
remotes::install_cran(
c("IRkernel", "reticulate"),
dependencies = TRUE,
# force = TRUE,
)
IRkernel::installspec()
# commented: for debugging
# print(reticulate::py_config())
# reticulate::py_run_string("import os; print(os.environ)")
# For R tutorial notebooks, run via the pytest suite: set up R kernel;
# actually install the R package
IRkernel::installspec()
remotes::install_local(
"rixmp",
force = TRUE,
INSTALL_opts = c("--no-multiarch"),
)
shell: Rscript {0}

- name: Run test suite using pytest
run: pytest ixmp -m "not performance" --verbose -rA --cov-report=xml --color=yes

- name: Run R CMD check
# Temporarily disabled: see https://github.com/iiasa/ixmp/issues/403
if: false
run: |
rcmdcheck::rcmdcheck(
"rixmp",
args = c("--no-manual", "--as-cran", "--no-multiarch"),
error_on = "warning",
check_dir = "check"
)
shell: Rscript {0}

- name: Test documentation build using Sphinx
if: matrix.python-version != '3.6'
run: make --directory=doc html
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ rixmp/source/inst/docum/*.html
*.pid
coverage.xml
htmlcov
prof/

# JetBrains IDEs
*.iml
Expand Down
9 changes: 9 additions & 0 deletions RELEASE_NOTES.rst
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
.. _v3.3.0:

Next release
============

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

- :pull:`416`:

- Add ``ixmp config show`` CLI command.
- Add :mod:`genno` and :mod:`message_ix_models` to the output of :func:`show_versions` / ``ixmp show-versions``.
- Clean up test suite, improve performance, increase coverage ().

- Deprecate :func:`.utils.logger` (:pull:`399`).
- Add a `quiet` option to :meth:`.GAMSModel.solve` and use in testing (:pull:`399`).
- :pull:`398`:

- Fix :class:`.GAMSModel` would try to write GDX data to filenames containing invalid characters on Windows.
- Format user-friendly exceptions when GAMSModel errors (:issue:`383`).

- :pull:`397`: Adjust :mod:`ixmp.reporting` to use :mod:`genno`.
- :pull:`396`: Fix two minor bugs in reporting.

Expand Down
1 change: 1 addition & 0 deletions doc/api-backend.rst
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ Backend API
get_scenarios
get_scenario_names
get_units
handle_config
open_db
read_file
remove_meta
Expand Down
43 changes: 17 additions & 26 deletions doc/api-r.rst
Original file line number Diff line number Diff line change
@@ -1,39 +1,30 @@
.. _rixmp:

R (``rixmp`` package)
*********************
Usage in R via ``reticulate``
*****************************

An R interface to the `ixmp` is provided by the ``rixmp`` package.
``rixmp`` uses the `reticulate <https://rstudio.github.io/reticulate/>`_ R-to-Python adapter to provide access to all features of the :mod:`ixmp` *Python* package
:mod:`ixmp` is fully usable in R via `reticulate`_, a package that allows nearly seamless access to the Python API.
No additional R packages are needed.

.. code-block:: R
# Load the rixmp package
library(rixmp)
ixmp <- import('ixmp')
# An 'ixmp' object is added to the global namespace.
# It can be used in the same way as the Python ixmp package.
mp <- ixmp$Platform(dbtype = 'HSQLDB')
scen <- ixmp$Scenario(mp, 'model name', 'scenario name', version = 'new')
.. note:: The former ``rixmp`` package was removed in :mod:`ixmp` :ref:`v3.3.0`.

# etc.
See :ref:`message_ix:install-r` for installing R and `reticulate`_ to use with :mod:`ixmp`.
Those instructions are suitable whether :mod:`message_ix` is also installed, or only :mod:`ixmp`.

One additional method, :meth:`adapt_to_ret` is provided.
Access its documentation with
Once installed, use reticulate to import the Python package:

.. code-block:: R
?rixmp::adapt_to_ret
library(reticulate)
ixmp <- import("ixmp")
This function is useful when adding :class:`data.frames` objects to a Scenario:
This creates a global variable, ``ixmp``, that can be used much like the Python module:

.. code-block:: R
scen$init_set("i")
i.set = c("seattle", "san-diego")
scen$add_set("i", i.set)
# load dataframes
scen$init_par("a", c("i"))
a.df = data.frame(i = i.set, value = c(350, 600) , unit = 'cases')
scen$add_par("a", adapt_to_ret(a.df))
mp <- ixmp$Platform(name = 'default')
scen <- ixmp$Scenario(mp, 'model name', 'scenario name', version = 'new')
Finally, see the R versions of the :doc:`tutorials`.

.. _reticulate: https://rstudio.github.io/reticulate/
2 changes: 1 addition & 1 deletion doc/file-io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,4 @@ Multiple dimensions indexed by the same set
File formats other than :file:`.xlsx`
The :file:`.xlsx` (Office Open XML) file format is preferred for input and output.
:mod:`ixmp` uses `openpyxl <https://openpyxl.readthedocs.io>`_ and :mod:`pandas` in order to read and write this format.
For other Excel file formats, including :file:`.xls` and :file:`.xlsb`, see the :pandas:ref:`Pandas documentation <io.excel>`.
For other Excel file formats, including :file:`.xls` and :file:`.xlsb`, see the :ref:`Pandas documentation <pandas:io.excel>`.
55 changes: 3 additions & 52 deletions doc/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ The sections below cover other use cases.
Ensure you have first read the :doc:`prerequisites <prereqs>` for understanding and using |MESSAGEix|.
These include specific points of knowledge that are necessary to understand these instructions and choose among different installation options.

To use :mod:`ixmp` from R, see :ref:`message_ix:install-r` in the |MESSAGEix| documentation.

Use cases for installing ixmp directly include:

- Installing *ixmp* to be used alone (i.e., with models or frameworks other than |MESSAGEix|).
Expand All @@ -21,13 +23,6 @@ Use cases for installing ixmp directly include:
- `Install system dependencies`_, then
- `From source`_.

- Installing the :doc:`rixmp <api-r>` R package, to use the :mod:`ixmp`, alone, from R.
Again, to use |MESSAGEix| from R, it is sufficient to install ``rmessageix``; and not necessary to also/separately install ``rximp``.

- Start with `Install system dependencies`_.
- Then install :mod:`ixmp` from source.
- Finally, see `Install rixmp`_.

**Contents:**

.. contents::
Expand Down Expand Up @@ -123,7 +118,7 @@ From source

4. (Optional) If you intend to contribute changes to *ixmp*, first register a Github account, and fork the `ixmp repository <https://github.com/iiasa/ixmp>`_.
This will create a new repository ``<user>/ixmp``.
(Please also see :message_ix:doc:`contributing`.)
(Please also see :doc:`message_ix:contributing`.)

5. Clone either the main repository, or your fork; using the `Github Desktop`_ client, or the command line::

Expand All @@ -144,42 +139,6 @@ From source
$ pytest


Install ``rixmp``
=================

``rixmp`` is the R interface to :mod:`ixmp`; see :doc:`its documentaiton <api-r>`.
You only need to install ``rixmp`` if you intend to use :mod:`ixmp` from R, rather than from Python.

Install :mod:`ixmp` **from source**, per the section above.
Then:

8. `Install R <https://www.r-project.org>`_.
Ensure that your ``PATH`` environment variable is configured correctly so that the ``Rscript`` executable is available.

.. warning::
Ensure the the R version installed is either 32- *or* 64-bit (and >= 3.5.0), consistently with GAMS and Java.
Having both 32- and 64-bit versions of R, or mixed 32- and 64-bit versions of different packages, can cause errors.

9. Open a command prompt in the :file:`ixmp/` directory.
Type the following commands to build, then install, ``rixmp`` and its dependencies, including reticulate_::

$ R CMD build rixmp

10. Check that there is only one :file:`*.tar.gz` or :file:`.zip` file in the folder, then run::

# On Windows
$ R CMD INSTALL rixmp_*.zip

# Other operating systems
$ R CMD INSTALL rixmp_*.tar.gz

11. (Optional) Install `IRKernel`_, which allows running R code in Jupyter notebooks (see the link for instructions).

12. (Optional) Check that the R interface works by using the built-in test suite to run the R tutorial notebooks::

$ pytest -m rixmp


Troubleshooting
===============

Expand Down Expand Up @@ -216,12 +175,6 @@ Java Development Kit (JDK)

.. warning:: Do not overwrite the existing ``PATH`` environment variable, but add to the list of existing paths.

Rtools
https://cran.r-project.org/bin/windows/Rtools/

For installing or modifying some R packages on Windows.


.. _`installing MESSAGEix`: https://docs.messageix.org/en/latest/getting_started.html
.. _`Anaconda`: https://www.continuum.io/downloads
.. _`GAMS`: http://www.gams.com
Expand All @@ -234,6 +187,4 @@ Rtools
.. _conda glossary: https://docs.conda.io/projects/conda/en/latest/glossary.html
.. _Anaconda Navigator documentation: https://docs.anaconda.com/anaconda/navigator/
.. _`Github Desktop`: https://desktop.github.com
.. _reticulate: https://rstudio.github.io/reticulate/
.. _IRkernel: https://irkernel.github.io/installation/
.. _JDK website instructions: https://docs.oracle.com/cd/E19182-01/820-7851/inst_cli_jdk_javahome_t/
2 changes: 1 addition & 1 deletion ixmp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

try:
__version__ = get_distribution(__name__).version
except DistributionNotFound:
except DistributionNotFound: # pragma: no cover
# Package is not installed
__version__ = "999"

Expand Down
Loading

0 comments on commit ef075f8

Please sign in to comment.