Handling multiprocessing#

gym-dssat supports multiprocessing as follows. Suppose you want to execute this piece of code:

with multiprocessing.Pool() as pool:
    results = pool.imap_unordered(multiproc_function, args))

Case 2#

You copy an already instantiated environment for your multiprocessing:

env = gym.make('gym_dssat_pdi:GymDssatPdi-v0', **env_args)

You first need to close the env:

env.close() # Necessary, else will fail !
args = [env for _ in range(10)]

Then, the correct definition of the multiproc_function follows:

def multiproc_function(env):
    foo = None
    env.reset_hard()  # Necessary, else will fail !
    try:
        ...
        foo = env.bar
    finally:
        env.close()
    return foo

Remark#

Caution

You need to explictely provide the seeds in the arguments of multiproc_function if you want variability