<jupyter_start><jupyter_text>So now we know the cluster is doing ok :)<jupyter_code>class Counter:
    """ A simple class to manage an incrementing counter """
    n = 0

    def __init__(self):
        self.n = 0

    def increment(self):
        self.n += 1
        return self.n

    def add(self, x):
        self.n += x
        return self.n
    
    def value(self):
        return self.n


future = client.submit(Counter, actor=True)  # Create a Counter on a worker
counter = future.result()     
counter
counter.increment()
counter.value().result()
import dask.bag as db
b = db.from_sequence(range(1,100), npartitions=10)
import time
def inc(x):
    time.sleep(x)
    f = counter.add(x)
    # Note: the counter ( above ) is serelizable, however the future we get back from it is not
    # this is likely because the future contains a network connection to the actor, so we don't return
    # that future. If we wanted to we could also block on f's value here.
    return x
j = b.map(inc)
j
f = j.to_delayed()
f
c = client
c.submit(*f)
counter.value().result()
counter.value().result()
counter.value().result()
f[0]
# Create a large array and calculate the mean
array = da.ones((1000, 1000, 1000))
print(array.mean().compute())  # Should print 1.0|<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11595330739299611, 'fraction_numerical': 0.01867704280155642, 'mean_word_length': 3.108626198083067, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '386772', 'license': 'Apache-2.0', 'n_tokens_mistral': 437, 'n_tokens_neox': 409, 'n_words': 148, 'path': 'dask/Dask-Explore-Actors.ipynb', 'repo_name': 'mlkimmins/scalingpythonml', 'size': '1285'}