Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Speedup of _correlation_3op_dm #2315 through parallel taulist simulations #2395

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

valleyofblackpanther
Copy link

Objective

The primary objective was to improve the computational efficiency of the correlation_2op_1t function in QuTiP. This function computes two-time correlations for quantum systems, which is computationally intensive, especially for large systems or long time arrays. The goal was to enhance performance by parallelizing these computations.

Enhancements Overview

  1. Parallel Computing:

    • Implementation: Utilized Python’s concurrent.futures module, specifically ProcessPoolExecutor, to parallelize the computation of correlation values over different tau values (taulist). Each tau value computation is independent of others, making this a suitable case for parallel execution.
    • Function Splitting: Created a helper function compute_single_tau_correlation to handle the computation for a single tau. This function manages the setup of the quantum system, computes the correlation for its specific tau, and handles any exceptions that may occur, logging them accordingly.
    • Resource Management: Used the cpu_count from the os module to dynamically determine the number of available processors and limited the number of worker processes to avoid overwhelming the host system. This approach helps in balancing load and performance.
  2. Error Handling and Robustness:

    • Enhanced the resilience of the parallel computation by encapsulating the worker function’s body in a try-except block, ensuring that failures in one computation do not impact the overall execution.
    • Ensured the stability of the test environment by restoring the original function state after the test execution, preventing side effects on subsequent tests.
  3. Testing:

    • Extended Test Coverage: Developed new test cases to validate both the parallel and sequential execution paths of the function. Tests ensure that both modes produce equivalent results, thereby confirming that the parallelization did not introduce computational errors.
    • Integration with Existing Tests: Integrated the new tests into the existing pytest framework used for QuTiP, making use of fixtures and parameterization to test different scenarios and system setups effectively.

Implementation Details

  • Concurrency: The parallel execution is managed through a pool of processes, where each process is responsible for a subset of the total computations. This method is particularly effective for operations that can be divided into independent, smaller tasks.
  • Compatibility: Ensured that the enhancements are backward-compatible with existing code by modifying only the internal execution strategy of the correlation_2op_1t function and by maintaining the original API signature.
  • Performance Considerations: The parallel implementation can significantly reduce computation times, particularly for larger systems or longer taulist arrays, by leveraging multiple CPU cores concurrently.

Conclusion

The enhancements to the correlation_2op_1t function in QuTiP are designed to harness the capabilities of modern multi-core processors, thereby improving the efficiency of quantum correlation computations. This is still a WIP enhancement.

@valleyofblackpanther valleyofblackpanther marked this pull request as draft April 16, 2024 23:37
@pmenczel
Copy link
Member

Hi and thank you for your contribution! I see that this is still a draft, but I wanted to quickly point out qutip's existing parallel module: https://qutip.readthedocs.io/en/master/apidoc/functions.html#module-qutip.solver.parallel
The module offers functions which can either execute tasks serially (serial_map) or in parallel (parallel_map, loky_pmap, mpi_pmap). For example in the Monte Carlo solver, the map option decides which of these functions is used, allowing users to switch easily between serial and parallel execution. These functions also come with error handling already, and they select a default number of processes based on the CPU count. It would be nice to have such a map option for the calculation of correlation functions.
Are you planning to make similar modifications also to the other types of correlation function in the same module?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants