Kaggle / kaggle-environments

https://www.kaggle.com/competitions
Apache License 2.0
290 stars 148 forks source link

Environments share information #156

Closed SiggyF closed 2 years ago

SiggyF commented 3 years ago

If I create multiple environments they will share variables (logs, steps, info). I believe this is not intended, or is it?

>>> env_a = kaggle_environments.make("lux_ai_2021", configuration=configuration, debug=True)
>>> env_b = kaggle_environments.make("lux_ai_2021", configuration=configuration, debug=True)
>>> env_a.logs is env_b.logs
True

If this is not intended it is likely caused by the following code: In the following code python variables are initiated with empty lists and dictionaries. But this happens during function definition time and not during the running of the function.

def make(environment, configuration={}, info={}, steps=[], logs=[], debug=False, state=None):

See the discussion at stackoverflow or the warning in the python docs for details.

def make(environment, configuration=None, info=None, steps=None, logs=None, debug=False, state=None):
    if configuration is None:
        configuration = {}
    if info is None:
        info = {}
    if steps is None:
        steps = []
    if logs is None:
        logs = []
StoneT2000 commented 3 years ago

This is actually likely to be caused by the lux ai 2021 environment itself. The backing engine is written in Typescript and runs on Nodejs, so all "actual" state is stored in a separate process.

SiggyF commented 3 years ago

I also tested it for the connectx environment. There the issue is also occuring.

>>> env_a = kaggle_environments.make('connectx')
>>> env_b = kaggle_environments.make('connectx')
>>> env_a.logs is env_b.logs
True

I made a PR (#157) that fixes this issue and another issue in the rewards instantiation. I tested it with the following code:

>>> env_a = kaggle_environments.make('connectx')
>>> env_b = kaggle_environments.make('connectx')
>>> env_a.logs is env_b.logs
False