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

Export scenario to gdx #259

Open
DIUANA opened this issue Jan 26, 2020 · 6 comments
Open

Export scenario to gdx #259

DIUANA opened this issue Jan 26, 2020 · 6 comments

Comments

@DIUANA
Copy link

DIUANA commented Jan 26, 2020

Hi. I would like to know how to export the scenario to a gdx file in order to debug a scenario?

In the previous version the function to_gdx was available but it is not working in the latest release.

I tried to take advantage from the backend functions but they are demanding about some dependencies I guess

from ixmp.backend import jdbc
jdbc.JDBCBackend.write_gdx(scenario, 'path' )

it returns: 'Scenario' object has no attribute 'jindex'

Does ixmp still have a simple function to generate gdx file withou solve the scenario?

@DIUANA
Copy link
Author

DIUANA commented Jan 28, 2020

Is it possible to get an older version of ixmp? Because if the possibility to export a scenario to gdx is deprecated I would prefer to have an older version to be able to do that.

@behnam-zakeri
Copy link
Contributor

@DIUANA , thanks for raising this issue. We'll check this. Meanwhile, you can use the scenario.solve() method, which contains methods of scenario.to_gdx() and scenario.read_sol_from_gdx(). Even if your scenario doesn't solve, the input GDX will be generated.

@behnam-zakeri
Copy link
Contributor

@khaeru, Previously, there were two methods of scenario.to_gdx() and scenario.read_sol_from_gdx(), which could be very handy in some workflows. Do you know if they are reformatted or removed?

@khaeru
Copy link
Member

khaeru commented Jan 30, 2020

which could be very handy in some workflows

Sorry about this! We didn't have any indication (e.g. a test, or documentation) that they were used for that purpose, so didn't hesitate to change them.

@DIUANA #243 is in progress and will be merged shortly, probably today. After that, the correct way to use the internal methods to write to file will be:

from ixmp.backend import ItemType

mp._backend.write_file(
    'debug.gdx',
    ItemType.SET | ItemType.PAR,
    filters={'scenario': scenario})

This is what is done in ixmp.model.gams.GAMSModel—please look there for more details.

We need to have a more general discussion about the I/O user interface for 3.0, since there are many possibilities. So I will target this issue there.

Is it possible to get an older version of ixmp?

Always possible. Read the documentation for pip or conda (whichever you use)—both allow you to install specific package versions; so you would just specify an earlier version of ixmp, e.g. 1.2.0.

@khaeru khaeru added this to the 3.0 milestone Jan 30, 2020
@DIUANA
Copy link
Author

DIUANA commented Jan 30, 2020

Many thanks guys. I will check by tomorrow or next week if I ll be able to apply the function.

@khaeru khaeru modified the milestones: 3.0, post-3.0 May 28, 2020
@khaeru khaeru modified the milestones: post-3.0, 3.1 Jun 7, 2020
@khaeru khaeru modified the milestones: 3.1, 3.2 Aug 25, 2020
@khaeru khaeru removed this from the 3.2 milestone Dec 18, 2020
@behnam-zakeri
Copy link
Contributor

This topic was mentioned in the MESSAGEix weekly meeting on 03 Nov 2022. At the moment, there is a possibility to read the solution from GDX using ixmp.backend as follows. However, as there is no intention to maintain the dependency on Java backend in the new code, we will not add new method under message_ix_Scenario for this functionality until the Java backend is migrated to ixmp.

# Load required packages
import ixmp as ix
import message_ix
from pathlib import Path
from ixmp.backend import FIELDS, ItemType

# Load a scenario
mp = ix.Platform()
sc = message_ix.Scenario(mp, "MESSAGEix-...", "baseline")

# Read solution from GDX to a scenario
path_gdx = <...\message_ix\message_ix\model\output>  # Path to the GDX file
file_name = path_gdx + '\output' + '\MsgOutput_' + sc.model + "_" + sc.scenario + ".gdx"
mp._backend.read_file(Path(file_name), item_type=ItemType.MODEL, filters={"scenario": sc},
                      check_solution= True, comment= "!!", equ_list= sc.equ_list(), var_list= sc.var_list())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants