Skip to content

Commit

Permalink
Merge pull request Deadsg#5 from K-Rawson/main
Browse files Browse the repository at this point in the history
Implemented working conda setup and run scripts
  • Loading branch information
Deadsg authored Jan 7, 2024
2 parents c7fbfed + 3925d90 commit b928602
Show file tree
Hide file tree
Showing 18 changed files with 45,314 additions and 24 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
miniconda
bin/condaenv.4d1pwj__.requirements.txt
miniconda.exe
UpgradeLog*.htm
.vs
45,192 changes: 45,192 additions & 0 deletions DQNAgent.pyproj

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions DQNAgent.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34321.82
MinimumVisualStudioVersion = 10.0.40219.1
Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "DQNAgent", "DQNAgent.pyproj", "{28662260-C52B-4423-BD57-B20195913E9A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{28662260-C52B-4423-BD57-B20195913E9A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{28662260-C52B-4423-BD57-B20195913E9A}.Release|Any CPU.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7EEACEF9-19A1-4CBA-BCE3-D4C0C3D73C3A}
EndGlobalSection
EndGlobal
Binary file added DQNAgent/__pycache__/DQN_Bot.cpython-310.pyc
Binary file not shown.
Binary file modified DQNAgent/__pycache__/DQN_Bot.cpython-38.pyc
Binary file not shown.
Binary file modified DQNAgent/__pycache__/QLAgent.cpython-38.pyc
Binary file not shown.
Binary file modified DQNAgent/__pycache__/learningmodule.cpython-38.pyc
Binary file not shown.
Binary file modified DQNAgent/__pycache__/perceptionmodule.cpython-38.pyc
Binary file not shown.
3 changes: 2 additions & 1 deletion DQNAgent/learningmodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ def q_learning(env, learning_rate=0.1, discount_factor=0.9, epsilon=0.9, episode
state_dqn = env_dqn.reset()

state_dqn = env_dqn.reset()
state_dqn = np.reshape(-1, (1, ))
#state_dqn = np.reshape(-1, (1, ))
state_dqn = np.array([-1])
for time in range(500):
action_dqn = agent_dqn.act(state_dqn)
next_state_dqn, reward_dqn, done_dqn, _, _ = env_dqn.step(action_dqn)
Expand Down
38 changes: 33 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,47 @@ This project aims to develop a deep Q-network (DQN) agent system that can learn
First you need to clone this repository. Using your preferred terminal console to navigate where you cloned this repository. Then run the following command in the terminal

```console
> .\bin\windows_start.bat
> .\bin\windows_setup.bat
```

This will download and install a local miniconda python environment. It will then install the required dependendencies.

## Linux

- TODO
- Coming Soon!

## Mac

- TODO
- Coming Soon!

# Usuage
# Usage

- TODO This should include a brief overview of how to start and stop the agent.
After you have installed the system with `windows_setup.bat` next you need to run `windows_run.bat`

```console
> .\bin\windows_run.bat
```

This will start the DQN Agent in your windows console terminal.

# Development

The project uses Visual Studio (or VS Code if preferred) and requires the project to be setup before loading into visual studio.

## Setup Local Development (Windows)
To setup for local development perform the following steps

1. Git clone the repository
2. open your command terminal (or powershell)
3. cd into where you cloned the repository
4. run `.\bin\windows_setup.bat`
5. wait for setup to finish
6. Open the `DQNAgent.sln`
7. wait for solution explorer to load
8. In Visual Studio, Open `tools -> python -> Python Environments`
9. In `Python Environments` window click on `Add Environment`
10. Select `Existing Environment`
11. In the environment dropdown select `<Custom>`
12. In `Prefix Path` browse to `<repo_location>\DQNAgent\miniconda\envs\DQNAgent`
13. Click `Add`
14. Select `DQNAgent` from dropdown in visual studio toolbar
16 changes: 11 additions & 5 deletions bin/environment.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
name: dqnagent
name: DQNAgent
channels:
- conda-forge
dependencies:
- python=3.8
- numpy
- pandas
- matplotlib
- tensorflow
- pip
- pip:
- stable-baselines3
- gym
- matplotlib
- numpy
- pandas
- scikit-learn
- tensorflow
- transformers

10 changes: 0 additions & 10 deletions bin/run_dqnagent.bat

This file was deleted.

5 changes: 5 additions & 0 deletions bin/windows_clean.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ set BIN_PATH=%~dp0
set ROOT_PATH=%BIN_PATH%..\
set MINICONDA_INSTALLER=%BIN_PATH%\miniconda_installer.exe
set MINICONDA_PATH=%BIN_PATH%\..\miniconda
set MODELS_ELEUTHERAI_GPT_NEOX_20B=models--EleutherAI--gpt-neox-20b
set HUGGINGFACE_PATH=%USERPROFILE%\.cache\huggingface\hub

rem Remove the miniconda folder and its subfolders
echo Working...
rd /s /q %MINICONDA_PATH%
rd /s /q %HUGGINGFACE_PATH%\%MODELS_ELEUTHERAI_GPT_NEOX_20B%
rd /s /q %HUGGINGFACE_PATH%\.locks\%MODELS_ELEUTHERAI_GPT_NEOX_20B%
del /s /f /q "%HUGGINGFACE_PATH%\tmp*."
echo Done!
35 changes: 35 additions & 0 deletions bin/windows_run.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@echo off
rem This script will activate the virtual environment and run the dqnagent.py script

set BIN_PATH=%~dp0
set ROOT_PATH=%BIN_PATH%..\
set DQNA_TEXT=DQNAgent
set OKAY_TEXT=Okay!
set DQNA_PATH=%ROOT_PATH%\%DQNA_TEXT%
set MINICONDA_PATH=%ROOT_PATH%\miniconda

echo.

:initialize_conda_env
echo Initialize Conda Environment
call %MINICONDA_PATH%\Scripts\conda init --quiet powershell
echo %OKAY_TEXT%
echo.

:activate_conda_env
echo Activate Conda Environment
call %MINICONDA_PATH%\condabin\activate %DQNA_TEXT%
echo %OKAY_TEXT%
echo.

:run_dqn_agent
echo Run DQN Agent
python %DQNA_PATH%\DQNAgent.py
echo %OKAY_TEXT%
echo.

:deactivate_conda_env
echo Deactivate Conda Environment
conda deactivate
echo %OKAY_TEXT%
echo.
14 changes: 11 additions & 3 deletions bin/windows_start.bat → bin/windows_setup.bat
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ set MINICONDA_INSTALL_TYPE=JustMe
set MINICONDA_PATH=%ROOT_PATH%\miniconda

echo.

:prepare_directory
echo Preparing Directory:
IF DEFINED MINICONDA_PATH (
rd /s /q %MINICONDA_PATH% >nul 2>&1
Expand All @@ -23,14 +25,20 @@ IF EXIST %MINICONDA_EXE% (
echo %OKAY_TEXT%
echo.

:download_install_conda
echo Downloading and Installing Miniconda:
curl %MINICONDA_URL% -o %MINICONDA_EXE%
start /wait "" %MINICONDA_EXE% /InstallationType=%MINICONDA_INSTALL_TYPE% /RegisterPython=0 /S /D=%MINICONDA_PATH%
del %MINICONDA_EXE%
echo %OKAY_TEXT%
echo.

:create_conda_env
echo Creating Environment:
%MINICONDA_PATH%\Scripts\conda env create -f %BIN_PATH%\environment.yml
%MINICONDA_PATH%\Scripts\conda activate %DQNA_TEXT%
python %DQNA_PATH%\DQNAgent.py
call %MINICONDA_PATH%\Scripts\conda env create -f %BIN_PATH%\environment.yml
echo.
call %MINICONDA_PATH%\Scripts\conda list -n %DQNA_TEXT%
echo.
call %MINICONDA_PATH%\Scripts\conda env list
echo %OKAY_TEXT%
echo.
Binary file not shown.
Binary file not shown.
Binary file added ref/lecture_7_advanced_q_learning.pdf
Binary file not shown.

0 comments on commit b928602

Please sign in to comment.