Qcodes icon indicating copy to clipboard operation
Qcodes copied to clipboard

[WIP] Extract API calls in Alazar class + some async work

Open cgranade opened this issue 7 years ago • 3 comments

NOTE: see comments below to understand the future of this PR.

This PR follows discussions with @astafan8, and extracts all C-level calls to the Alazar SDK into its own class to make it easier for that class to manage the use of background threads. To do so, this PR includes a metatype that converts a list of ctypes signatures into sync and async methods that both ensure that all calls to the Alazar SDK are executed in the same ThreadPoolExecutor. Refactoring in this way allows for the acquire method to be simplified, as ownership of threads and some memory management can be extracted. For example, work is in progress on this PR to allow for buffer allocation and posting to be done concurrently by using asyncio.gather to join after all buffers have been successfully posted. Similarly, extracting and unifying the sync/async APIs in this way allowed for making find_boards_async(), which may help speed up init scripts for stations which depend on Alazar initialization.

Still TODO:

  • [ ] Docstrings and comments are still pretty sparse.
  • [ ] More logic needs extracted from acquire to make it easier to reuse buffers across acquire calls.
  • [ ] Testing
  • [x] The DLL wrapper is still somewhat coupled to the Alazar usage, but could be generalized to provide thread-safe async wrappers for common C APIs.
  • [x] The ctypes return values of metatype-time generated methods are saved as type annotations, but argument types are not due to complications with mypy's semantics for *args.
  • [ ] Other methods like get_idn are still blocking, reducing parallelization of init scripts

cgranade avatar Nov 08 '18 15:11 cgranade

I'm going to continue working on this PR. (the field-vector related stuff does not belong to this PR, and will be removed from it)

astafan8 avatar Nov 12 '18 08:11 astafan8

I removed field-vector-related changes from this PR. Also resolved merge conflict which came due to changes in mercury IPS driver.

What's left in this PR:

  • Alazar API refactoring
  • attempt to make ALazar driver async
  • attempt to make mercury IPS driver async ( + test )
  • async utils

All the async things will be done later in other PRs. The Alazar API refactoring will be continued, but yet in a different PR.

astafan8 avatar Feb 13 '19 18:02 astafan8

UPDATE: what's left in this PR:

  • attempt to make ALazar driver async
  • attempt to make mercury IPS driver async ( + test )
  • async utils

All of these will be done later in other PRs.

This PR is left open for reference and history reasons.

astafan8 avatar Apr 12 '19 09:04 astafan8