Skip to main content

A Smart City Env designed for Reinforcement Learning

Project description

SmartCity-simulator

Smart City Simulator designed for hackathons !

Package installation

pip3 install --user smartcity On Google Colab !pip3 install smartcity

Python > 3.6

Env Instantiation

In the package, 3 envs are available :

  • SmartCity-v0 : small env
  • SmartCity-v1 : medium env
  • SmartCity-v2 : big env
import smartcity
import gym

env = gym.make("SmartCity-v0")

obs, info = env.reset()

Actions

To send action, you have to send a dictionnary instead of the usual vectors. There's 3 keys to send : energies, heaters and lights. Energies defines how much of each type of energy you buy. Lights define whether each light is on or off (a threshold at 0.5 is set). Heaters define the temperature of each heater. To have the size and the type of each parameter, they are available in the obs variable. obs is a dictionnary you can use to predict your actions. Keys lights, heaters and energies_amount have the exact format requested for actions, you can just copy them.

Energies

Energies are ordered the same way for all the arrays

Observations and informations

There's 5 keys in the obs dictionnary :

  • lights : numpy array of size #light. Each light is either 0 (off) or 1 (on)
  • heaters : numpy array of size #heater. Each heater is defined by its temperature
  • energies_cost : cost of each quantity. This cost is defined for each point of each energy
  • energies_amount : available amount for energy
  • needed_energy : the total amount of energy needed. If you don't send enough energy, an exception is raised. During Hackathon submission, it will be an elimination criteria. If you buy more energy that needed, it is stored indefinitely so you can use it.

There's 2 keys in info dictionnary :

  • light_interraction : a matrix of shape (#people, #lights). If there's a 1 at [i, j], the citizen i is connected to light light
  • heaters_interraction : same as lights but for heaters
  • energy_pollution : pollution factor for each type of enegy (carbon, nuclear, renewable)

Example

import smartcity
import gym
import random

env = gym.make("SmartCity-v0")

obs, info = env.reset()

energies = [0.8*obs["needed_energy"], 0.15*obs["needed_energy"], 0.1*obs["needed_energy"]]

lights = np.array([random.random() for _ in range(obs["lights"].shape[0])])
heaters = obs["heaters"] + 2

actions = {"energies": energies, "heaters": heaters, "lights": lights}

obs, score, done, info = env.step(actions)

Evaluation

We'll give you a seed and a json file dubbed setting.json and a seed.

import smartcity
import gym

seed = # given seed
env = gym.make("SmartCity-v0")
env.change_settings("path/to/setting.json")
env.seed(seed)

obs, info = env.reset()
# Learning
# your code here

# Evaluation
env.seed(seed)
obs, info = env.reset()

with open("groupe_name.sub", "w") as f:
    for i in range(100):
        actions = # prediction de votre modèle
        obs, score, done, info = env.step(actions)
        f.write(f"{actions}\n")

Pour ceux qui sont dans colab, copiez collez le contenu du fichier json dans une variable dans une cellule puis sauvegarder là comme suit :

import json
content = # copy paste subission.json
with open("submission.json", "w") as f:
    json.dump(content, f)

import smartcity
import gym

seed = # given seed
env = gym.make("SmartCity-v0")
env.change_settings("submission.json")
env.seed(seed)

SEED = 1337

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

smartcity-1.1.2.tar.gz (9.2 kB view details)

Uploaded Source

File details

Details for the file smartcity-1.1.2.tar.gz.

File metadata

  • Download URL: smartcity-1.1.2.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.4

File hashes

Hashes for smartcity-1.1.2.tar.gz
Algorithm Hash digest
SHA256 4b0719f2c85dec564308a023fac23f7f08d45979b79c0a352dc68af8e62897de
MD5 40c357be5222dfa617b72e8f87675fb9
BLAKE2b-256 6a5ee14b1155fcfe28c6d3eec5fcf928729a608a14c8d4fc8e3c9c6256c8ea4f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page