Skip to content

Commit

Permalink
remove dotenv dep, update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
AlirezaMorsali committed Oct 19, 2022
1 parent 1101782 commit 0fd02bf
Show file tree
Hide file tree
Showing 11 changed files with 198 additions and 320 deletions.
3 changes: 1 addition & 2 deletions docs/source/examples/carlasim.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# CARLA Integration
# CARLA Example

## Carla Env
17 changes: 15 additions & 2 deletions docs/source/examples/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Examples

## CARLA integration
{ref}`CARLA Example`

---
```{toctree}
:maxdepth: 2
carlasim
```


<!-- ```{toctree} -->
<!-- :maxdepth: 2 -->

<!-- examples/carlasim -->
<!-- ``` -->

TODO
20 changes: 10 additions & 10 deletions docs/source/userguide.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## User guide
# User guide

Inverted AI API provides a service that controls non-playable characters (NPCs) in driving simulations. The two main
functions are INITIALIZE, called at the beginning of the simulation, and DRIVE, called at each time step. Typically, the
Expand All @@ -12,14 +12,14 @@ fashion. In most circumstances, the latency is less than ???, but the API should
simulation. The underlying technology is based on [ITRA]() and was optimized to handle simulations of up to 30 seconds (
300 time steps) with up to 100 agents, contained within an area of roughly 300 meters in diameter.

### Programming language support
## Programming language support
The core interface is a {ref}`REST API`, that can be called from any programming language. This is a low-level, bare-bones
access mode that offers maximum flexibility to deploy in any environment.
For convenience, we also provide a {ref}`Python SDK`, freely available on PyPI with minimal dependencies, which
provides an abstraction layer on top of the REST API. In the future we intend to release a similar library in C++ and
potentially other languages.

### Maps and geofencing
## Maps and geofencing
The API operates on a pre-defined collection of maps and currently there is no programmatic way to add additional
locations. For each location there is a map, represented internally in the [Lanelet2](https://github.com/fzi-forschungszentrum-informatik/Lanelet2) format, which specifies
lanelets, traffic lights, and a selection of static traffic signs (along with their relationship to specific lanelets).
Expand All @@ -37,7 +37,7 @@ Note that different API keys may allow access to different locations. For a loca
access, LOCATION_INFO provides all the relevant information. Please contact us with requests to include additional
locations.

### Agent types and representations
## Agent types and representations
At the moment the API only supports vehicles, but future releases will also support pedestrians, bicycles, etc.. We
assume that each vehicle is a rigid rectangle with a fixed length and width. The motion of each vehicle is constrained
by the kinematic bicycle model, which further requires specifying the rear axis offset, that is the distance between the
Expand All @@ -52,7 +52,7 @@ corresponding motion could be realized through some action given a particular dy
recommend teleporting the NPCs to their new positions, since any discrepancies between predicted and realized states for
NPCs may negatively affect the quality of subsequent predictions.

### Traffic lights and other control signals
## Traffic lights and other control signals
Static traffic signals form a part of the map description and influence NPC predictions, but they are not exposed in the
interface. Traffic light placement, in particular regarding which traffic light applies to which lanelet, forms a part
of the map as well. Traffic light state changes dynamically and is controlled exclusively by the client when calling the
Expand All @@ -61,7 +61,7 @@ from the map, but for convenience we also provide traffic light IDs and the corr
For maps with traffic lights, the client is responsible for specifying their state on each call to INITIALIZE and DRIVE.
If no state is provided for any particular light, it will be considered absent.

### Handling agents and NPCs
## Handling agents and NPCs
In the API, there is no distinction between agents, controlled by you, and NPCs, controlled by us, so we refer to them
collectively as agents. In any simulation there can be zero or more characters of either kind. When calling DRIVE, the
client needs to list all agents in simulation and we predict the next states for all of them. It is up to the client to
Expand All @@ -71,7 +71,7 @@ Due to the recurrent nature of ITRA, we generally recommend that the customer is
the simulation - predictions for agents whose state is updated differently from ITRA predictions may not be as good as
when ITRA fully controls them.

### Consistent simulation with a stateless API
## Consistent simulation with a stateless API
The API is stateless, so each call to DRIVE requires specifying both the static attributes and the dynamic state of each
agent. However, ITRA is a recurrent model that uses the simulation’s history to make predictions, which we facilitate
through the stateless API by passing around a recurrent state, which is a vector with unspecified semantics from the
Expand All @@ -84,7 +84,7 @@ be provided.
To simplify the process of passing the recurrent states around, we provide a stateful [Simulator]() wrapper in the
Python library that handles this internally.

### Entering and exiting simulation
## Entering and exiting simulation
In the simple case there is a fixed number of agents present throughout the entire simulation. However, it is also
possible to dynamically introduce and remove agents, which is typically done when they enter and exit the supported
area. Removing agents is easy, all it takes is removing the information for a given agent from the lists of agent
Expand All @@ -98,13 +98,13 @@ initializes the recurrent state and DRIVE can be called from that point on norma
should initially be controlled by the client for at least 10 time steps before being handed off to ITRA as an NPC by
calling INITIALIZE.

### Reproducibility and control over predictions
## Reproducibility and control over predictions
INITIALIZE and DRIVE optionally accept a random seed, which controls their stochastic behavior. With the same seed and
the same inputs, the outputs will be approximately the same with high accuracy.
Other than for the random seed, there is currently no mechanism to influence the behavior of predicted agents, such as
by directing them to certain exits or setting their speed, but such mechanisms will be included in future releases.

### Validation and debugging
## Validation and debugging
To facilitate development of integration without incurring the costs of API calls, we provide a mock API version that
returns locally computed simple responses in the correct format. This mock API also performs validation of message
formats, including checking lengths of lists and bounds for numeric values, and those checks can also be optionally
Expand Down
80 changes: 17 additions & 63 deletions examples/Colab-Demo.ipynb

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions examples/Demo_Drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
import cv2
from tqdm import tqdm
import argparse
from dotenv import load_dotenv

load_dotenv()
os.environ["IAI_MOCK_API"] = "0"
os.environ["DEV"] = "1"
# os.environ["DEV_URL"] = "http://localhost:8888"

if os.environ.get("DEV", False):
sys.path.append("../")
import invertedai as iai
Expand Down
6 changes: 4 additions & 2 deletions examples/Demo_Drive_REST.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
import cv2
from tqdm import tqdm
import argparse
from dotenv import load_dotenv

load_dotenv()
os.environ["IAI_MOCK_API"] = "0"
os.environ["DEV"] = "1"
# os.environ["DEV_URL"] = "http://localhost:8888"

if os.environ.get("DEV", False):
sys.path.append("../")
import invertedai as iai
Expand Down
43 changes: 25 additions & 18 deletions examples/Drive-Demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 6,
"id": "609dafe1",
"metadata": {},
"outputs": [
Expand All @@ -23,11 +23,15 @@
}
],
"source": [
"import sys\n",
"import os\n",
"IAI_API_KEY=''\n",
"if not IAI_API_KEY:\n",
" print(\"Running mock API - specify IAI_API_KEY to obtain real results\")\n",
" import os\n",
" os.environ['IAI_MOCK_API'] = '1'"
" print(\"Running mock API - specify IAI_API_KEY to obtain real results\") \n",
" os.environ['IAI_MOCK_API'] = '0'\n",
" os.environ[\"DEV\"] = \"1\"\n",
"sys.path.append('../')\n",
"# !pip install invertedai==0.0.3rc1"
]
},
{
Expand All @@ -38,9 +42,6 @@
"outputs": [],
"source": [
"%matplotlib widget\n",
"import sys\n",
"sys.path.append('../')\n",
"# !pip install invertedai==0.0.3rc0\n",
"from IPython.display import clear_output\n",
"from invertedai import Jupyter_Render\n",
"import numpy as np\n",
Expand All @@ -57,9 +58,7 @@
"outputs": [],
"source": [
"if IAI_API_KEY:\n",
" iai.add_apikey(IAI_API_KEY)\n",
"# available_locations = iai.available_locations(\"carla\", \"roundabout\")\n",
"# print(available_locations)"
" iai.add_apikey(IAI_API_KEY)"
]
},
{
Expand All @@ -71,7 +70,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "ce9e4a8cb18f450aba85500bfbff95f2",
"model_id": "423e03bd479d4a4b9a64df10e2129a5c",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -85,7 +84,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "d6b41fccd53b4fbbbe1c0d4c092f4c2d",
"model_id": "3da95c9fdece46e4965663dfefadffca",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -109,20 +108,28 @@
}
],
"source": [
"location=\"CARLA:Town03:Roundabout\"\n",
"location=\"iai:ubc_roundabout\"\n",
"simulation_length = 100\n",
"renderer = Jupyter_Render()\n",
"display(renderer)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 5,
"id": "94506da0-9a15-4dc0-9d57-5ac30bc36d72",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Unable to spawn a scenario for 10 agents, 6 spawned instead.\n"
]
}
],
"source": [
"rendered_map = iai.location_info(location=location).rendered_map\n",
"rendered_map = iai.location_info(location=location).birdview_image\n",
"rendered_map = cv2.imdecode(np.array(rendered_map, dtype=np.uint8), cv2.IMREAD_COLOR)\n",
"renderer.add_frame(rendered_map)\n",
"\n",
Expand All @@ -140,7 +147,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 6,
"id": "cd7f84c7",
"metadata": {},
"outputs": [],
Expand All @@ -154,7 +161,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 7,
"id": "7fc2dd8d",
"metadata": {},
"outputs": [
Expand Down
Binary file modified examples/iai-drive.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 0 additions & 2 deletions invertedai/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
from distutils.util import strtobool

from dotenv import load_dotenv
from invertedai.api_resources import (
drive,
initialize,
Expand All @@ -10,7 +9,6 @@
from invertedai.simulation import Simulation
from invertedai.utils import Jupyter_Render, IAILogger, Session

load_dotenv()
dev = os.environ.get("DEV", False)
if dev:
dev_url = os.environ.get("DEV_URL", "http://localhost:8000")
Expand Down

0 comments on commit 0fd02bf

Please sign in to comment.