Several examples are provided here demonstrating how to use the Inverted AI API in Python.
Click here to download the folder as a zip-file. To run the examples locally, first build the virtual environment.
python -m venv .venv source .venv/bin/activate pip install --upgrade pip pip install --upgrade -r requirements.txt # optionally install carla, if you want to run carla demos pip install carla==0.9.13
*If you run into an issue like
ERROR: No matching distribution found for carla==0.9.13, your Python version may not
Then, once you obtain an API key, you can run the examples.
python npc_only.py --api_key $IAI_API_KEY
There are currently three different examples available.
This demonstration script runs without a local simulator and the API is used to control all vehicles, meaning all vehicles in the simulation are NPCs. To minimize client-side complexity, the visualizations are provided through the API, which is very inefficient and only used for demonstration purposes (click here for response time comparison). The purpose of those demonstrations is to quickly give you an idea for how the underlying NPCs behave. This example is available in a few different versions, one calling the underlying REST API directly, and others using the wrapper provided as a part of our library, the latter version also being available as a Jupyter notebook and Colab.
Cosimulation Minimal example#
The minimal example, as shown on the front page, mocks up the local simulator with
a class that implements trivial control logic for the ego vehicle. This example is
meant to provide an illustration of the basic logic for performing co-simulation
using Inverted AI API and give you a sandbox to experiment with it. It will save
the generated gif as
iai-example.gif in the current directory.
Finally, as a realistic example, we provide a basic integration with CARLA. This example is meant to provide a comprehensive illustration of co-simulation logic and to be a starting point for creating custom scenarios with Inverted AI NPCs, both in CARLA and in other simulators. Running CARLA requires additional setup, which is documented within the corresponding subfolder.