Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions docs/source/interface/tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,34 @@ class MyTask(Task[MyTaskConfig]):
If the system is our `SimulationNode` object, then there are two copies of the `Task` in the system and the controller respectively. The `SimulationNode` is responsible for stepping the `mujoco` simulation, while the `Controller` is responsible for rolling out the task. We expose functions for modifying the task before and after each of these steps. Additionally, we also allow a task-specific optimizer warm start, which is useful for tasks that require some initial setup before the optimization loop starts. The interface for these functions is as follows:
```python
class MyTask(Task[MyTaskConfig]):
def pre_rollout(self, curr_state: np.ndarray, config: MyTaskConfig) -> None:
def pre_rollout(
self,
curr_state: np.ndarray,
rollout_times: np.ndarray,
rollout_controls: np.ndarray,
config: MyTaskConfig,
) -> None:
"""Pre-rollout behavior for task (does nothing by default).

Args:
curr_state: Current state of the task. Shape=(nq + nv,).
rollout_times: The rollout times for the current rollout (global time). Shape=(T,).
rollout_controls: The intended controls to apply during the rollout - can modify in place. Shape=(T, nu).
config: The current task config (passed in from the top-level controller).
"""

def post_rollout(
self,
states: np.ndarray,
sensors: np.ndarray,
times: np.ndarray,
controls: np.ndarray,
config: MyTaskConfig,
system_metadata: dict[str, Any] | None = None,
) -> None:
"""Post-rollout behavior for task (does nothing by default).

Same inputs as in reward function.
Same inputs as in reward function except times, which are the global rollout times associated with controls.
"""

def pre_sim_step(self) -> None:
Expand Down
3 changes: 2 additions & 1 deletion judo/controller/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def update_action(self, curr_state: np.ndarray, curr_time: float) -> None:
self.rollout_controls = candidate_splines(curr_time + self.rollout_times)

# Roll out dynamics with action sequences.
self.task.pre_rollout(curr_state, self.task_cfg)
self.task.pre_rollout(curr_state, curr_time + self.rollout_times, self.rollout_controls, self.task_cfg)
self.states, self.sensors = self.rollout_backend.rollout(
self.model_data_pairs,
curr_state,
Expand All @@ -192,6 +192,7 @@ def update_action(self, curr_state: np.ndarray, curr_time: float) -> None:
self.task.post_rollout(
self.states,
self.sensors,
curr_time + self.rollout_times,
self.rollout_controls,
self.task_cfg,
self.system_metadata,
Expand Down
13 changes: 11 additions & 2 deletions judo/tasks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,25 +89,34 @@ def dt(self) -> float:
"""Returns Mujoco physics timestep for default physics task."""
return self.model.opt.timestep

def pre_rollout(self, curr_state: np.ndarray, config: ConfigT) -> None:
def pre_rollout(
self,
curr_state: np.ndarray,
rollout_times: np.ndarray,
rollout_controls: np.ndarray,
config: ConfigT,
) -> None:
"""Pre-rollout behavior for task (does nothing by default).

Args:
curr_state: Current state of the task. Shape=(nq + nv,).
rollout_times: The rollout times for the current rollout (global time). Shape=(T,).
rollout_controls: The intended controls to apply during the rollout - can modify in place. Shape=(T, nu).
config: The current task config (passed in from the top-level controller).
"""

def post_rollout(
self,
states: np.ndarray,
sensors: np.ndarray,
times: np.ndarray,
controls: np.ndarray,
config: ConfigT,
system_metadata: dict[str, Any] | None = None,
) -> None:
"""Post-rollout behavior for task (does nothing by default).

Same inputs as in reward function.
Same inputs as in reward function except times, which are the global rollout times associated with controls.
"""

def pre_sim_step(self) -> None:
Expand Down
8 changes: 7 additions & 1 deletion judo/tasks/fr3_pick.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,13 @@ def check_sensor_dists(
dist = sensors[:, :, i]
return dist

def pre_rollout(self, curr_state: np.ndarray, config: FR3PickConfig) -> None:
def pre_rollout(
self,
curr_state: np.ndarray,
rollout_times: np.ndarray,
rollout_controls: np.ndarray,
config: FR3PickConfig,
) -> None:
"""Computes the current phase of the system."""
# update the data object associated with the current state
self._data.qpos[:] = curr_state[: self.model.nq]
Expand Down
Loading