Package: agymc
agymcFor reinforcement learning and concurrency lovers out there ...TL;DRMostly the same API as gym, except now multiple environments are run.Envs are run concurrently, which means speedup with time consuming operations such as backprop, render etc..IntroThis is a concurrent wrapper for OpenAI Gym library that runs multiple environments concurrently, which means running faster in training* without consuming more CPU power.What exactly isconcurrency?Maybe you have heard ofparallel computing? When we say we execute things in parallel, we run the program onmultipleprocessors, which offers significant speedup.Concurrency computinghas a broader meaning, though. The definition of aconcurrentprogram, is that it is designed not to execute sequentially, and will one day be executed parallelly**. Aconcurrent programcan run on a sigle processor or multiple processors. These tasks may communicate with each other, but have separate private states hidden from others.Why do we needconcurrencyon a single processor ?Some tasks, by nature, takes a lot of time to complete. Downloading a file, for example. Without concurrency, the processor would have to wait for the task to complete before starting to execute the next task. However, with concurrency we could temporarily suspend the current task, and come back later when the task finishes.Without using extra computing power.So much for introducing concurrency... now, what is gym ?OpenAI gym, is aPythonlibrary that helps research reinforcement learning. Reinforcement learning is a branch from control theory, and focusing mainly on agents interacting with environments. And OpenAI gym provides numerous environments for people to benchmark their beloved reinforcement learning algorithms. For you agents totrainin agym, they say.Um, so why do we need agymc, do you say ?Despite its merits, OpenAI gym has one major drawback. It is designed to runone agent on a processor at a time, only. What if you want to run multiple environments on the same processor at a time? Well, it will run,sequentially. Which means slow if you want to train a robot inbatches.ExperimentsUsingenv.renderas our bottlenecking operation, runing 200 environments, our versionagymccompletes 50 episodes in 4 minutes, while naivegymversion takes around twice as long. This is what the madness looks like:Wow, how to use agymc ?agymc, which combines the power ofPythonasync API and OpenAI gym, hence the name, designed for users to make final Except now the returns are inbatches(lists). And except serveral environments are run asynchronously.Example Usage Code Snippetimportargparseimportagymcif__name__=="__main__":parser=argparse.ArgumentParser()parser.add_argument("--num-envs",type=int)parser.add_argument("--episodes",type=int)parser.add_argument("--render",action="store_true")parser.add_argument("--verbose",action="store_true")flags=parser.parse_args()num_envs=flags.num_envsnum_episodes=flags.episodesrender=flags.renderverbose=flags.verboseenvs=agync.make("CartPole-v0",num_envs)ifverbose:importtqdmiterable=tqdm.tqdm(range(num_episodes))else:iterable=range(num_episodes)for_initerable:done=list(Falsefor_inrange(num_envs))envs.reset()whilenotall(done):ifrender:envs.render()action=envs.action_space.sample()(_,_,done,_)=envs.step(action)envs.close()* When doing puregymoperation such as sampling, stepping, this library runs slower since this is a wrapper for gym. However, for actions thattakes a while to execute, such as backprop and update, sending data back and forth, or even rendering, concurrency makes the operations execute much faster than anaive gym implementation** If you would like to learn more about concurrency patterns,thisvideo is really informative.