Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update versions and readme #16

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@
PyTorch [official tutorial](https://pytorch.org/tutorials/intermediate/mario_rl_tutorial.html) to build an AI-powered Mario.

## Set Up

### Poetry (Working as of Jan 2023)

1. Install [poetry](https://python-poetry.org/docs/)
2. Run the following in a terminal
```
poetry config virtualenvs.in-project true
poetry env use python3.10
poetry install
```
3. Run mario
```
poetry run python3 main.py
```
**NOTE** In the instructions below on running commands, prepend `poetry run python3` if using poetry.

### Conda (Out of date dependencies)
1. Install [conda](https://www.anaconda.com/products/individual)
2. Install dependencies with `environment.yml`
```
Expand Down
4 changes: 2 additions & 2 deletions agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Mario:
def __init__(self, state_dim, action_dim, save_dir, checkpoint=None):
self.state_dim = state_dim
self.action_dim = action_dim
self.memory = deque(maxlen=100000)
self.memory = deque(maxlen=15000)
self.batch_size = 32

self.exploration_rate = 1
Expand All @@ -23,7 +23,7 @@ def __init__(self, state_dim, action_dim, save_dir, checkpoint=None):
self.learn_every = 3 # no. of experiences between updates to Q_online
self.sync_every = 1e4 # no. of experiences between Q_target & Q_online sync

self.save_every = 5e5 # no. of experiences between saving Mario Net
self.save_every = 5e3 # no. of experiences between saving Mario Net
self.save_dir = save_dir

self.use_cuda = torch.cuda.is_available()
Expand Down
9 changes: 5 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from wrappers import ResizeObservation, SkipFrame

# Initialize Super Mario environment
env = gym_super_mario_bros.make('SuperMarioBros-1-1-v0')
env = gym_super_mario_bros.make('SuperMarioBros-1-1-v0', render_mode='human', apply_api_compatibility=True)

# Limit the action-space to
# 0. walk right
Expand All @@ -37,7 +37,7 @@
save_dir = Path('checkpoints') / datetime.datetime.now().strftime('%Y-%m-%dT%H-%M-%S')
save_dir.mkdir(parents=True)

checkpoint = None # Path('checkpoints/2020-10-21T18-25-27/mario.chkpt')
checkpoint = Path('trained_mario.chkpt')
mario = Mario(state_dim=(4, 84, 84), action_dim=env.action_space.n, save_dir=save_dir, checkpoint=checkpoint)

logger = MetricLogger(save_dir)
Expand All @@ -47,7 +47,7 @@
### for Loop that train the model num_episodes times by playing the game
for e in range(episodes):

state = env.reset()
state, info = env.reset()

# Play the game!
while True:
Expand All @@ -59,7 +59,8 @@
action = mario.act(state)

# 5. Agent performs action
next_state, reward, done, info = env.step(action)
next_state, reward, truncated, terminated, info = env.step(action)
done = truncated or terminated

# 6. Remember
mario.cache(state, next_state, action, reward, done)
Expand Down
985 changes: 985 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[tool.poetry]
name = "mad-mario"
version = "0.1.0"
description = ""
authors = ["Rohit <[email protected]>"]
readme = "README.md"
packages = [{include = "mario_rl"}]

[tool.poetry.dependencies]
python = "^3.8"
nes-py = "^8.2.1"
torch = "^1.13.1"
gym-super-mario-bros = "^7.4.0"
matplotlib = "^3.6.3"
scikit-image = "^0.19.3"
opencv-python = "^4.7.0.68"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Loading