forked from openai/retro
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
1,575 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
################################################################################ | ||
# | ||
# Copyright (C) 2024 retro.ai | ||
# This file is part of retro3 - https://github.com/retroai/retro3 | ||
# | ||
# SPDX-License-Identifier: AGPL-3.0-or-later | ||
# See the file LICENSE.txt for more information. | ||
# | ||
################################################################################ | ||
|
||
name: Python CI | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
build-and-deploy: | ||
# The type of runner that the job will run on | ||
runs-on: ${{ matrix.os }} | ||
|
||
defaults: | ||
run: | ||
# Set the working directory to frontend folder | ||
working-directory: src/learning | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
include: | ||
- os: ubuntu-20.04 | ||
python-version: '3.10' | ||
- os: ubuntu-22.04 | ||
python-version: '3.12' | ||
|
||
steps: | ||
- name: Checkout 🛎️ | ||
uses: actions/checkout@v4 | ||
|
||
- name: Cache OpenAI modules | ||
id: cache-openai | ||
uses: actions/cache@v4 | ||
with: | ||
path: openai | ||
key: cache-openai-${{ matrix.os }}-${{ matrix.python-version }}-${{ hashFiles('openai/**') }} | ||
|
||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install OpenAI dependencies | ||
if: steps.cache-openai.outputs.cache-hit != 'true' | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y \ | ||
build-essential \ | ||
cmake \ | ||
libgtest-dev | ||
python3 -m pip install --upgrade pip setuptools setuptools_scm | ||
- name: Build OpenAI modules | ||
if: steps.cache-openai.outputs.cache-hit != 'true' | ||
run: | | ||
cd ../../openai | ||
cmake . | ||
make -j | ||
- name: Install poetry | ||
run: | | ||
curl -sSL https://install.python-poetry.org | python3 - | ||
- name: Configure Poetry | ||
run: | | ||
poetry config virtualenvs.create false | ||
- name: Install Python dependencies | ||
run: | | ||
poetry install | ||
- name: Check formatting with Black | ||
run: | | ||
poetry run black --check . | ||
- name: Lint with Flake8 | ||
run: | | ||
poetry run flake8 . | ||
- name: Sort imports with isort | ||
run: | | ||
poetry run isort . --check-only | ||
- name: Type check with mypy | ||
run: | | ||
poetry run mypy . --check-untyped-defs | ||
- name: Run test cases | ||
run: | | ||
poetry run pytest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "retro3-meta", | ||
"version": "1.0.0", | ||
"scripts": { | ||
"build": "npm run build:openai", | ||
"build:openai": "cd openai && cmake . && make -j", | ||
"clean": "npm run clean:openai", | ||
"clean:openai": "cd openai && (git clean -xdf . || true)" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.mypy_cache | ||
.pytest_cache | ||
__pycache__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# retro.ai learning environment | ||
|
||
## Dependencies | ||
|
||
This project is managed by poetry. Install it with: | ||
|
||
```bash | ||
pip install poetry | ||
``` | ||
|
||
Then, install the dependencies with: | ||
|
||
```bash | ||
poetry install | ||
``` | ||
|
||
## Running the tests | ||
|
||
To run the tests, use the following command: | ||
|
||
```bash | ||
poetry run ci | ||
``` | ||
|
||
## Running the formatters | ||
|
||
To run the formatters, use the following command: | ||
|
||
```bash | ||
poetry run format | ||
``` | ||
|
||
## Running the agents | ||
|
||
Learning agents are placed in the `agents` directory. To run an agent, invoke it directly: | ||
|
||
```bash | ||
cd agents | ||
./random_agent.py | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#!/usr/bin/env python3 | ||
################################################################################ | ||
# | ||
# Copyright (C) 2023-2024 retro.ai | ||
# This file is part of retro3 - https://github.com/retroai/retro3 | ||
# | ||
# This file is derived from OpenAI's Gym Retro under the MIT license | ||
# Copyright (C) 2017-2018 OpenAI (http://openai.com) | ||
# | ||
# SPDX-License-Identifier: AGPL-3.0-or-later AND MIT | ||
# See the file LICENSE.txt for more information. | ||
# | ||
################################################################################ | ||
|
||
|
||
import os | ||
import sys | ||
|
||
# Get the absolute path of the current script's directory | ||
current_dir: str = os.path.dirname(os.path.abspath(__file__)) | ||
|
||
# Get the parent directory of the current directory, which is the project root | ||
project_root: str = os.path.dirname(current_dir) | ||
|
||
# Add the project root to sys.path | ||
sys.path.insert(0, project_root) | ||
|
||
|
||
from typing import Optional | ||
|
||
import gymnasium | ||
|
||
import retroai.brute as brute_module | ||
import retroai.enums | ||
import retroai.retro_env | ||
|
||
|
||
def main() -> None: | ||
game: str = "Airstriker-Genesis" | ||
state: retroai.enums.State = retroai.enums.State.DEFAULT | ||
scenario: Optional[str] = None | ||
max_episode_steps: int = 4500 | ||
timestep_limit: float = 1e8 | ||
|
||
retro_env: retroai.retro_env.RetroEnv = retroai.retro_env.retro_make( | ||
game, | ||
state, | ||
use_restricted_actions=retroai.enums.Actions.DISCRETE, | ||
scenario=scenario, | ||
) | ||
|
||
env: gymnasium.Wrapper = brute_module.Frameskip(retro_env) | ||
env = brute_module.TimeLimit(env, max_episode_steps=max_episode_steps) | ||
|
||
brute: brute_module.Brute = brute_module.Brute( | ||
env, max_episode_steps=max_episode_steps | ||
) | ||
timesteps: int = 0 | ||
best_rew: float = float("-inf") | ||
while True: | ||
acts, rew = brute.run() | ||
timesteps += len(acts) | ||
|
||
if rew > best_rew: | ||
print("new best reward {} => {}".format(best_rew, rew)) | ||
best_rew = rew | ||
|
||
if timesteps > timestep_limit: | ||
print("timestep limit exceeded") | ||
break | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env python3 | ||
################################################################################ | ||
# | ||
# Copyright (C) 2023-2024 retro.ai | ||
# This file is part of retro3 - https://github.com/retroai/retro3 | ||
# | ||
# This file is derived from OpenAI's Gym Retro under the MIT license | ||
# Copyright (C) 2017-2018 OpenAI (http://openai.com) | ||
# | ||
# SPDX-License-Identifier: AGPL-3.0-or-later AND MIT | ||
# See the file LICENSE.txt for more information. | ||
# | ||
################################################################################ | ||
|
||
|
||
import os | ||
import sys | ||
|
||
# Get the absolute path of the current script's directory | ||
current_dir = os.path.dirname(os.path.abspath(__file__)) | ||
|
||
# Get the parent directory of the current directory, which is the project root | ||
project_root = os.path.dirname(current_dir) | ||
|
||
# Add the project root to sys.path | ||
sys.path.insert(0, project_root) | ||
|
||
|
||
import retroai.retro_env | ||
|
||
|
||
def main() -> None: | ||
env: retroai.retro_env.RetroEnv = retroai.retro_env.retro_make( | ||
game="Airstriker-Genesis" | ||
) | ||
|
||
env.reset() | ||
while True: | ||
obs, rew, done, info = env.step(env.action_space.sample()) | ||
print(info) | ||
if done: | ||
env.reset() | ||
|
||
env.close() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.