Ray: Can't create remote actor without decorator and apply arguments

Created on 28 Nov 2019  路  3Comments  路  Source: ray-project/ray

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Ubuntu 16.04
  • Ray installed from (source or binary): binary
  • Ray version: 0.7.6
  • Python version: 3.6.8
import ray

ray.init()

class Test:
    def __init__(self):
        pass

actor = ray.remote(Test, num_cpus=1).remote()

fails with

AssertionError: The @ray.remote decorator must be applied either with no arguments and no parentheses, for example '@ray.remote', or it must be applied using some of the arguments 'num_return_vals', 'num_cpus', 'num_gpus', 'memory', 'object_store_memory', 'resources', 'max_calls', or 'max_reconstructions', like '@ray.remote(num_return_vals=2, resources={"CustomResource": 1})'.

Doing the same thing with a decorator (@ray.remote(num_cpus=1)) works, but I want to be able to use classes with and without Ray (eg for unit tests), so I don't want to use decorators.

question stale

All 3 comments

Try:

actor = ray.remote(num_cpus=1)(Test).remote()

# is equivalent to:

RemoteTestClass = ray.remote(num_cpus=1)(Test)
actor = RemoteTestClass.remote()

Gotcha, that works. The example in the docs is
Counter = ray.remote(Counter)
which is how I got to my approach. Perhaps another example could be provided with your method?

Hi, I'm a bot from the Ray team :)

To help human contributors to focus on more relevant issues, I will automatically add the stale label to issues that have had no activity for more than 4 months.

If there is no further activity in the 14 days, the issue will be closed!

  • If you'd like to keep the issue open, just leave any comment, and the stale label will be removed!
  • If you'd like to get more attention to the issue, please tag one of Ray's contributors.

You can always ask for help on our discussion forum or Ray's public slack channel.

Was this page helpful?
0 / 5 - 0 ratings