QStream – Working with quantum datastreams

class squanch.qstream.QStream(system_size, num_systems, array=None, agent=None)[source]

Bases: object

Efficiently represents many separable quantum subsystems in a contiguous block of shared memory. QSystem``s and ``Qubit``s can be instantiated from the ``state of this class.

__init__(system_size, num_systems, array=None, agent=None)[source]

Instantiate the quantum datastream object

Parameters:
  • system_size (int) – number of entangled qubits in each quantum system; each system has dims 2^system_size
  • num_systems (int) – number of small quantum systems in the data stream
  • array (np.array) – pre-allocated array in memory for purposes of sharing QStreams in multiprocessing
  • agent (Agent) – optional reference to the Agent owning the qstream; useful for progress monitoring across separate processes
__iter__()[source]

Iterates over the ``QSystem``s in this class instance

Returns:each system in the stream
__len__()[source]

Custom length method for streams; equivalent to stream.num_systems

Returns:stream.num_systems
__weakref__

list of weak references to the object (if defined)

classmethod from_array(array, reformat=False, agent=None)[source]

Instantiates a quantum datastream object from an existing state array

Parameters:
  • array (np.array) – the pre-allocated np.complex64 array representing the shared Hilbert space
  • reformat (bool) – if providing a pre-allocated array, whether to reformat it to the all-zero state
Returns:

the child QStream

next()[source]

Access the next element in the quantum stream, returning it as a QSystem object, and increment the head by 1

Returns:a QSystem for the “head” system
static reformat()[source]

Reformats a Hilbert space array in-place to the all-zero state

Parameters:array (np.array) – a num_systems x 2^system_size x 2^system_size array of np.complex64 values
static shared_hilbert_space(num_systems)[source]

Allocate a portion of shareable c-type memory to create a numpy array that is sharable between processes

Parameters:
  • system_size (int) – number of entangled qubits in each quantum system; each has dimension 2^system_size
  • num_systems (int) – number of small quantum systems in the data stream
Returns:

a blank, sharable, num_systems * 2^system_size * 2^system_size array of np.complex64 values

system(index)[source]

Access the nth quantum system in the quantum datastream object

Parameters:index (int) – zero-index of the quantum system to access
Returns:the quantum system