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

robosuite #92

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d949a1c
Single python entry point & hydra based configuration
cloderic Jun 12, 2022
68953eb
Introducing DQN
cloderic Jun 17, 2022
4212224
Add support for petting zoo classic environment
cloderic Jun 20, 2022
757cf38
Self play and HILL DQN training for connect four
cloderic Jun 22, 2022
9219e00
Update readme with missing dependencies
cloderic Jun 23, 2022
4cb7598
Fix issue in the mountain car bc experiment conf
cloderic Jun 23, 2022
da28604
Fix bug for linux
joshair Jul 15, 2022
079c69f
Using cogment 2.5.0
cloderic Jul 15, 2022
2a6fc1a
add debugger for docs in the next branch (#82)
lhnguyen102 Jul 26, 2022
c9e32de
Pytorch multiproc fix (#81)
joshair Aug 18, 2022
36d0489
fix SimpleQueue issue (#83)
saikrishna-1996 Aug 23, 2022
282578c
fix log_metric bug (#86)
vabdollahi Aug 30, 2022
1556b8d
Upgrading Cogment and Gym (#87)
cloderic Aug 31, 2022
0b0d637
environmenrt adapter, config, requirements
saikrishna-1996 Sep 21, 2022
5b14a24
environment service starting
saikrishna-1996 Sep 24, 2022
07f3d6f
clean up
saikrishna-1996 Sep 24, 2022
f023444
black format
saikrishna-1996 Sep 24, 2022
0dcde44
pylint
saikrishna-1996 Sep 24, 2022
7b24793
local disable pylint
saikrishna-1996 Oct 2, 2022
2f813fc
Dev ppo (#91)
lhnguyen102 Oct 6, 2022
9ac1abe
Merge branch 'next' into dev-robosuite
saikrishna-1996 Oct 17, 2022
c7a3af2
fix pylint
saikrishna-1996 Oct 17, 2022
aed3e1b
fixe bugs in gyms (#98)
lhnguyen102 Oct 21, 2022
a8f8220
Hot fix (#100)
lhnguyen102 Oct 24, 2022
ce4c5ee
TD3 (#94)
saikrishna-1996 Nov 3, 2022
53a9617
Merge branch 'next' into dev-robosuite
saikrishna-1996 Nov 3, 2022
95f8f94
Isaac gym integration (#84)
saikrishna-1996 Nov 7, 2022
176376e
Merge branch 'next' into dev-robosuite
saikrishna-1996 Nov 7, 2022
6a166a1
Introduce a lobby + fix multiuser joining + instruction for deploying…
cloderic Dec 7, 2022
1281274
Merge branch 'next' into dev-robosuite
saikrishna-1996 Dec 15, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
14 changes: 4 additions & 10 deletions .apache-license-checker.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
ignore:
- "?eggs"
- "**/__pycache__"
- "**/.venv"
- "**/cogment_*.yaml"
- "**/_old"
- "**/*_pb2*.py"
- "**/*.pb.go"
- "**/*_pb*.js"
Expand All @@ -12,12 +10,8 @@ ignore:
- "**/CogSettings.d.ts"
- "**/CogSettings.js"
- "**/CogTypes.d.ts"
- "**/third_party"
- "*/cogment/api"
- "**/htmlcov"
- "web_client/node_modules"
- "web_client/build"
- "**/pybullet_driving_env/*"
- "**/node_modules"
- "**/build"
license:
CopyrightYear: 2021
CopyrightYear: 2022
Author: "AI Redefined Inc. <[email protected]>"
23 changes: 16 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Generated code
/*/*.proto
/*/cogment.yaml
cog_settings.py
*_pb2.py
*_pb2_grpc.py
base_python/cogment_verse/api
CogSettings.*
CogTypes.d.ts
*_pb.d.ts
*_pb.js
cogment_verse/web/cogment.yaml
cogment_verse/web/*.proto

# Python stuffs
__pycache__/
Expand All @@ -24,6 +24,15 @@ node_modules/

# Runtime data
/data
/debug
/isaacgym

# Cogment
/.cogment
/.cogment_verse

# Run outputs generated by Hydra
outputs
multirun

# Local ngrok configuration
ngrok.yaml
50 changes: 28 additions & 22 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,50 @@
stages:
- lint
- test

.base:
image: python:3.9
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
NPM_CACHE_DIR: "$CI_PROJECT_DIR/.cache/npm"
before_script:
- mkdir -p ${PIP_CACHE_DIR}
- mkdir -p ${NPM_CACHE_DIR}
# Installation instructions from https://github.com/nodesource/distributions/blob/master/README.md#installation-instructions
- curl -fsSL https://deb.nodesource.com/setup_14.x | bash -
- apt-get update && apt-get install -y software-properties-common && apt-add-repository non-free && apt-get update
- apt-get install -y nodejs swig unrar python3-opencv
- pip install virtualenv
- npm config set cache ${NPM_CACHE_DIR} --global
- apt-get update
- apt-get install -y swig python3-opencv
- python -m venv .venv
- source .venv/bin/activate
- pip install -r requirements.txt
cache:
# pip's cache
- paths:
- .cache/pip
- "**/.venv"
# npm's cache
# .venv
- key:
files:
- web_client/package-lock.json
- requirements.txt
paths:
- .cache/npm/
# atari roms cache
- key:
files:
- run.sh
- environment/requirements.txr
paths:
- environment/.atari_roms
- .venv

black:
stage: lint
extends: .base
script:
- black --check --diff .

build_and_test:
pylint:
stage: lint
extends: .base
script:
- ./run.sh build
- ./run.sh lint
- ./run.sh test
- pylint --recursive=y .

apache_licenses_check:
stage: lint
image: registry.gitlab.com/ai-r/apache-license-checker:latest
script:
- apache-license-checker

pytest:
stage: test
extends: .base
script:
- python -m pytest
118 changes: 68 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

[![Apache 2 License](https://img.shields.io/badge/license-Apache%202-green?style=flat-square)](./LICENSE) [![Changelog](https://img.shields.io/badge/-Changelog%20-blueviolet?style=flat-square)](./CHANGELOG.md)

> 🚧 A new major version of Cogment Verse is under develelopment in the [`next`](https://github.com/cogment/cogment-verse/tree/next). Not all the algorithms and environments are available yet but it is fully operational. Do not hesitate to test it!
> 🚧 A new major version of Cogment Verse is under develelopment in the [`next`](https://github.com/cogment/cogment-verse/tree/next). Not all the algorithms and environments are available yet but it is fully operational. Do not hesitate to test it!
>
> Follow and discuss the development in this [Pull Request](https://github.com/cogment/cogment-verse/pull/71).
> Follow and discuss the development in this [Pull Request](https://github.com/cogment/cogment-verse/pull/71).

[Cogment](https://cogment.ai) is an innovative open source AI platform designed to leverage the advent of AI to benefit humankind through human-AI collaboration developed by [AI Redefined](https://ai-r.com). Cogment enables AI researchers and engineers to build, train and operate AI agents in simulated or real environments shared with humans. For the full user documentation visit <https://docs.cogment.ai>

Expand Down Expand Up @@ -34,82 +34,100 @@ Cogment verse includes environments from:
- [Development Setup](/docs/development_setup.md)
- [Debug](#debug)
- [Environment development](/docs/environment.md)
- Deploy 🚧
- [Tunnel unsing ngrok](/docs/deployment/tunnel_using_ngrok.md)
- [Changelog](/CHANGELOG.md)
- [Contributors guide](/CONTRIBUTING.md)
- [Community code of conduct](/CODE_OF_CONDUCT.md)
- [Acknowledgments](#acknowledgements)

## Getting started

### Setup, Build and Run

1. Clone this repository
2. Install the following dependencies:
- [Python 3.9](https://www.python.org/) or above,
- [Node.JS v14](https://nodejs.org/) or above,
- `parallel`, on ubuntu it is installable using `apt-get install parallel`, on mac it is available through `brew install parallel`,
- `unrar`, on ubuntu it is installable using `apt-get install unrar`, on mac it is available through `brew install unrar`.
3. `./run.sh build`
4. `./run.sh services_start`
5. In a different terminal, start the trials with `./run.sh client start <run-name>`.
Different run names can be found in `run_params.yaml`
6. (Optional) To launch webclient, run `./run.sh web_client_start` in a different
terminal. Open http://localhost:8000 to join or visualize trials
2. Install [Python 3.9](https://www.python.org/)
3. Depending on your specific machine, you might also need to following dependencies:

- `swig`, which is required for the Box2d gym environments, it can be installed using `apt-get install swig` on ubuntu or `brew install swig` on macOS
- `python3-opencv`, which is required on ubuntu systems, it can be installed using `apt-get install python3-opencv`

4. Create and activate a virtual environment by runnning

```console
$ python -m venv .venv
$ source .venv/bin/activate
```

#### Run monitoring
5. Install the python dependencies by running
```console
$ pip install -r requirements.txt
```
6. In another terminal, launch a mlflow server on port 3000 by running
```console
$ source .venv/bin/activate
$ python -m simple_mlflow
```
7. Start the default Cogment Verse run using `python -m main`
8. Open Chrome (other web browser might work but haven't tested) and navigate to http://localhost:8080/
9. Play the game!

You can monitor ongoing run using [mlflow](https://mlflow.org). By default a local instance of mlflow is started by cogment-verse and is accessible at <http://localhost:3000>.
That's the basic setup for Cogment Verse, you are now ready to train AI agents.

#### Human player
### Configuration

Some of the availabe run involve a human player,
for example `benchmark_lander_hill` enables a human player
to momentarily take control of the lunar lander to help the
AI agents during the training process.
Cogment Verse relies on [hydra](https://hydra.cc) for configuration. This enables easy configuration and composition of configuration directly from yaml files and the command line.

Then start the run
The configuration files are located in the `config` directory, with defaults defined in `config/config.yaml`.

```console
./run.sh client start benchmark_lander_hill
```
Here are a few examples:

Access the playing interface by launching a webclient with
`./run.sh web_client_start` and navigating to <http://localhost:8000>
- Launch a Simple Behavior Cloning run with the [Mountain Car Gym environment](https://www.gymlibrary.ml/environments/classic_control/mountain_car/) (which is the default environment)
```console
$ python -m main +experiment=simple_bc/mountain_car
```
- Launch a Simple Behavior Cloning run with the [Lunar Lander Gym environment](https://www.gymlibrary.ml/environments/box2d/lunar_lander/)
```console
$ python -m main +experiment=simple_bc/mountain_car services/environment=lunar_lander
```
- Launch and play a single trial of the Lunar Lander Gym environment with continuous controls
```console
$ python -m main services/environment=lunar_lander_continuous
```
- Launch an A2C training run with the [Cartpole Gym environment](https://www.gymlibrary.ml/environments/classic_control/cartpole/)

#### **Play**
```console
$ python -m main +experiment=simple_a2c/cartpole
```

The `play` run implementation can be used to have any actor play in any environment. 3 example run parameters are provided:
This one is completely _headless_ (training doens't involve interaction with a human player). It will take a little while to run, you can monitor the progress using mlflow at <http://localhost:3000>

**`headless_play`** instanciates any agents and start a number of trials.
- Launch an DQN self training run with the [Connect Four Petting Zoo environment](https://www.pettingzoo.ml/classic/connect_four)

```console
./run.sh client start headless_play
```
```console
$ python -m main +experiment=simple_dqn/connect_four
```

**`observe`** instanciates any agents and start a number of trials with a human observer through the webclient.
The same experiment can be launched with a ratio of human-in-the-loop training trials (that are playable on in the web client)

```console
./run.sh client start observe
```
```console
$ python -m main +experiment=simple_dqn/connect_four +run.hill_training_trials_ratio=0.05
```

**`play`** instanciates let a human player play in a supported environment.
## Isaac gym

```console
./run.sh client start play
```
If you want to use Isaac Gym, use python3.8 (not python3.9)

They can be inspected and adapted to your needs in `run_params.yaml`:
1. download the zip file from [NVIDIA webpage](https://developer.nvidia.com/isaac-gym)
, unzip and copy the `isaacgym` folder to this repo.
2. clone [IsaacGymEnvs](https://github.com/NVIDIA-Omniverse/IsaacGymEnvs) and copy the
folder inside the `isaacgym` folder
3. comment out line-32 in `isaacgym/IsaacGymEnvs/isaacgymenvs/__init__.py`
4. (Assuming you already installed requirements.txt), run `pip install -r isaac_requirements.txt`.
5. nvidia-smi` to check that you have NVIDIA drivers and proper cuda installations.
6. (Assuming you already have mlflow running in a different terminal), Run `python -m main services/environment=ant`

## List of publications and submissions using Cogment and/or Cogment Verse

- Analyzing and Overcoming Degradation in Warm-Start Off-Policy Reinforcement Learning [code](https://github.com/benwex93/cogment-verse)
- Multi-Teacher Curriculum Design for Sparse Reward Environments [code](https://github.com/kharyal/cogment-verse/)

(please open a pull request to add missing entries)

## Acknowledgements

The subdirectories `/tf_agents/cogment_verse_tf_agents/third_party` and `/torch_agents/cogment_verse_torch_agents/third_party` contains code from third party sources

- `hive`: Taken from the [Hive library](https://github.com/chandar-lab/RLHive)
- `td3`: Taken form the [authors' implementation](https://github.com/sfujim/TD3)
1 change: 1 addition & 0 deletions .env → _old/.env
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ COGMENT_VERSE_MODEL_REGISTRY_PORT=9002
COGMENT_VERSE_TORCH_AGENTS_PORT=9003
COGMENT_VERSE_TF_AGENTS_PORT=9004
COGMENT_VERSE_ENVIRONMENT_PORT=9005
COGMENT_VERSE_PRETRIAL_HOOK_PORT=9006

## Prometheus metrics server ports
COGMENT_VERSE_TORCH_AGENTS_PROMETHEUS_PORT=9500
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import pytest
from cogment_verse_environment.utils.serialization_helpers import deserialize_img, deserialize_np_array
from data_pb2 import AgentAction, EnvironmentConfig
from data_pb2 import PlayerAction, EnvironmentConfig
from mock_environment_session import ActorInfo

# pylint doesn't like test fixtures
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import numpy as np
import pytest
from cogment_verse_environment.utils.serialization_helpers import deserialize_img, deserialize_np_array
from data_pb2 import AgentAction, EnvironmentConfig
from data_pb2 import PlayerAction, EnvironmentConfig
from mock_environment_session import ActorInfo

# pylint doesn't like test fixtures
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import pytest
from cogment_verse_environment.procgen_env import ENV_NAMES, ProcGenEnv
from cogment_verse_environment.utils.serialization_helpers import deserialize_img, deserialize_np_array
from data_pb2 import AgentAction, EnvironmentConfig
from data_pb2 import PlayerAction, EnvironmentConfig
from mock_environment_session import ActorInfo

# pylint doesn't like test fixtures
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions run.sh → _old/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ function mlflow_start() {
function web_client_build() {
_load_dot_env
export PORT="${COGMENT_VERSE_WEBCLIENT_PORT}"
export REACT_APP_ORCHESTRATOR_HTTP_ENDPOINT="${COGMENT_VERSE_ORCHESTRATOR_HTTP_ENDPOINT}"
export REACT_APP_ORCHESTRATOR_WEB_ENDPOINT="${COGMENT_VERSE_ORCHESTRATOR_HTTP_ENDPOINT}"
cp "${ROOT_DIR}/data.proto" "${ROOT_DIR}/cogment.yaml" "${ROOT_DIR}/web_client"
cd "${ROOT_DIR}/web_client"
npm install --no-audit
Expand All @@ -253,7 +253,7 @@ function web_client_start() {
function web_client_start_dev() {
_load_dot_env
export PORT="${COGMENT_VERSE_WEBCLIENT_PORT}"
export REACT_APP_ORCHESTRATOR_HTTP_ENDPOINT="${COGMENT_VERSE_ORCHESTRATOR_HTTP_ENDPOINT}"
export REACT_APP_ORCHESTRATOR_WEB_ENDPOINT="${COGMENT_VERSE_ORCHESTRATOR_HTTP_ENDPOINT}"
cd "${ROOT_DIR}/web_client"
npm run dev
}
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import cv2
import numpy as np
from data_pb2 import AgentAction, ContinuousAction
from data_pb2 import PlayerAction, ContinuousAction

# TODO directly use tf tensors

Expand Down Expand Up @@ -53,11 +53,11 @@ def cog_action_from_tf_action(action):
if dtype in (int, np.int32, np.int64):
field = "discrete_action"
kwargs = {field: action}
return AgentAction(**kwargs)
return PlayerAction(**kwargs)

# else
# pylint: disable=no-member
agent_action = AgentAction(continuous_action=ContinuousAction())
agent_action = PlayerAction(continuous_action=ContinuousAction())
action = np.squeeze(action)
if action.shape == ():
agent_action.continuous_action.data.append(action)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from cogment_verse import AgentAdapter

from cogment_verse_torch_agents.utils.tensors import tensor_from_cog_obs
from data_pb2 import AgentAction
from data_pb2 import PlayerAction

from huggingface_sb3 import load_from_hub
from stable_baselines3 import PPO
Expand Down
Loading