Click anywhere to close

Running Multiple Retro Environments

Due to constraints on Retro, it is not possible to run multiple retro environments in the same process. This restriction will will cause creating multiple environments this to raise the following error:

import retro

env1 = retro.make( game='SonicTheHedgehog2-Genesis', state='MetropolisZone.Act1' )
env2 = retro.make( game='SonicTheHedgehog2-Genesis', state='MetropolisZone.Act2' )
RuntimeError: Cannot create multiple emulator instances per process

Due to this restriction, it can be hard to do parallel joint training of agents. Thankfully the retrowrapper project makes it very easy to run environments as subprocess and interact with them as if they were a standard gym environment.

Using retrowrapper is easy. First install via pip:

pip install retrowrapper

Then simply import and create your environments.

import retrowrapper

env1 = retrowrapper.RetroWrapper(
    game='SonicTheHedgehog2-Genesis',
    state='MetropolisZone.Act1'
)
env2 = retrowrapper.RetroWrapper(
    game='SonicTheHedgehog2-Genesis',
    state='MetropolisZone.Act2'
)

Now you should no longer get the “Cannot create multiple emulator instances per process” error.

The retrowrapper library also allows you to specify a custom make function, this is useful when you want to apply custom wrappers to the environment. It is also useful during the retro-contest, allowing you to use the retro_contest.local make function that applies the contest wrappers.

To use retrowrapper with the retro_contest make function you simply need to set it before create your environments.

import retrowrapper
from retro_contest.local import make

retrowrapper.set_retro_make( make )

env1 = retrowrapper.RetroWrapper(
    game='SonicTheHedgehog2-Genesis',
    state='MetropolisZone.Act1'
)
env2 = retrowrapper.RetroWrapper(
    game='SonicTheHedgehog2-Genesis',
    state='MetropolisZone.Act2'
)

The environments are now created using the retro_contest.local make function.

Recent Posts

draft 5: How to make weed coffee creamer important mid-act break to talk about something that seems totally irrelevant
Personal
posted: February 03, 2025
draft 4: power 1 - convincing someone to do something the next chapters will probably be about control and responsibility
Personal
posted: February 01, 2025
Farewell to Arkansas St a farewell letter to the best apartment I have ever had
Personal
posted: 1/07/2024 (Updated: 1/30/2025)
Poetry Publishing my personal poetry
Personal
posted: 11/22/2023 (Updated: 1/30/2025)
rough draft 3: you are going to have to do it alone you are the only person who can swim under the iceberg
Personal
posted: October 26, 2024