Skip to content

Commit

Permalink
Merge pull request #719 from flow-project/passing_env_instances
Browse files Browse the repository at this point in the history
Allows passing of Env and Scenario instance through flow_params.

Passing of strings will be deprecated, but backwards functionality is provided.
  • Loading branch information
temetski committed Sep 25, 2019
2 parents 26ffa1c + c73a881 commit 3c01094
Show file tree
Hide file tree
Showing 37 changed files with 210 additions and 127 deletions.
6 changes: 4 additions & 2 deletions examples/rllib/figure_eight.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from ray.tune import run_experiments
from ray.tune.registry import register_env

from flow.envs import AccelEnv
from flow.networks import FigureEightNetwork
from flow.utils.registry import make_create_env
from flow.utils.rllib import FlowParamsEncoder
from flow.core.params import SumoParams, EnvParams, InitialConfig, NetParams, \
Expand Down Expand Up @@ -53,10 +55,10 @@
exp_tag='figure_eight_intersection_control',

# name of the flow environment the experiment is running on
env_name='AccelEnv',
env_name=AccelEnv,

# name of the network class the experiment is running on
network='FigureEightNetwork',
network=FigureEightNetwork,

# simulator that is used by the experiment
simulator='traci',
Expand Down
6 changes: 4 additions & 2 deletions examples/rllib/multiagent_exps/multiagent_figure_eight.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
from ray.tune.registry import register_env
from ray.tune import run_experiments

from flow.envs.multiagent import MultiAgentAccelEnv
from flow.networks import FigureEightNetwork
from flow.controllers import ContinuousRouter
from flow.controllers import IDMController
from flow.controllers import RLController
Expand Down Expand Up @@ -66,10 +68,10 @@
exp_tag='multiagent_figure_eight',

# name of the flow environment the experiment is running on
env_name='MultiAgentAccelEnv',
env_name=MultiAgentAccelEnv,

# name of the network class the experiment is running on
network='FigureEightNetwork',
network=FigureEightNetwork,

# simulator that is used by the experiment
simulator='traci',
Expand Down
6 changes: 4 additions & 2 deletions examples/rllib/multiagent_exps/multiagent_highway.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
from flow.utils.registry import make_create_env
from flow.utils.rllib import FlowParamsEncoder

from flow.envs.multiagent import MultiAgentHighwayPOEnv
from flow.envs.ring.accel import ADDITIONAL_ENV_PARAMS
from flow.networks import HighwayRampsNetwork
from flow.networks.highway_ramps import ADDITIONAL_NET_PARAMS


Expand Down Expand Up @@ -134,8 +136,8 @@

flow_params = dict(
exp_tag='multiagent_highway',
env_name='MultiAgentHighwayPOEnv',
network='HighwayRampsNetwork',
env_name=MultiAgentHighwayPOEnv,
network=HighwayRampsNetwork,
simulator='traci',

env=EnvParams(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
from ray.tune.registry import register_env
from ray.tune import run_experiments

from flow.envs.multiagent import MultiWaveAttenuationPOEnv
from flow.networks import MultiRingNetwork
from flow.controllers import ContinuousRouter
from flow.controllers import IDMController
from flow.controllers import RLController
Expand Down Expand Up @@ -58,10 +60,10 @@
exp_tag='lord_of_numrings{}'.format(NUM_RINGS),

# name of the flow environment the experiment is running on
env_name='MultiWaveAttenuationPOEnv',
env_name=MultiWaveAttenuationPOEnv,

# name of the network class the experiment is running on
network='MultiRingNetwork',
network=MultiRingNetwork,

# simulator that is used by the experiment
simulator='traci',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
from ray.tune.registry import register_env
from ray.tune import run_experiments

from flow.envs.multiagent import MultiTrafficLightGridPOEnv
from flow.networks import TrafficLightGridNetwork
from flow.core.params import SumoParams, EnvParams, InitialConfig, NetParams
from flow.core.params import InFlows, SumoCarFollowingParams, VehicleParams
from flow.controllers import SimCarFollowingController, GridRouter
Expand Down Expand Up @@ -92,10 +94,10 @@ def make_flow_params(n_rows, n_columns, edge_inflow):
edge_inflow),

# name of the flow environment the experiment is running on
env_name='MultiTrafficLightGridPOEnv',
env_name=MultiTrafficLightGridPOEnv,

# name of the network class the experiment is running on
network="TrafficLightGridNetwork",
network=TrafficLightGridNetwork,

# simulator that is used by the experiment
simulator='traci',
Expand Down
6 changes: 4 additions & 2 deletions examples/rllib/stabilizing_highway.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
from ray.tune import run_experiments
from ray.tune.registry import register_env

from flow.envs import MergePOEnv
from flow.networks import MergeNetwork
from flow.utils.registry import make_create_env
from flow.utils.rllib import FlowParamsEncoder
from flow.core.params import SumoParams, EnvParams, InitialConfig, NetParams, \
Expand Down Expand Up @@ -94,10 +96,10 @@
exp_tag="stabilizing_open_network_merges",

# name of the flow environment the experiment is running on
env_name="MergePOEnv",
env_name=MergePOEnv,

# name of the network class the experiment is running on
network="MergeNetwork",
network=MergeNetwork,

# simulator that is used by the experiment
simulator='traci',
Expand Down
6 changes: 4 additions & 2 deletions examples/rllib/stabilizing_the_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from ray.tune import run_experiments
from ray.tune.registry import register_env

from flow.envs import WaveAttenuationPOEnv
from flow.networks import RingNetwork
from flow.utils.registry import make_create_env
from flow.utils.rllib import FlowParamsEncoder
from flow.core.params import SumoParams, EnvParams, InitialConfig, NetParams
Expand Down Expand Up @@ -50,10 +52,10 @@
exp_tag="stabilizing_the_ring",

# name of the flow environment the experiment is running on
env_name="WaveAttenuationPOEnv",
env_name=WaveAttenuationPOEnv,

# name of the network class the experiment is running on
network="RingNetwork",
network=RingNetwork,

# simulator that is used by the experiment
simulator='traci',
Expand Down
6 changes: 4 additions & 2 deletions examples/rllib/traffic_light_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from ray.tune import run_experiments
from ray.tune.registry import register_env

from flow.envs import TrafficLightGridPOEnv
from flow.networks import TrafficLightGridNetwork
from flow.utils.registry import make_create_env
from flow.utils.rllib import FlowParamsEncoder
from flow.core.params import SumoParams, EnvParams, InitialConfig, NetParams, \
Expand Down Expand Up @@ -181,10 +183,10 @@ def get_non_flow_params(enter_speed, add_net_params):
exp_tag='traffic_light_grid',

# name of the flow environment the experiment is running on
env_name='TrafficLightGridPOEnv',
env_name=TrafficLightGridPOEnv,

# name of the network class the experiment is running on
network='TrafficLightGridNetwork',
network=TrafficLightGridNetwork,

# simulator that is used by the experiment
simulator='traci',
Expand Down
6 changes: 4 additions & 2 deletions examples/rllib/velocity_bottleneck.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
from ray.tune import run_experiments
from ray.tune.registry import register_env

from flow.envs import BottleneckDesiredVelocityEnv
from flow.networks import BottleneckNetwork
from flow.utils.registry import make_create_env
from flow.utils.rllib import FlowParamsEncoder
from flow.core.params import SumoParams, EnvParams, InitialConfig, NetParams, \
Expand Down Expand Up @@ -111,10 +113,10 @@
exp_tag="DesiredVelocity",

# name of the flow environment the experiment is running on
env_name="BottleneckDesiredVelocityEnv",
env_name=BottleneckDesiredVelocityEnv,

# name of the network class the experiment is running on
network="BottleneckNetwork",
network=BottleneckNetwork,

# simulator that is used by the experiment
simulator='traci',
Expand Down
10 changes: 6 additions & 4 deletions examples/stable_baselines/figure_eight.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
from stable_baselines.common.vec_env import DummyVecEnv, SubprocVecEnv
from stable_baselines import PPO2

from flow.core.params import SumoParams, EnvParams, InitialConfig, NetParams, \
SumoCarFollowingParams
from flow.envs import AccelEnv
from flow.networks import FigureEightNetwork
from flow.core.params import SumoParams, EnvParams, InitialConfig, NetParams
from flow.core.params import SumoCarFollowingParams
from flow.core.params import VehicleParams
from flow.controllers import IDMController, ContinuousRouter, RLController
from flow.networks.figure_eight import ADDITIONAL_NET_PARAMS
Expand Down Expand Up @@ -51,10 +53,10 @@
exp_tag='figure_eight_intersection_control',

# name of the flow environment the experiment is running on
env_name='AccelEnv',
env_name=AccelEnv,

# name of the network class the experiment is running on
network='FigureEightNetwork',
network=FigureEightNetwork,

# simulator that is used by the experiment
simulator='traci',
Expand Down
6 changes: 4 additions & 2 deletions examples/stable_baselines/stabilizing_highway.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from stable_baselines.common.vec_env import DummyVecEnv, SubprocVecEnv
from stable_baselines import PPO2

from flow.envs import MergePOEnv
from flow.networks import MergeNetwork
from flow.core.params import SumoParams, EnvParams, InitialConfig, InFlows, NetParams
from flow.core.params import VehicleParams, SumoCarFollowingParams
from flow.controllers import RLController, IDMController
Expand Down Expand Up @@ -90,10 +92,10 @@
exp_tag="stabilizing_open_network_merges",

# name of the flow environment the experiment is running on
env_name="MergePOEnv",
env_name=MergePOEnv,

# name of the network class the experiment is running on
network="MergeNetwork",
network=MergeNetwork,

# simulator that is used by the experiment
simulator='traci',
Expand Down
6 changes: 4 additions & 2 deletions examples/stable_baselines/stabilizing_the_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from stable_baselines.common.vec_env import DummyVecEnv, SubprocVecEnv
from stable_baselines import PPO2

from flow.envs import WaveAttenuationPOEnv
from flow.networks import RingNetwork
from flow.core.params import SumoParams, EnvParams, InitialConfig, NetParams
from flow.core.params import VehicleParams, SumoCarFollowingParams
from flow.controllers import RLController, IDMController, ContinuousRouter
Expand Down Expand Up @@ -43,10 +45,10 @@
exp_tag="stabilizing_the_ring",

# name of the flow environment the experiment is running on
env_name="WaveAttenuationPOEnv",
env_name=WaveAttenuationPOEnv,

# name of the network class the experiment is running on
network="RingNetwork",
network=RingNetwork,

# simulator that is used by the experiment
simulator='traci',
Expand Down
10 changes: 6 additions & 4 deletions examples/stable_baselines/traffic_light_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
from stable_baselines.common.vec_env import DummyVecEnv, SubprocVecEnv
from stable_baselines import PPO2

from flow.core.params import SumoParams, EnvParams, InitialConfig, NetParams, \
SumoCarFollowingParams, InFlows
from flow.envs import TrafficLightGridPOEnv
from flow.networks import TrafficLightGridNetwork
from flow.core.params import SumoParams, EnvParams, InitialConfig, NetParams
from flow.core.params import SumoCarFollowingParams, InFlows
from flow.core.params import VehicleParams
from flow.controllers import SimCarFollowingController, GridRouter
from flow.utils.registry import env_constructor
Expand Down Expand Up @@ -175,10 +177,10 @@ def get_non_flow_params(enter_speed, add_net_params):
exp_tag='traffic_light_grid',

# name of the flow environment the experiment is running on
env_name='TrafficLightGridPOEnv',
env_name=TrafficLightGridPOEnv,

# name of the network class the experiment is running on
network='TrafficLightGridNetwork',
network=TrafficLightGridNetwork,

# simulator that is used by the experiment
simulator='traci',
Expand Down
6 changes: 4 additions & 2 deletions examples/stable_baselines/velocity_bottleneck.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from stable_baselines.common.vec_env import DummyVecEnv, SubprocVecEnv
from stable_baselines import PPO2

from flow.envs import BottleneckDesiredVelocityEnv
from flow.networks import BottleneckNetwork
from flow.core.params import SumoParams, EnvParams, InitialConfig, NetParams, \
InFlows, SumoCarFollowingParams, SumoLaneChangeParams
from flow.core.params import TrafficLightParams
Expand Down Expand Up @@ -108,10 +110,10 @@
exp_tag="DesiredVelocity",

# name of the flow environment the experiment is running on
env_name="BottleneckDesiredVelocityEnv",
env_name=BottleneckDesiredVelocityEnv,

# name of the network class the experiment is running on
network="BottleneckNetwork",
network=BottleneckNetwork,

# simulator that is used by the experiment
simulator='traci',
Expand Down
6 changes: 2 additions & 4 deletions flow/benchmarks/baselines/bottleneck0.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ class needed to run simulations
env_params.evaluate = True

# import the network class
module = __import__('flow.networks', fromlist=[flow_params['network']])
network_class = getattr(module, flow_params['network'])
network_class = flow_params['network']

# create the network object
network = network_class(
Expand All @@ -79,8 +78,7 @@ class needed to run simulations
)

# import the environment class
module = __import__('flow.envs', fromlist=[flow_params['env_name']])
env_class = getattr(module, flow_params['env_name'])
env_class = flow_params['env_name']

# create the environment object
env = env_class(env_params, sim_params, network)
Expand Down
6 changes: 2 additions & 4 deletions flow/benchmarks/baselines/bottleneck1.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ class needed to run simulations
env_params.evaluate = True

# import the network class
module = __import__('flow.networks', fromlist=[flow_params['network']])
network_class = getattr(module, flow_params['network'])
network_class = flow_params['network']

# create the network object
network = network_class(
Expand All @@ -79,8 +78,7 @@ class needed to run simulations
)

# import the environment class
module = __import__('flow.envs', fromlist=[flow_params['env_name']])
env_class = getattr(module, flow_params['env_name'])
env_class = flow_params['env_name']

# create the environment object
env = env_class(env_params, sim_params, network)
Expand Down
6 changes: 2 additions & 4 deletions flow/benchmarks/baselines/bottleneck2.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ class needed to run simulations
env_params.evaluate = True

# import the network class
module = __import__('flow.networks', fromlist=[flow_params['network']])
network_class = getattr(module, flow_params['network'])
network_class = flow_params['network']

# create the network object
network = network_class(
Expand All @@ -79,8 +78,7 @@ class needed to run simulations
)

# import the environment class
module = __import__('flow.envs', fromlist=[flow_params['env_name']])
env_class = getattr(module, flow_params['env_name'])
env_class = flow_params['env_name']

# create the environment object
env = env_class(env_params, sim_params, network)
Expand Down
6 changes: 2 additions & 4 deletions flow/benchmarks/baselines/figureeight012.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ class needed to run simulations
num_vehicles=14)

# import the network class
module = __import__('flow.networks', fromlist=[flow_params['network']])
network_class = getattr(module, flow_params['network'])
network_class = flow_params['network']

# create the network object
network = network_class(
Expand All @@ -67,8 +66,7 @@ class needed to run simulations
)

# import the environment class
module = __import__('flow.envs', fromlist=[flow_params['env_name']])
env_class = getattr(module, flow_params['env_name'])
env_class = flow_params['env_name']

# create the environment object
env = env_class(env_params, sim_params, network)
Expand Down

0 comments on commit 3c01094

Please sign in to comment.