# Send customised metric from gym to ASyncHyperBand in Tune

**URL:** <https://discuss.ray.io/t/send-customised-metric-from-gym-to-asynchyperband-in-tune/9260>\
**Category:** Ray Tune stopping condition & comparisons\
**Created:** [February 6, 2023, 2:30pm UTC](https://discuss.ray.io/t/send-customised-metric-from-gym-to-asynchyperband-in-tune/9260 "2023-02-06T14:30:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Teenforever](https://avatars.discourse-cdn.com/v4/letter/t/e9a140/32.png) [@Teenforever](https://discuss.ray.io/u/Teenforever)\
**Post date:** [February 6, 2023, 2:30pm UTC](https://discuss.ray.io/t/send-customised-metric-from-gym-to-asynchyperband-in-tune/9260/1 "2023-02-06T14:30:20Z")

</div>

I am working on a customised gym environment under RLLIB, and the step function of the wrapper returns the following:

`return obs, reward, done, {"cus_metric": self.some_customised_metric}`

After reading this ([Training (tune.Trainable, session.report) — Ray 2.2.0](https://docs.ray.io/en/latest/tune/api_docs/trainable.html#trainable-class-api)) and this ([Training (tune.Trainable, session.report) — Ray 2.2.0](https://docs.ray.io/en/latest/tune/api_docs/trainable.html#comparing-the-function-api-and-class-api)) I was under the impression that the following code will pick up the customised metric:

```auto
tuner = Tune.Tuner("SAC", tune_config = TuneConfig(
        scheduler = ASHAScheduler(metric = "cus_metric", mode = "max"),
)

```

But I keep getting the error message:

`ValueError: Trial returned a result which did not include the specified metric(s) "acc_value" that "AsyncHyperBandScheduler" expects. Make sure your calls to `tune.report()` include the metric, or set the TUNE_DISABLE_STRICT_METRIC_CHECKING environment variable to 1.`

Could someone please shed light on this and show me how I can pass the customized metric to ASHAScheduler? Thanks a lot!

---

<div class="post-metadata">

**Author:** ![arturn](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/arturn/32/2096_2.png) [@arturn](https://discuss.ray.io/u/arturn)\
**Post date:** [March 22, 2023, 12:30am UTC](https://discuss.ray.io/t/send-customised-metric-from-gym-to-asynchyperband-in-tune/9260/2 "2023-03-22T00:30:19Z")

</div>

This metric is not returned from your RLlib Algorithm to tune.  
You can use an air run config like the follwing…  
`run_config=air.RunConfig(..., verbose=2)`  
… to see which values are actually returned to tune from the tune Trainable - in this case an RLlib Algorithm. Tune has no notion of RL concepts like an environment. It only reacts to metrics that RLlib/you report back.

→ So you need to make sure that the metric you are referring to is aggregated from the batches that RLlib collects and also logged as a custom metric to tune. You ca do this with the [callback](https://docs.ray.io/en/latest/_modules/ray/rllib/algorithms/callbacks.html) `on_learn_on_batch()`.

Let us know if this works for you 🙂
