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

Bug: Cannot serialize action if it modifies all elements (e.g. all lines) #667

Open
DEUCE1957 opened this issue Nov 27, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@DEUCE1957
Copy link
Contributor

DEUCE1957 commented Nov 27, 2024

Environment

  • Grid2op version: 1.11.0.dev0
  • System: arch
  • Python: 1.12.4

Bug description

If you try to store and then load a serialized version of a Grid2Op action, this will usually work without a problem. However, there is an edge case where it fails (with a misleading/confusing error message) if the action modified all line statuses. This only happens if you modify all lines, even modify all-but-one will not throw the error. It also does not happen if you directly reload the action from the serialized form (i.e. the error only happens if you write and read the serialized form from file)

How to reproduce

Minimal code to reproduce the error:

import json
import tempfile
import grid2op
from pathlib import Path
env = grid2op.make("l2rpn_case14_sandbox")
init_obs = env.reset(options={"time serie id":0})
all_but_one_lines_on = env.action_space({"set_line_status":[(name, 1) for name in env.name_line[0:-1]]})
all_lines_on = env.action_space({"set_line_status":[(name, 1) for name in env.name_line[:]]})

with tempfile.TemporaryDirectory() as tmpdirname:
    for act in [all_but_one_lines_on, all_lines_on]:
        with open(Path(tmpdirname) / "act.json", "w") as f:
            json.dump(act.as_serializable_dict(), f)
        with open(Path(tmpdirname) / "act.json", "r") as f:
            dict_ = json.load(f)
        act = env.action_space(dict_) # Will throw error on 'all_lines_on' (2nd iteration)
        print(act)

This results in the following error message:

IllegalAction: Grid2OpException IllegalAction "Impossible to modify the line status with your input. Please consult the documentation. The error was:
"Grid2OpException IllegalAction "new_bus should be between -1 and 1, found a value  > 1"""

Note from additional tests, this seems to also be the case for other action, e.g. with redispatch:

import json
import tempfile
import grid2op
from pathlib import Path
env = grid2op.make("l2rpn_case14_sandbox")
init_obs = env.reset(options={"time serie id":0})
all_gens_but_one = env.action_space({"redispatch":[(name, 0.01) for name in env.name_gen[0:-1]]})
all_gens = env.action_space({"redispatch":[(name, 0.01) for name in env.name_gen[:]]})

with tempfile.TemporaryDirectory() as tmpdirname:
    for act in [all_gens_but_one, all_gens]:
        with open(Path(tmpdirname) / "act.json", "w") as f:
            json.dump(act.as_serializable_dict(), f)
        with open(Path(tmpdirname) / "act.json", "r") as f:
            dict_ = json.load(f)
        act = env.action_space(dict_) # Will throw error on 'all_gens' (2nd iteration)
        print(act)

Will give the error message:

IllegalAction: Grid2OpException IllegalAction "Impossible to modify the redispatching with your input. Please consult the documentation. The error was:
"too many indices for array: array is 1-dimensional, but 2 were indexed""

Expected output

Expect no error message to be thrown.

@DEUCE1957 DEUCE1957 added the bug Something isn't working label Nov 27, 2024
BDonnot added a commit to BDonnot/Grid2Op that referenced this issue Nov 28, 2024
Signed-off-by: DONNOT Benjamin <[email protected]>
@BDonnot BDonnot mentioned this issue Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant