quchip.utils.memory

Memory estimates, and checks against the memory available to this process.

Call sites name what they allocate, for example the eigensystem of a matrix of dimension D, and the estimators below turn that into bytes. Each backend adds the cost of its own lowering and solvers. require_memory() refuses an allocation that cannot fit before quchip makes it.

Functions

available_memory_bytes()

Return the memory this process can still allocate, or None when unknown.

dense_bytes(*shape[, copies, itemsize])

Return the bytes of copies dense arrays of shape.

eigensystem_bytes(dimension)

Return the peak bytes of the dense Hermitian eigensystem of a square matrix.

fits_memory(required)

Return whether an estimated allocation fits, and True when memory is unknown.

krylov_bytes(size, vectors)

Return the bytes of a Krylov basis.

level_table_bytes(states, devices)

Return the bytes of a table that gives the level of each device in each product state.

require_memory(required, *, task, remedy)

Raise MemoryError before an allocation that cannot fit.

sparse_lu_bytes(matrix)

Return a low estimate of the bytes of the sparse LU factors of a square matrix.

quchip.utils.memory.dense_bytes(*shape, copies=1, itemsize=16)[source]

Return the bytes of copies dense arrays of shape.

Parameters:
  • *shape (int) – Shape of one array.

  • copies (int, default=1) – Number of arrays that exist at the same time.

  • itemsize (int, default=16) – Bytes of one entry. The default is a complex double.

quchip.utils.memory.eigensystem_bytes(dimension)[source]

Return the peak bytes of the dense Hermitian eigensystem of a square matrix.

Parameters:

dimension (int) – Number of rows of the matrix.

quchip.utils.memory.level_table_bytes(states, devices)[source]

Return the bytes of a table that gives the level of each device in each product state.

Parameters:
  • states (int) – Number of product states.

  • devices (int) – Number of devices.

quchip.utils.memory.krylov_bytes(size, vectors)[source]

Return the bytes of a Krylov basis.

Parameters:
  • size (int) – Number of entries of one vector.

  • vectors (int) – Number of vectors that the basis keeps.

quchip.utils.memory.sparse_lu_bytes(matrix)[source]

Return a low estimate of the bytes of the sparse LU factors of a square matrix.

SuperLU knows its fill only after the factorization, so the estimate is a quarter of the reverse Cuthill-McKee envelope of the symmetrized pattern. For a few modes with many levels the envelope grows faster than the fill, and the estimate can exceed the fill of a resonator with many hundreds of levels.

Parameters:

matrix (scipy.sparse matrix or array) – Square matrix.

quchip.utils.memory.available_memory_bytes()[source]

Return the memory this process can still allocate, or None when unknown.

The value is the available system memory that psutil reports. Under a cgroup v2 memory limit, as in many Linux containers, the value is the remaining limit when that is smaller.

quchip.utils.memory.fits_memory(required)[source]

Return whether an estimated allocation fits, and True when memory is unknown.

Parameters:

required (float) – Estimated peak allocation in bytes.

quchip.utils.memory.require_memory(required, *, task, remedy)[source]

Raise MemoryError before an allocation that cannot fit.

Parameters:
  • required (float) – Estimated peak allocation in bytes.

  • task (str) – What would allocate it, for the error message.

  • remedy (str) – How to avoid the allocation.