quantumaudio.tools
- quantumaudio.tools.test_signal(num_samples=8, num_channels=1, seed=None)[source]
Simulates sythetic data for quick testing and plots. Typically, Audio data contains several thousands of samples per second which is difficult to visualise as circuit and plot.
- Parameters:
num_channels (int) – The number of channels for each sample. Defaults to 1.
num_samples (int) – The number of samples to generate.
seed (int | None) – The seed for the random number generator. Defaults to 42.
- Returns:
A numpy array of simulated data.
- Return type:
ndarray
quantumaudio.tools.plot
- quantumaudio.tools.plot.plot_1d(samples, title=None, label=('original', 'reconstructed'))[source]
Plots the given samples.
- Parameters:
samples (ndarray) – The samples to plot.
title (str | None) – Title for the plot. Defaults to None.
label (tuple[str, str]) – Labels for the samples. Defaults to (“original”, “reconstructed”).
- Returns:
None
- Return type:
None
- quantumaudio.tools.plot.plot(samples, title=None, label=('original', 'reconstructed'), figsize=(6, 4))[source]
Plots the given samples. It accepts multi-dimensional array and also multiple plots for comparisons.
- Parameters:
samples (ndarray | list[ndarray]) – The samples to plot. Can be a single numpy array or a list of numpy arrays.
title (str | None) – Title for the plot. Defaults to None.
label (tuple[str, str]) – Labels for the samples. Defaults to (“original”, “reconstructed”).
figsize (tuple[int, int]) – Set the width and height for matplotlib plot
- Returns:
None
- Return type:
None
quantumaudio.tools.stream
- quantumaudio.tools.stream.get_chunks(data, chunk_size=256, verbose=False)[source]
Splits a numpy array into smaller chunks of specified size.
This function takes a long array and divides it into smaller chunks, which can be useful for processing large datasets in manageable pieces.
- Parameters:
data (ndarray) – The input array to be split. The array can be one-dimensional or two-dimensional. If one-dimensional, it will be reshaped into two dimensions.
chunk_size (int) – The size of each chunk. Default is 256.
verbose (bool) – If True, prints detailed information about the data and chunks. Default is False.
- Returns:
None
- Return type:
None
- quantumaudio.tools.stream.process(chunk, scheme, backend=None, shots=8000)[source]
Process a chunk of data according to a specified scheme by encoding it and decoding it back.
- Parameters:
chunk (ndarray) – Data chunk to be processed.
scheme (quantumaudio.schemes.Scheme) – Processing scheme.
backend (Any) – A valid Backend object accepted by the execute function at decode. Defaults to qiskit_aer.AerSimulator().
shots (int) – Number of shots.
- Returns:
None
- Return type:
ndarray
- quantumaudio.tools.stream.process_chunks(chunks, scheme, process_function=<function process>, batch_process=False, verbose=True, **kwargs)[source]
Process chunks of data in an iteration according to a specified scheme.
- Parameters:
chunks (list[ndarray]) – Data chunks to be processed.
scheme (quantumaudio.schemes.Scheme) – Processing scheme.
process_function (Callable[[ndarray, Any, dict], list]) – Function to process each chunk (default is ‘process’).
verbose (bool) – If True, enables verbose logging. Defaults to False.
batch_process (bool)
- Returns:
None
- Return type:
list
- quantumaudio.tools.stream.combine_chunks(chunks)[source]
Combine a list of numpy arrays along an axis based on the data dimension.
- Parameters:
chunks (list[ndarray]) – A list of numpy arrays to be combined.
- Returns:
np.ndarray
- Return type:
ndarray
- quantumaudio.tools.stream.normalize(data)[source]
Normalize the input data to ensure it lies within the standard range [-1.0, 1.0].
- Parameters:
data (ndarray) – Input array containing audio data.
- Return type:
ndarray
- quantumaudio.tools.stream.stream_data(data, scheme, chunk_size=64, process_function=<function process>, batch_process=False, verbose=2, **kwargs)[source]
Processes data by dividing it into chunks, applying a Quantum Audio scheme, and combining the results.
- Parameters:
data (ndarray) – The input data array to be processed.
scheme (quantumaudio.schemes.Scheme) – The quantum audio scheme to be applied to each chunk.
chunk_size (int) – The size of each chunk. Defaults to 64.
process_function (Callable[[ndarray, Any, dict], list]) –
Function to process each chunk.
Defaults to
process()which accepts any additional **kwargs.
batch_process (bool) – Boolean value to inidicate whether the provided process_function applies to a single chunk or a batch.
verbose (int | bool) –
If True, enables verbose logging. Defaults to 2.
>1: Shows progress bar.
>2: Shows additional information such as buffer size and number of qubits.
- Returns:
np.ndarray
- Return type:
ndarray