iiasa / message_ix

The integrated assessment and energy systems model MESSAGEix
https://docs.messageix.org
Apache License 2.0
112 stars 149 forks source link

Westeros Baseline Example Reporting Module Error #787

Open brendandanaher opened 5 months ago

brendandanaher commented 5 months ago

Code sample or context When plotting results in westeros_baseline.ipynb there is a typo calling the reporting module. The error can be seen below.

There needs to be a change to the where the module is called so that it calls "from message_ix.reporting import Reporter". This will allow the program to work.

# Create a Reporter object to describe and carry out reporting
# calculations and operations (like plotting) based on `scenario`
from message_ix.report import Reporter

rep = Reporter.from_scenario(scenario)

# "prepare_plots" enables several to describe reporting operations, e.g.
# "plot activity", "plot capacity", or "plot prices"
# See message_ix/util/tutorial.py for more information
from message_ix.util.tutorial import prepare_plots

prepare_plots(rep)

Expected result

The program should prepare the plots that get called later on.

Problem description

Due to the typo, the following error is raised:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
[~\AppData\Local\Temp\ipykernel_24900\3937561850.py](https://file+.vscode-resource.vscode-cdn.net/c%3A/Users/brend/Documents/CIVE%20566/MESSAGE%20Tutorials/iiasa-message_ix-f2bd088/tutorial/westeros/~/AppData/Local/Temp/ipykernel_24900/3937561850.py) in <module>
      1 # Create a Reporter object to describe and carry out reporting
      2 # calculations and operations (like plotting) based on `scenario`
----> 3 from message_ix.report import Reporter
      4 
      5 rep = Reporter.from_scenario(scenario)

ModuleNotFoundError: No module named 'message_ix.report'

Versions

Output of message-ix show-versions ``` ixmp: 3.4.0 message_ix: 3.4.0 message_ix_models: None message_data: None click: 8.1.7 dask: 2022.02.0 genno: installed graphviz: None jpype: 1.4.1 … JVM path: C:\Program Files\Java\jdk-21\bin\server\jvm.dll openpyxl: 3.0.10 pandas: 1.2.5 pint: 0.17 xarray: 0.20.2 yaml: 6.0 iam_units: installed jupyter: installed matplotlib: 3.4.2 plotnine: None pyam: 1.3.1 GAMS: 38.3.0 python: 3.7.15 (default, Nov 24 2022, 18:44:54) [MSC v.1916 64 bit (AMD64)] python-bits: 64 OS: Windows OS-release: 10 machine: AMD64 processor: Intel64 Family 6 Model 154 Stepping 3, GenuineIntel byteorder: little LC_ALL: None LANG: None LOCALE: (None, None) ```
brendandanaher commented 5 months ago

I am using MESSAGE as part of a course and originally downloaded using conda and the version was older. I updated through pip to version 3.7 and the error persists.

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
[~\AppData\Local\Temp\ipykernel_12324\3937561850.py](https://file+.vscode-resource.vscode-cdn.net/c%3A/Users/brend/Documents/CIVE%20566/MESSAGE%20Tutorials/iiasa-message_ix-f2bd088/tutorial/westeros/~/AppData/Local/Temp/ipykernel_12324/3937561850.py) in <module>
      1 # Create a Reporter object to describe and carry out reporting
      2 # calculations and operations (like plotting) based on `scenario`
----> 3 from message_ix.report import Reporter
      4
      5 rep = Reporter.from_scenario(scenario)
ModuleNotFoundError: No module named 'message_ix.report'

Versions

Output of message-ix show-versions ``` ixmp: 3.7.0 message_ix: 3.7.0 message_ix_models: None message_data: None click: 8.1.7 dask: 2022.02.0 genno: installed graphviz: None jpype: 1.4.1 … JVM path: C:\Program Files\Java\jdk-21\bin\server\jvm.dll openpyxl: 3.0.10 pandas: 1.2.5 pint: 0.17 xarray: 0.20.2 yaml: 6.0 iam_units: installed jupyter: installed matplotlib: 3.4.2 plotnine: None pyam: 1.3.1 GAMS: 38.3.0 python: 3.7.15 (default, Nov 24 2022, 18:44:54) [MSC v.1916 64 bit (AMD64)] python-bits: 64 OS: Windows OS-release: 10 machine: AMD64 processor: Intel64 Family 6 Model 154 Stepping 3, GenuineIntel byteorder: little LC_ALL: None LANG: None LOCALE: (None, None) ```
glatterf42 commented 5 months ago

Hi @brendandanaher, thanks for reaching out!

This typo is somewhat intentional, I would say. Please note that we have recently released version 3.8.0 of message_ix, which changed the syntax of calling the reporting-related module (as you can see in our docs). So at version 3.4.0 and 3.7.0, the syntax needs to be the way you describe it (from message_ix.reporting import Reporter), while for version 3.8.0 and above, it needs to be the new way (from message_ix.report import Reporter). We took precautions to avoid people running into such errors, so the version of the tutorials that is distributed along with the code always reflects the currently working syntax. For example, you will find that the westeros baseline tutorial in the 3.7.0 version does call from message_ix.reporting, while only the 3.8.0 version calls from message_ix.report. So you must have gotten your hands on the latest version of the tutorial, which does not necessarily work with not-the-latest version of message_ix.

Please try updating the message_ix module to the latest version or try running the old version of the tutorials! They are identical on the content side, but some syntax has changed.