# Trials with remote function calls not scheduled

**URL:** <https://discuss.ray.io/t/trials-with-remote-function-calls-not-scheduled/4309>\
**Category:** Ray Tune\
**Created:** [December 1, 2021, 8:37am UTC](https://discuss.ray.io/t/trials-with-remote-function-calls-not-scheduled/4309 "2021-12-01T08:37:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![xiaohan2012](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/xiaohan2012/32/1754_2.png) [@xiaohan2012](https://discuss.ray.io/u/xiaohan2012)\
**Post date:** [December 1, 2021, 8:37am UTC](https://discuss.ray.io/t/trials-with-remote-function-calls-not-scheduled/4309/1 "2021-12-01T08:37:19Z")

</div>

Hi,

Say I have a function `run_trial` to be called by `tune.run` with different hyperparameter configurations. Further, inside `run_trial`, a remote function is called and the result is retrieved via `ray.get`.

However when executing `tune.run(run_trial)`, none of the trials is finished and Ray outputs that tasks cannot be scheduled.

An MWE is:

```python
import ray
import time
from ray import tune

@ray.remote
def remote_hello(name):
    """a function to be called inside MyClass"""
    time.sleep(1)
    return "Hello, {}!".format(name)

class MyClass:
    def hello(self, name):
        ret_id = remote_hello.remote(name)
        return ray.get(ret_id)

def run_trial(config):
    obj = MyClass()
    ret = obj.hello(config['name'])
    tune.report(ret=ret)

trial_config = {
    'name': tune.choice(['Ray', 'Tune'])
}

analysis = tune.run(
    run_trial,
    config=trial_config,
    num_samples=2,
)

```

The output is something like:

```auto
The actor or task with ID {some id} cannot be scheduled right now. You can ignore this message if this Ray cluster is expected to auto-scale or if you specified a runtime_env for this actor or task, which may take time to install. Otherwise, this is likely due to all cluster resources being claimed by actors. To resolve the issue, consider creating fewer actors or increasing the resources available to this Ray cluster.
Required resources for this actor or task: {CPU_group_0: 1.000000}

```

---

<div class="post-metadata">

**Author:** ![xiaohan2012](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/xiaohan2012/32/1754_2.png) [@xiaohan2012](https://discuss.ray.io/u/xiaohan2012)\
**Post date:** [December 1, 2021, 9:30am UTC](https://discuss.ray.io/t/trials-with-remote-function-calls-not-scheduled/4309/2 "2021-12-01T09:30:17Z")

</div>

The reason that the tasks cannot be scheduled is: to call remote functions, you need to specify **extra resources** , which I didn’t do.

One solution is to use [tune.PlacementGroupFactory](https://docs.ray.io/en/latest/tune/api_docs/internals.html#ray.tune.utils.placement_groups.PlacementGroupFactory), which I found [here](https://github.com/ray-project/ray/issues/13905).

```python
analysis = tune.run(
    run_trial,
    config=trial_config,
    num_samples=2,
    resources_per_trial=tune.PlacementGroupFactory(
            [{"CPU": 1}, {"CPU": 1}], strategy="PACK"
))

```

The first `{"CPU": 1}` specifies the number of CPUs for the main function,  
while the second `{"CPU": 1}` specifies the number of CPUs for remote function calls.
