Package: environment-framework
🌐 Environment FrameworkThis repository contains the Python packageenvironment-framework. The project aims to provide loose building blocks to manage the logic, observation, estimation and visualization of an agent-environment loop. It can be used to implement problems which might be solved with reinforcement learning or dynamic programming algorithms.A wrapper aroundgymnasiumis provided to connect to well-known frameworks in the field.The wrapper for gymnasium uses the gymnasium>=0.26 API structure!🤔 Why create this project?The project emerges from a previous project of mine. It was used to separate the different elements of the projects agent-environment-loop.🚀 Get StartedInstallationpip3installenvironment-framework👩‍🏫 GridWorld ExampleThe implemented example ofGridWorldcan also be found in a Jupyter notebookgrid_world.ipynb.pip3install"environment-framework[extra]"jupyterlabclassAction(Enum):UP=0DOWN=1RIGHT=2LEFT=3classGridWorldGame:def__init__(self,size:int)->None:self.size=sizeself.player_position=(0,0)self.target_position=(0,0)self.reset()@propertydefdone(self)->bool:returnself.player_position==self.target_position@propertydefspace(self)->Space:returnDiscrete(4)defact(self,action:Action,**_:Any)->None:ifaction==Action.UP:self.player_position=(self.player_position[0],self.player_position[1]-1)ifaction==Action.DOWN:self.player_position=(self.player_position[0],self.player_position[1]+1)ifaction==Action.RIGHT:self.player_position=(self.player_position[0]+1,self.player_position[1])ifaction==Action.LEFT:self.player_position=(self.player_position[0]-1,self.player_position[1])corrected_x=max(0,min(self.size-1,self.player_position[0]))corrected_y=max(0,min(self.size-1,self.player_position[1]))self.player_position=(corrected_x,corrected_y)defreset(self)->None:defget_random_position()->int:returnrandint(0,self.size-1)self.player_position=(get_random_position(),get_random_position())self.target_position=(get_random_position(),get_random_position())ifself.done:self.reset()classGridWorldObserver:def__init__(self,game:GridWorldGame)->None:self.game=game@propertydefspace(self)->Space:returnBox(shape=(4,),low=-math.inf,high=math.inf)defobserve(self,_:Any)->NDArray:returnnp.array([*self.game.player_position,*self.game.target_position])classGridWorldEstimator:def__init__(self,game:GridWorldGame)->None:self.game=gamedefestimate(self,_:Any)->float:return-1+float(self.game.done)classGridWorldVisualizer:# We use BGRBLUE=[255,0,0]GREEN=[0,255,0]def__init__(self,game:GridWorldGame)->None:self.game=gamedefrender(self,_:Any)->Any:frame=[[[0forkinrange(3)]forjinrange(self.game.size)]foriinrange(self.game.size)]frame[self.game.player_position[1]][self.game.player_position[0]]=self.BLUEframe[self.game.target_position[1]][self.game.target_position[0]]=self.GREENreturnframeclassGridWorldLevel(Level):_game:GridWorldGame_observer:GridWorldObserver_estimator:GridWorldEstimator_visualizer:GridWorldVisualizerdef__init__(self,game:GridWorldGame,observer:GridWorldObserver,estimator:GridWorldEstimator,visualizer:GridWorldVisualizer,)->None:super().__init__(game,observer,estimator,visualizer)defreset(self)->None:self._game.reset()defstep(self,action:Action)->Any:ifisinstance(action,np.int64):# handle integer inputsaction=Action(action)self._game.act(action)game=GridWorldGame(7)level=GridWorldLevel(game,GridWorldObserver(game),GridWorldEstimator(game),GridWorldVisualizer(game))simulator=Simulator(level)whilenotsimulator.done:action=Action(randint(0,3))simulator.step(action)📃 DocumentationSome doc-strings are already added. Documentation is a work-in-progress and will be updated on a time by time basis.💃🕺 ContributionI welcome everybody contributing to this project. Please read theCONTRIBUTING.mdfor more information.
Feel free to open an issue on the project if you have any further questions.💻 DevelopmentThe repository provides tools for development usinghatch.All dependencies for the project also can be found in arequirements-file.Install the development dependencies.pip3install-rrequirements/dev.txtorpip3install"environment-framework[dev]"ToolsTo run all development tools, type checking, linting and testshatchis required.makeallType checkingType checking withmypy.makemypyLintingLinting withpylint.makelintTestsRun tests withpytest.maketestUpdate dependenciesUpdate python requirements withpip-compile.makeupdate🧾 LicenseThis repository is licensed under the MIT License.