Skip to content

Commit

Permalink
- Resolve Sphinx build docs issue
Browse files Browse the repository at this point in the history
- Remove 'actions' and 'behaviors' folders and import directly from the driving domain in metadrive model.
- Update documentation
  • Loading branch information
lola831 committed Feb 19, 2025
1 parent ab0ba25 commit 6f59b62
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 20 deletions.
3 changes: 2 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ omit =
src/scenic/simulators/carla/*
src/scenic/simulators/gta/*
src/scenic/simulators/lgsvl/*
src/scenic/simulators/metadrive/*
src/scenic/simulators/webots/*
src/scenic/simulators/xplane/*

Expand All @@ -26,4 +27,4 @@ exclude_lines =

ignore_errors = True
show_missing = True
precision = 2
precision = 2
5 changes: 3 additions & 2 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
codecov:
codecov:
require_ci_to_pass: true

coverage:
Expand All @@ -21,6 +21,7 @@ ignore:
- "src/scenic/simulators/carla/"
- "src/scenic/simulators/gta/"
- "src/scenic/simulators/lgsvl/"
- "src/scenic/simulators/metadrive/"
- "src/scenic/simulators/webots/"
- "src/scenic/simulators/xplane/"
- "!**/*.py"
Expand All @@ -30,4 +31,4 @@ comment:
cli:
plugins:
pycoverage:
report_type: "json"
report_type: "json"
2 changes: 1 addition & 1 deletion docs/simulators.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ These issues are expected to be addressed in the next version of MetaDrive.

Scenic uses OpenDRIVE maps, while MetaDrive relies on SUMO maps. Scenic provides corresponding SUMO maps for OpenDRIVE maps under the :file:`assets/maps/CARLA` directory.
Additionally, you can convert your own OpenDRIVE maps to SUMO maps using the `netconvert <https://sumo.dlr.de/docs/Networks/Import/OpenDRIVE.html/>`_ tool.
To avoid setting the SUMO map manually, name it the same as your OpenDRIVE file.
To avoid setting the SUMO map manually, name it the same as your OpenDRIVE file and place it in the same directory.
Otherwise, specify it explicitly with:

.. code-block:: console
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/dynamics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ scenarios. We have examples written for the CARLA and LGSVL driving simulators,
in :file:`examples/driving` in particular are designed to use Scenic's abstract
:ref:`driving domain <driving_domain>` and so work in either of these simulators, as well
as Scenic's built-in Newtonian physics simulator and MetaDrive simulator. While the Newtonian simulator is convenient
for testing and simple experiments, we recommend using MetaDrive for more realistic driving scenarios.
for testing simple experiments, we recommend using MetaDrive for more realistic driving scenarios.

MetaDrive support is **optional**. If your system supports MetaDrive, you can install it separately using:

Expand Down
9 changes: 9 additions & 0 deletions src/scenic/domains/driving/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
Scenarios written for the driving domain should work without changes [#f1]_ in any of the
following simulators:
* MetaDrive, using the model :doc:`scenic.simulators.metadrive.model`
* CARLA, using the model :doc:`scenic.simulators.carla.model`
* LGSVL, using the model :doc:`scenic.simulators.lgsvl.model`
* the built-in Newtonian simulator, using the model
Expand All @@ -34,6 +35,14 @@
$ scenic -S --model scenic.simulators.newtonian.driving_model \\
examples/driving/badlyParkedCarPullingIn.scenic
* MetaDrive, using the corresponding SUMO map (.net.xml) from the default map specified in
the scenario:
.. code-block:: console
$ scenic -S --2d --model scenic.simulators.metadrive.model \\
examples/driving/badlyParkedCarPullingIn.scenic
* CARLA, using the default map specified in the scenario:
.. code-block:: console
Expand Down
24 changes: 19 additions & 5 deletions src/scenic/simulators/metadrive/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
"""Interface to the MetaDrive driving simulator.
This interface must currently be used in `2D compatibility mode`.
It supports dynamic scenarios involving vehicles and pedestrians.
The interface implements the :obj:`scenic.domains.driving` abstract domain, so any
object types, behaviors, utility functions, etc. from that domain may be used freely.
For details of additional MetaDrive-specific functionality, see the world model
:obj:`scenic.simulators.metadrive.model`.
"""

# Only import MetaDriveSimulator if the metadrive package is installed; otherwise the
# import would raise an exception.
metadrive = None
try:
import metadrive
except ImportError:
raise ImportError(
"Metadrive is required. Please install the 'metadrive' package (and sumolib) or use scenic[metadrive]."
)

from .simulator import MetaDriveSimulator
pass
if metadrive:
from .simulator import MetaDriveSimulator
del metadrive
1 change: 0 additions & 1 deletion src/scenic/simulators/metadrive/actions.py

This file was deleted.

2 changes: 0 additions & 2 deletions src/scenic/simulators/metadrive/behaviors.scenic

This file was deleted.

27 changes: 22 additions & 5 deletions src/scenic/simulators/metadrive/model.scenic
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,31 @@ Global Parameters:
to process each step.
"""
import pathlib

from scenic.domains.driving.model import *
from scenic.core.errors import InvalidScenarioError
from scenic.domains.driving.actions import *
from scenic.domains.driving.behaviors import *

from scenic.simulators.metadrive.simulator import MetaDriveSimulator
from scenic.simulators.metadrive.actions import *
from scenic.simulators.metadrive.behaviors import *
from scenic.simulators.metadrive.utils import scenicToMetaDriveHeading
from scenic.core.errors import InvalidScenarioError

try:
from scenic.simulators.metadrive.simulator import MetaDriveSimulator
from scenic.simulators.metadrive.utils import scenicToMetaDriveHeading
except ModuleNotFoundError:
# for convenience when testing without the metadrive package
from scenic.core.simulators import SimulatorInterfaceWarning
import warnings
warnings.warn('The "metadrive" package is not installed; '
'will not be able to run dynamic simulations',
SimulatorInterfaceWarning)

def MetaDriveSimulator(*args, **kwargs):
"""Dummy simulator to allow compilation without the 'metadrive' package.
:meta private:
"""
raise RuntimeError('the "metadrive" package is required to run simulations '
'from this scenario')

if globalParameters.get("sumo_map") is None:
sumo_map_path = str(pathlib.Path(globalParameters.map).with_suffix(".net.xml"))
Expand Down
4 changes: 2 additions & 2 deletions src/scenic/simulators/metadrive/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
from metadrive.component.vehicle.vehicle_type import DefaultVehicle
except ImportError as e:
raise ModuleNotFoundError(
'Metadrive scenarios require the "metadrive" package'
"Metadrive is required. Please install the 'metadrive' package (and sumolib) or use scenic[metadrive]."
) from e

import logging
import sys
import time

from scenic.core.simulators import SimulationCreationError
from scenic.domains.driving.actions import *
from scenic.domains.driving.controllers import (
PIDLateralController,
PIDLongitudinalController,
)
from scenic.domains.driving.simulators import DrivingSimulation, DrivingSimulator
from scenic.simulators.metadrive.actions import *
import scenic.simulators.metadrive.utils as utils


Expand Down

0 comments on commit 6f59b62

Please sign in to comment.