question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot initialise superclass from actor process

See original GitHub issue

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Manjaro Linux 18.1.2
  • Ray installed from (source or binary): binary, pip install
  • Ray version: 0.7.6
  • Python version: 3.7.4

Describe the problem

I am trying to parallelise a sampling process, so I created a Sampler object. The Sampler depends on two datasets, which are large (stored as numpy arrays), which are arguments to the constructor. To avoid having duplicates in the object store, my idea has been to first use ray.put to add the object to the object store and then initialise the Sampler objects with the corresponding ids.

Moreover, I don’t want to add the decorators to the Sampler class. Instead, I created a subclass of Sampler, RemoteSampler which decorates the methods of the superclass and modifies them by adding the .remote() call. However, I seem to be unable to initialise the superclass from the ActorClass. I get a type error:

TypeError: super() argument 1 must be type, not ActorClass(RemoteSampler).

Source code / logs

Please see the skeleton code below:

class Sampler(object):

    def __init__(self, train_data, d_train_data, *others):

        # these can be big, so we want to have only one copy that
        # mutliple actors share
        if isinstance(train_data, np.ndarray):
            self.train_data = train_data
        else:
            self.train_data = ray.get(train_data)

        if isinstance(d_train_data, np.ndarray):
            self.d_train_data = d_train_data
        else:
            self.d_train_data = ray.get(d_train_data)

        # Initialise the rest of the sampler state
        self.d1 = {}
        self.d2 = {}

    def __call__(self, features, n_samples):

        a, b, c = self._sampling_loop(features, n_samples)

        # process a, b, c and return them

        return a, b, c

    def build_lookups(self, X):

    # Use X to modify state of d1 and d2

    def _sampling_loop(self, features, n_samples):
    # Use train_data, d_train data and other attributes to
    # return some data to call`

@ray.remote
class RemoteSampler(Sampler):

    def __init__(self, *args):
        super(RemoteSampler, self).__init__(*args)
        # TODO: don't hardcode return vals
   
    @ray.method(num_return_vals=4)
    def __call__(self, anchor, num_samples):
        return self(anchor, num_samples)
    
    @ray.method(num_return_vals=3)
    def build_lookups(self, X):
        a, b, c = self.build_lookups(X)
        return a, b, c

def _fit_parallel(*args, **kwargs):
    # method of a class where the RemoteSampler objects are initialised
   train_data, d_train_data, *others = args
   train_data_id = ray.put(train_data)
   d_train_data_id = ray.put(d_train_data)
   n_args = (train_data_id, d_train_data_id, *others)

   return [RemoteSampler.remote(*n_args) for _ in range(kwargs['ncpu'])]

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
rkooo567commented, Feb 5, 2020

@alexcoca More concisely, use super().__init__([your_args]). (I believe Python2 does not support this, but Ray’s python2 support reached to the end anyway)

0reactions
robertnishiharacommented, Nov 14, 2020

Closing because I think this is a duplicate of https://github.com/ray-project/ray/issues/449. Please reopen if that’s a mistake.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot innitialise superclass from Ray actor process
I am trying to parallelise a sampling process, so I created a Sampler object. The Sampler depends on two datasets, which are large...
Read more >
Why must I specify @MainActor on init() but not on a function?
When trying to use a Task inside the init method of a class derived from NSWindowController , I have to explicitly annotate the...
Read more >
Subclasses and Inheritance (Java in a Nutshell)
This constructor explicitly initializes the cx and cy fields newly defined by PlaneCircle, but it relies on the superclass Circle() constructor to initialize...
Read more >
Subclassing and Inheritance - Learning Java, 4th Edition [Book]
A class in Java can be declared as a subclass of another class using the ... A subclass inherits all members of its...
Read more >
Inheritance - Learning the Java Language
them yourself. A subclass inherits all the members (fields, methods, and nested classes) from its superclass. Constructors are not members, so they are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found