Skip to content

Commit

Permalink
Merge pull request #122 from inverted-ai/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Ruishenl committed Mar 10, 2023
2 parents ba09b95 + e36fa6c commit 611c189
Show file tree
Hide file tree
Showing 13 changed files with 404 additions and 80 deletions.
62 changes: 62 additions & 0 deletions examples/region_drive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import argparse
import invertedai as iai
from simulation.simulator import Simulation, SimulationConfig
import pathlib
import pygame
from tqdm import tqdm
from time import perf_counter
path = pathlib.Path(__file__).parent.resolve()


parser = argparse.ArgumentParser(description="Simulation Parameters.")
parser.add_argument("--api_key", type=str, default=None)
parser.add_argument("--fov", type=float, default=500)
parser.add_argument("--location", type=str, default="carla:Town10HD")
parser.add_argument("--center", type=str, default="carla:Town10HD")
parser.add_argument("-l", "--episode_length", type=int, default=300)
parser.add_argument("-cap", "--quadtree_capacity", type=int, default=15)
parser.add_argument("-ad", "--agent_density", type=int, default=10)
parser.add_argument("-ri", "--re_initialization", type=int, default=30)
parser.add_argument("-len", "--simulation_length", type=int, default=10000)
args = parser.parse_args()


if args.api_key is not None:
iai.add_apikey(args.api_key)
response = iai.location_info(location=args.location)
if response.birdview_image is not None:
rendered_static_map = response.birdview_image.decode()

cfg = SimulationConfig(location=args.location, map_center=(response.map_center.x, response.map_center.y),
map_fov=response.map_fov, rendered_static_map=rendered_static_map,
map_width=response.map_fov+200, map_height=response.map_fov+200, agent_density=args.agent_density,
initialize_stride=50, quadtree_capacity=args.quadtree_capacity,
re_initialization_period=args.re_initialization)
simulation = Simulation(cfg=cfg)

fps = 100
clock = pygame.time.Clock()
run = True
start = perf_counter()
fram_counter = 0
for _ in tqdm(range(args.simulation_length)):
# ----- HANDLE EVENTS ------
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
if event.type == pygame.KEYUP:
if event.key in [pygame.K_q, pygame.K_ESCAPE]:
run = False
if event.key == pygame.K_t:
simulation.show_quadtree = not simulation.show_quadtree
if event.key == pygame.K_l:
for npc in simulation.npcs:
npc.show_agent_neighbors = not npc.show_agent_neighbors
if not run:
break
# -----------------------------
simulation.drive()
clock.tick(fps)

pygame.quit()
print(f"Speed: {(perf_counter()-start)/simulation.timer} secs/frame")
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pydantic import validate_arguments
from invertedai.common import AgentState, AgentAttributes, RecurrentState
from collections import deque
from invertedai.simulation.utils import MAX_HISTORY_LEN, AGENT_FOV, Rectangle
from simulation.utils import MAX_HISTORY_LEN, AGENT_FOV, Rectangle
from uuid import uuid1 as UUID


Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from pygame.math import Vector2
from invertedai.simulation.utils import Rectangle, RE_INITIALIZATION_PERIOD, DEBUG
from simulation.utils import Rectangle, RE_INITIALIZATION_PERIOD, DEBUG
from typing import List, Optional, Callable
from random import randint
from invertedai import drive, async_drive
from invertedai.simulation.car import Car
from simulation.car import Car


class Region:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

import invertedai as iai
from invertedai.common import Point
from invertedai.simulation.utils import MAX_HISTORY_LEN, Rectangle, get_pygame_convertors, DEBUG
from invertedai.simulation.regions import QuadTree
from invertedai.simulation.car import Car
from simulation.utils import MAX_HISTORY_LEN, Rectangle, get_pygame_convertors, DEBUG
from simulation.regions import QuadTree
from simulation.car import Car

Color1 = (1, 1, 1)

Expand Down
File renamed without changes.
3 changes: 0 additions & 3 deletions invertedai/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
from invertedai.api.initialize import initialize, async_initialize
from invertedai.api.drive import drive, async_drive
from invertedai.cosimulation import BasicCosimulation
from invertedai.simulation.simulator import Simulation
from invertedai import simulation
from invertedai.utils import Jupyter_Render, IAILogger, Session

dev = strtobool(os.environ.get("IAI_DEV", "false"))
Expand Down Expand Up @@ -45,7 +43,6 @@
"initialize",
"location_info",
"light",
"Simulation",
"async_initialize",
"async_drive",
]
1 change: 0 additions & 1 deletion invertedai/simulation/__init__.py

This file was deleted.

92 changes: 90 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "invertedai"
version = "0.0.8"
version = "0.0.8.post1"
description = "Client SDK for InvertedAI"
authors = ["Inverted AI <info@inverted.ai>"]
readme = "README.md"
Expand All @@ -14,6 +14,7 @@ python = ">=3.8,<3.11"
requests = "^2.28.1"
pydantic = "^1.10.2"
matplotlib = "^3.6.2"
tqdm = "^4.65.0"

[tool.poetry.group.dev.dependencies]
numpy = "^1.17.0"
Expand Down Expand Up @@ -41,6 +42,10 @@ sphinx-autobuild = "^2021.3.14"
nbsphinx = "^0.8.9"
breathe = "^4.34.0"


[tool.poetry.group.tests.dependencies]
pytest = "^7.2.2"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
19 changes: 19 additions & 0 deletions tests/run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

# Install the package using Poetry
poetry install --without dev,docs

# Source the .env file for API keys
# source .env

# Activate the virtual environment
source "$(poetry env info --path)/bin/activate"

# Run pytest
pytest

# Deactivate the virtual environment
deactivate

# Remove the virtual environment
rm -rf "$(poetry env info --path)"

0 comments on commit 611c189

Please sign in to comment.