Coder Social home page Coder Social logo

Comments (7)

zikolach avatar zikolach commented on May 20, 2024

@behnam2015 can you help adding a test for this case or extending one or more of existing? (see test_integration.py and test_core.py for details)

from ixmp.

gidden avatar gidden commented on May 20, 2024

cc @danielhuppmann @khaeru FYI

from ixmp.

khaeru avatar khaeru commented on May 20, 2024

cc @danielhuppmann @khaeru FYI

Thanks. This is pursuant to @behnam2015 explaining to me why I had to do this.

May also be related to #112

from ixmp.

behnam-zakeri avatar behnam-zakeri commented on May 20, 2024

@zikolach, when I only load ixmp things are okey. But when I load a message_ix Scenario this behavoir happens, i.e., scen = message_ix.Scenario(mp, model, scenario)
I wrote the test below to show this. And I realized that when I do scenario.clone() for a model that doesn't have a first model year, I get an error:
image
Then, when I add the first model year and I clone, the situation that I explained happens: the default version is loaded instead of the new version. It seems there is a problem in the interaction between ixmp and message_ix on my machine.

from ixmp.

danielhuppmann avatar danielhuppmann commented on May 20, 2024

thanks for identifying this issue @behnam2015. I'm currently reworking the clone feature for MESSAGE-scheme scenarios and will take a look.

from ixmp.

behnam-zakeri avatar behnam-zakeri commented on May 20, 2024
from message_ix import Scenario
import ixmp
test_mp = ixmp.Platform()
def model_setup(scen):
    scen.add_set('node', 'node')
    scen.add_set('commodity', 'comm')
    scen.add_set('level', 'level')
    scen.add_set('year', 2010)
    scen.add_set('technology', 'tec')
    scen.add_set('mode', 'mode')
    output_specs = ['node', 'comm', 'level', 'year', 'year']
    scen.add_par('demand', ['node', 'comm', 'level', 2010, 'year'], 1, 'GWa')
    tec_specs = ['node', 'tec', 2010, 2010, 'mode']
    scen.add_par('output', tec_specs + output_specs, 1, 'GWa')
def add_first_year(scen):
    scen.remove_solution()
    scen.check_out()
    scen.add_set('cat_year', ['firstmodelyear', 2010])
    scen.commit('')

Check if clone works as expected

def do_clone(scen):
    try:
        scen_new = scen.clone()
    except:
        print('Clone did not work!')
        scen_new = []
    return scen_new

Testing version number after cloning

def test_clone(test_mp):
    scen = Scenario(test_mp, 'test_clone', 'test', version='new')
    model_setup(scen)
    scen.commit('initialize test model')
    scen.solve(case='test_clone')
    scen.set_as_default()
    ver_old = scen.version

Cloning without first model year

    scen_new = do_clone(scen)
    assert scen_new

Cloning after adding first model year

    add_first_year(scen)
    scen_new = do_clone(scen)
    ver_new = scen_new.version

Testing the version number

    assert ver_new == ver_old + 1

from ixmp.

behnam-zakeri avatar behnam-zakeri commented on May 20, 2024

@danielhuppmann, thanks Daniel! I used the test above for this.

from ixmp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.