pygsti.tools.sharedmemtools
Utility functions for working with shared memory
Module Contents
Classes
Numpy array with metadata for referencing how this "local" array is part |
Functions
Whether shared memory functionality is available (Python 3.8+) |
|
|
Creates a numpy.ndarray that is potentially shared between processors. |
De-allocates a (potentially) shared numpy array, created by |
- class pygsti.tools.sharedmemtools.LocalNumpyArray(shape, dtype=float, buffer=None, offset=0, strides=None, order=None)
Bases:
numpy.ndarray
Numpy array with metadata for referencing how this “local” array is part of a larger shared memory array.
- pygsti.tools.sharedmemtools.shared_mem_is_enabled()
Whether shared memory functionality is available (Python 3.8+)
Returns
bool
- pygsti.tools.sharedmemtools.create_shared_ndarray(resource_alloc, shape, dtype, zero_out=False, memory_tracker=None)
Creates a numpy.ndarray that is potentially shared between processors.
A shared memory array is created when resource_alloc.host_comm is not None, in which case it indicates which processors belong to the same host and have access to the same shared memory.
Parameters
- resource_allocResourceAllocation
The resource allocation object containing information about whether or not to create shared memory arrays and how to do so (see above).
- shapetuple
The shape of the returned array
- dtypenumpy.dtype
The numpy data type of the returned array.
- zero_outbool, optional
Whether to initialize the array to all zeros. When True, this function behaves as numpy.zeros; when False as numpy.empty.
- memory_trackerResourceAllocation, optional
If not none, callc memory_tracker.add_tracked_memory to track the size of the allocated array.
Returns
- arnumpy.ndarray
The potentially shared-memory array.
- shmmultiprocessing.shared_memory.SharedMemory
A shared memory object needed to cleanup the shared memory. If a normal array is created, this is None. Provide this to
cleanup_shared_ndarray()
to ensure ar is deallocated properly.
- pygsti.tools.sharedmemtools.cleanup_shared_ndarray(shm)
De-allocates a (potentially) shared numpy array, created by
create_shared_ndarray()
.Parameters
- shmmultiprocessing.shared_memory.SharedMemory or None
The shared memory object to deallocate. If None, no deallocation is is performed.
Returns
None