Error when manipulating dynamic sets after loading from a saved container

Hi all,

I have been working with the parallelization of my models, and as such, I decided to use .write() function for my model’s container. My model has a few dynamics sets, which I use to define a domain to solve in each iteration. I have been getting an error when trying to change the dynamic set after loading them from a container.

Specifically, I am getting the error:

****        $352
**** 352  Set has not been initialized

The GDX file and domain of both super-set and sub-set look good when directly checked after loading. Only the manipulation produced the error.

Here is a reproducible example:

from gamspy import (Container, Set)

def main():
    m = Container()

    j = Set(
        m,
        name="j",
        records=["new-york", "chicago", "topeka"],
        description="markets",
    )
    j_sub = Set(
        m, name="j_sub", records=["new-york", "chicago"], domain=j, description="markets"
    )

    gdx_file = "test.gdx"
    m.write(gdx_file)
    m = Container()
    m.read(gdx_file)

    print("set ", m["j"].toList())
    print("sub set ", m["j_sub"].toList())
    m["j_sub"][m["j"]] = False # here the error occurs

if __name__ == "__main__":
    main()

I would greatly appreciate your help with that. Many thanks for your time.

Best,

Adam

GAMSPy version

This information can be retrieved with:

gamspy -v1.4.0

Looks like a synchronization issue. You can add m._synch_with_gams() as a temporary solution. This will be fixed in the next release. Here is the full script:

from gamspy import (Container, Set)

def main():
    m = Container()

    j = Set(
        m,
        name="j",
        records=["new-york", "chicago", "topeka"],
        description="markets",
    )
    j_sub = Set(
        m, name="j_sub", records=["new-york", "chicago"], domain=j, description="markets"
    )

    gdx_file = "test.gdx"
    m.write(gdx_file)
    m = Container()
    m.read(gdx_file)
    m._synch_with_gams()

    print("set ", m["j"].toList())
    print("sub set ", m["j_sub"].toList())
    m["j_sub"][m["j"]] = False # here the error occurs


if __name__ == "__main__":
    main()

1 Like

Many thanks, Muhammet!
That works.

Just an additional comment that this seems to be a problem, not only when trying to manipulate the dynamic sets. I had a similar issue when trying to change the parameter after loading from .gdx. ._synch_with_gams() solves it, though.

1 Like

Yes. It is not an issue specific to dynamic set assignments. It will be fixed in the next release.

This issue has been fixed with GAMSPy 1.5.0.

1 Like