[Python] Why does generating the Sobol Sequence in SciPy hang after completing 25% of the...

Discussão em 'Python' iniciado por Stack, Julho 29, 2025.

  1. Stack

    Stack Membro Participativo

    I'm doing a heavy Quasi Monte Carlo simulation using the Sobol sequence, I need the generator to be able to create over 2 ** 30 samples. SciPy says that the generator is capped at 2 ** 30. It says also that by modifying the argument bits it should be possible to lift the limit to a maximium of 2 ** 64 (That is enough for me).

    sampler = qmc.Sobol(d=2, scramble=True, bits=64)

    However I still encounter the same bug, at exactly 25 per cent of the function, everything stops without error message. I am sure the problem is in the generator because i have tried moving it inside the for loop and it worked, however regenerating the Sobol sequence each time i think might cause math trouble with QMC properties.

    Here it is the code in a minimal reproducible version (You must have CUDA installed)

    import cupy as cp
    from scipy.stats import qmc
    from tqdm import tqdm
    import os


    def run_simulation_batch_cupy_QMC(samples, a):
    batch_size = 2 ** 27
    n_batches = samples // batch_size
    sampler = qmc.Sobol(d=2, scramble=True, bits=64)

    for i in tqdm(range(n_batches)):

    qmc_samples = sampler.random(n=batch_size)

    #Here there is some computation I cut off

    cuda_bin_path = r"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.9\bin"
    os.add_dll_directory(cuda_bin_path)

    if __name__ == "__main__":

    samples = 2 ** 34 #Samples must be, to get the bug, greater than 10 ** 10 and a power of 2 so 2**34
    a_values = [1.1, 1.2, 1.3] #Example

    for a in tqdm(a_values):
    run_simulation_batch_cupy_QMC(samples, a)



    I was expecting the function to complete the generation. Monitoring the GPU and other I can say I do not get an memory overflow. The GPU just stop calculating exactly at 25 %.

    Continue reading...

Compartilhe esta Página