<jupyter_start><jupyter_text>Table of Contents<jupyter_code>!pip install ray
import time
import numpy as np
from cartesian_explorer import Explorer
from cartesian_explorer import parallels
from cartesian_explorer import caches 
def payload(rnd):
    N = 2000
    product = 1
    for j in range(N):
        product *= np.sin(j/N)**2 + np.cos(j/N)**2
    return product
def test_backend(parallel, cache):
    ex = Explorer(parallel=parallel, cache=cache)
    _payload = ex.provider(cache=True)(payload)


    start = time.time()
    %timeit ex.map_variable('payload', rnd=np.random.randn(8))
    end = time.time()
    print(f'Duration = {end-start}')
   
def test_with_caches(Parallel):
    for Cache in [caches.JobLibCache, caches.FunctoolsCache_Disk]:
        cache = Cache('/tmp/test_caex')
        print('\n-cache=', cache)
        try:
            for nproc in [1, 2]:
                print('-- nproc=', nproc)
                parallel = Parallel(processes=nproc)
                test_backend(parallel, cache)
        except Exception as e:
            print('!Failed to distribute tasks:', e)

test_with_caches(parallels.Ray)
test_with_caches(parallels.Thread)
test_with_caches(parallels.Multiprocess)
try:
    parallel = parallels.Thread(processes=1)
    test_backend(parallel)
    parallel = parallels.Thread(processes=2)
    test_backend(parallel)
except Exception as e:
    print('Failed to distribute tasks:', e)
try:
    parallel = parallels.Multiprocess(processes=1)
    test_backend(parallel)
    parallel = parallels.Multiprocess(processes=2)
    test_backend(parallel)
except Exception as e:
    print('Failed to distribute tasks:', e)<jupyter_output>999.9999999999957
Duration = 8.987144708633423
999.9999999999957
Duration = 4.482992887496948
{'fraction_non_alphanumeric': 0.10693970420932879, 'fraction_numerical': 0.04436860068259386, 'mean_word_length': 3.6411609498680737, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '138397', 'license': 'MIT', 'n_tokens_mistral': 633, 'n_tokens_neox': 562, 'n_words': 128, 'path': 'examples/Calculate in parallel.ipynb', 'repo_name': 'danlkv/cartesian-explorer', 'size': '1758'}