-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #177 from diegoferigo/refactor/randomizers
Add Randomizers: model and physics
- Loading branch information
Showing
21 changed files
with
1,495 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT). All rights reserved. | ||
# This software may be modified and distributed under the terms of the | ||
# GNU Lesser General Public License v2.1 or any later version. | ||
|
||
from . import base | ||
from . import model | ||
from . import physics | ||
|
||
from . import gazebo_env_randomizer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT). All rights reserved. | ||
# This software may be modified and distributed under the terms of the | ||
# GNU Lesser General Public License v2.1 or any later version. | ||
|
||
from . import task | ||
from . import model | ||
from . import physics |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT). All rights reserved. | ||
# This software may be modified and distributed under the terms of the | ||
# GNU Lesser General Public License v2.1 or any later version. | ||
|
||
import abc | ||
|
||
|
||
class ModelRandomizer(abc.ABC): | ||
|
||
@abc.abstractmethod | ||
def randomize_model(self) -> str: | ||
""" | ||
Randomize the model. | ||
Return: | ||
A string with the randomized model. | ||
""" | ||
pass | ||
|
||
def seed_model_randomizer(self, seed: int) -> None: | ||
""" | ||
Seed the randomizer to ensure reproducibility. | ||
Args: | ||
seed: The seed number. | ||
""" | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT). All rights reserved. | ||
# This software may be modified and distributed under the terms of the | ||
# GNU Lesser General Public License v2.1 or any later version. | ||
|
||
import abc | ||
from gym_ignition import scenario_bindings as bindings | ||
|
||
|
||
class PhysicsRandomizer(abc.ABC): | ||
""" | ||
Abstract class that provides the machinery for randomizing physics in a Ignition | ||
Gazebo simulation. | ||
Args: | ||
randomize_after_rollouts_num: defines after many rollouts physics should be | ||
randomized (i.e. the amount of times :py:meth:`gym.Env.reset` is called). | ||
""" | ||
|
||
def __init__(self, randomize_after_rollouts_num: int = 0): | ||
|
||
self._rollout_counter = randomize_after_rollouts_num | ||
self.randomize_after_rollouts_num = randomize_after_rollouts_num | ||
|
||
@abc.abstractmethod | ||
def randomize_physics(self, world: bindings.World) -> None: | ||
""" | ||
Method that insert and configures the physics of a world. | ||
By default this method loads a plugin that uses DART with no randomizations. | ||
Randomizing physics engine parameters or changing physics engine backend could be | ||
done by redefining this method and passing it to | ||
:py:class:`~gym_ignition.runtimes.gazebo_runtime.GazeboRuntime`. | ||
Args: | ||
world: A world object without physics. | ||
""" | ||
pass | ||
|
||
def seed_physics_randomizer(self, seed: int) -> None: | ||
""" | ||
Seed the randomizer to ensure reproducibility. | ||
Args: | ||
seed: The seed number. | ||
""" | ||
pass | ||
|
||
def increase_rollout_counter(self) -> None: | ||
""" | ||
Increase the rollouts counter. | ||
""" | ||
|
||
if self.randomize_after_rollouts_num != 0: | ||
assert self._rollout_counter != 0 | ||
self._rollout_counter -= 1 | ||
|
||
def physics_expired(self) -> bool: | ||
""" | ||
Checks if the physics needs to be randomized. | ||
Return: | ||
True if the physics has expired, false otherwise. | ||
""" | ||
|
||
if self.randomize_after_rollouts_num == 0: | ||
return False | ||
|
||
if self._rollout_counter == 0: | ||
self._rollout_counter = self.randomize_after_rollouts_num | ||
return True | ||
|
||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Copyright (C) 2020 Istituto Italiano di Tecnologia (IIT). All rights reserved. | ||
# This software may be modified and distributed under the terms of the | ||
# GNU Lesser General Public License v2.1 or any later version. | ||
|
||
import abc | ||
from gym_ignition import base | ||
from gym_ignition import scenario_bindings as bindings | ||
|
||
|
||
class TaskRandomizer(abc.ABC): | ||
|
||
@abc.abstractmethod | ||
def randomize_task(self, | ||
task: base.task.Task, | ||
gazebo: bindings.GazeboSimulator, | ||
**kwargs) -> None: | ||
""" | ||
Randomize a :py:class:`~gym_ignition.base.task.Task` instance. | ||
Args: | ||
task: the task to randomize. | ||
gazebo: a :py:class:`~scenario_bindings.GazeboSimulator` instance. | ||
Note: | ||
Note that each task has a :py:attr:`~gym_ignition.base.task.Task.world` | ||
property that provides access to the simulated | ||
:py:class:`scenario_bindings.World`. | ||
""" | ||
pass | ||
|
||
def seed_task_randomizer(self, seed: int) -> None: | ||
""" | ||
Seed the randomizer to ensure reproducibility. | ||
Args: | ||
seed: The seed number. | ||
""" | ||
pass |
Oops, something went wrong.