Lux-AI-Challenge / Lux-Design-S1

Home to the design and engine of the @Lux-AI-Challenge Season 1, hosted on @kaggle
https://lux-ai.org/
Apache License 2.0
897 stars 152 forks source link

Kaggle failed when main.py is changed #141

Closed gaogaotiantian closed 2 years ago

gaogaotiantian commented 2 years ago

I changed main.py to keep states. I thought kaggle simply use main.py as stdout pipe but I was obviously wrong. There's some fancy stuff going in the engine and my code can't run.

CLI worked fine locally with lux-ai-2021.

What I did is pretty simple, just instantiate a class and use the class method to parse the observation:

    my_agent = MinkerAgent()  # This is the object
    while True:
        inputs = read_input()
        observation["updates"].append(inputs)

        if step == 0:
            player_id = int(observation["updates"][0])
            observation.player = player_id
        if inputs == "D_DONE":
            logging.info(f"===========  Turn {step} ===========")
            actions = my_agent.do_action(observation)  # This line is changed

The json err log said

[[{"duration": 0.210151, "stdout": "", "stderr": "Traceback (most recent call last):\n  File \"/opt/conda/lib/python3.7/site-packages/kaggle_environments/agent.py\", line 157, in act\n    action = self.agent(*args)\n  File \"/opt/conda/lib/python3.7/site-packages/kaggle_environments/agent.py\", line 126, in callable_agent\n    args = args[:agent.__code__.co_argcount]\nAttributeError: type object 'MinkerAgent' has no attribute '__code__'\n"}]]

So clearly it tries to do something clever instead of just running main.py file. How could I know that the code that's working locally won't fail when submitted and how should I fix this?

gaogaotiantian commented 2 years ago

Okay after some digging into kaggle(this is my first kaggle competition), maybe agent has to be a function? There are some ways to making it stateful, but it would be nice to know it ahead(without knowledge about kaggle). If this is the case, then you can close this issue.

StoneT2000 commented 2 years ago

Yes agent has to be a function. I don't recommend editing main.py

Kaggle actually reads the last function in agent.py as your agent

You can store global variables as state (e.g. game_state is done for you)

main.py is for the CLI tool primarily (but kaggle also requires you to submit it as well)