# Logging custom metrics by trial during PBT training

**URL:** <https://discuss.ray.io/t/logging-custom-metrics-by-trial-during-pbt-training/2730>\
**Category:** RLlib\
**Created:** [July 1, 2021, 7:50am UTC](https://discuss.ray.io/t/logging-custom-metrics-by-trial-during-pbt-training/2730 "2021-07-01T07:50:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kai\_Yun](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/kai_yun/32/167_2.png) [@Kai\_Yun](https://discuss.ray.io/u/Kai_Yun)\
**Post date:** [July 1, 2021, 7:50am UTC](https://discuss.ray.io/t/logging-custom-metrics-by-trial-during-pbt-training/2730/1 "2021-07-01T07:50:02Z")

</div>

I’ve been surveying the Ray documentation and examples on its GitHub page for a while to find an answer to do this, but can’t seem to find a solution.

I’m training multiple trials(`num_samples` parameter in `tune.run`) of PPO with Tune’s PBT and would like to get tensorboard and csv log files of some simulator-related custom metrics made during training.  
Let’s say I’m running 10 samples. I’d like to know the custom\_metric values each sample outputs after every episode while training.

The issues I’m facing are:

- There seems to be no method to access the sample indices such as 0~9 (since there are 10 samples), not the worker\_index. Each sample uses multiple RolloutWorkers and I’d like to log the average of the custom metrics after each iteration.
- I’ve read the `DefaultCallbacks` API and its [example](https://github.com/ray-project/ray/blob/master/rllib/examples/custom_metrics_and_callbacks.py). This callback class is only “called at points during policy evaluation” as the documentation states, which is not what I want. I’m not using the evaluation option here.
- However, in case I do use evaluation in near future, I would like to know how to access/mutate the `episode (MultiAgentEpisode)` object shown in the example. The example [ray/custom\_metrics\_and\_callbacks.py at master · ray-project/ray · GitHub](https://github.com/ray-project/ray/blob/master/rllib/examples/custom_metrics_and_callbacks.py) uses `episode.user_data`, `episode.hist_data`, `episode.custom_metrics`, etc. How do I access/use these???

Thanks for any help.

---

<div class="post-metadata">

**Author:** ![Kai\_Yun](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/kai_yun/32/167_2.png) [@Kai\_Yun](https://discuss.ray.io/u/Kai_Yun)\
**Post date:** [July 1, 2021, 8:30am UTC](https://discuss.ray.io/t/logging-custom-metrics-by-trial-during-pbt-training/2730/2 "2021-07-01T08:30:28Z")

</div>

Edit: if someone can answer even just the third bullet, that’d be nice. I have no idea how to put my custom metrics to the episode object in my simulator. (fyi, the custom simulator uses the ExternalEnv API).
