quantumaudio.utils.circuit
quantumaudio.utils.convert
- quantumaudio.utils.convert.convert_to_probability_amplitudes(array)[source]
Converts an array to probability amplitudes.
- Parameters:
array (ndarray) – The input array.
- Returns:
A tuple containing the norm and the array of probability amplitudes.
- Return type:
tuple[float, ndarray]
- quantumaudio.utils.convert.convert_to_angles(array)[source]
Converts an array of values to angles. The conversion is done using the formula:
arcsin(sqrt((x + 1) / 2))
- Parameters:
array (ndarray) – The input array. Values must be in the range [-1, 1].
- Returns:
The array of angles.
- Return type:
ndarray
- quantumaudio.utils.convert.quantize(array, qubit_depth)[source]
Quantizes the array to a given qubit depth.
- Parameters:
array (ndarray) – The input array.
qubit_depth (int) – The number of bits to quantize to.
- Returns:
The quantized array as integers.
- Return type:
ndarray
- quantumaudio.utils.convert.convert_from_probability_amplitudes(probabilities, norm, shots)[source]
Converts probability amplitudes to the original data range.
- Parameters:
probabilities (ndarray) – The array of probability amplitudes.
norm (float) – The normalization factor.
shots (int) – The number of measurement shots.
- Returns:
The array of original data values.
- Return type:
ndarray
- quantumaudio.utils.convert.convert_from_angles(cosine_amps, sine_amps, inverted=False)[source]
Converts angles back to the original data range.
- Parameters:
cosine_amps (ndarray) – The cosine amplitude array.
sine_amps (ndarray) – The sine amplitude array.
inverted (bool) – If True, uses cosine amplitudes instead of sine amplitudes. Defaults to False.
- Returns:
The array of original data values.
- Return type:
ndarray
quantumaudio.utils.data
- quantumaudio.utils.data.is_within_range(arr, min_val, max_val)[source]
Checks if all elements in the array are within the specified range.
- Parameters:
arr (ndarray) – The input array.
min_val (float) – The minimum value of the range.
max_val (float) – The maximum value of the range.
- Returns:
True if all elements are within the range, False otherwise.
- Return type:
bool
- quantumaudio.utils.data.validate_data(data)[source]
Ensure the input data is a numpy array and that its values are within the digital audio range: -1.0 to 1.0.
- Parameters:
data (list | tuple | ndarray) – Input data array.
- Return type:
None
- quantumaudio.utils.data.split_string(input_str, lengths)[source]
Splits the input string into segments based on the specified lengths.
- Parameters:
input_str – The string to be split.
lengths – A list of integers representing the lengths of each segment.
- Returns:
A list of substrings split according to the specified lengths.
- quantumaudio.utils.data.apply_index_padding(array, num_index_qubits)[source]
Applies zero-padding to 1-D array based on the specified number of index qubits.
- Parameters:
array (ndarray) – The input array to be padded.
num_index_qubits (int) – The number of qubits to determine the padding length.
- Returns:
The padded array.
- Return type:
ndarray
- quantumaudio.utils.data.apply_padding(array, num_qubits)[source]
Applies zero-padding to both dimensions of a 2-D array based on the specified number of index qubits.
- Parameters:
array (ndarray) – The input array to be padded.
num_qubits ((<class 'int'>, <class 'int'>)) – The padding length at each dimension is determined by number of channel qubits and number of index qubits respectively.
- Returns:
The padded array.
- Return type:
ndarray
- quantumaudio.utils.data.get_bit_depth(signal)[source]
Determines the bit depth of a given signal.
- Parameters:
signal (ndarray) – The input signal.
- Returns:
The bit depth of the signal.
- Return type:
int
- quantumaudio.utils.data.get_qubit_count(data_length)[source]
Calculates the number of qubits required to represent a given data length.
- Parameters:
data_length (int) – The length of the data.
- Returns:
The number of qubits needed to represent the data length.
- Return type:
int
- quantumaudio.utils.data.interleave_channels(array)[source]
Interleaves the channels of a given array.
- Parameters:
array (ndarray) – The input array with shape (samples, channels).
- Returns:
A 1-dimensional array with interleaved channels.
- Return type:
ndarray
- quantumaudio.utils.data.restore_channels(array, num_channels)[source]
Restores the interleaved channels into their original form.
- Parameters:
array (ndarray) – The input array with interleaved channels.
num_channels (int) – The number of channels.
- Returns:
The array with shape (samples, channels).
- Return type:
ndarray
quantumaudio.utils.execute
- quantumaudio.utils.execute.execute(circuit, shots=8000, backend=None, keep_memory=False, optimization_level=3)[source]
Executes a quantum circuit on a given backend and return the results.
- Parameters:
circuit (qiskit.QuantumCircuit) – The quantum circuit to be executed.
backend (Any) – The backend on which to run the circuit. If None, the default backend qiskit_aer.AerSimulator() is used.
shots (int) – Total number of times the quantum circuit is measured.
keep_memory (bool) – Whether to return the memory (quantum state) of each shot.
optimization_level (int) – Optimization level for transpiling the circuit.
- Returns:
The result of the execution, containing the counts and other metadata.
- Return type:
Result
- quantumaudio.utils.execute.execute_with_sampler(circuit, backend=None, shots=8000, optimization_level=3)[source]
Executes a quantum circuit on a given backend using Sampler Primitive and return the results.
- Parameters:
circuit (qiskit.QuantumCircuit) – The quantum circuit to be executed.
backend (Any) – The backend on which to run the circuit. If None, the default backend qiskit_aer.AerSimulator() is used.
shots (int) – Total number of times the quantum circuit is measured.
optimization_level (int) – Optimization level for transpiling the circuit.
- Returns:
The result of the execution, containing the counts and other metadata.
- Return type:
Result
quantumaudio.utils.preview
- quantumaudio.utils.preview.print_num_qubits(num_qubits, labels)[source]
Prints the number of qubits required and their allocation per label.
- Parameters:
num_qubits (tuple[int, ...]) – List of integers representing the number of qubits.
labels (tuple[str, ...]) – List of strings representing labels for each qubit allocation.
- Return type:
None
quantumaudio.utils.results
- quantumaudio.utils.results.pad_counts(counts)[source]
Pads the counts to its full length covering all basis states.
- Parameters:
counts (dict | Counts) – Counts dictionary
- Returns:
Padded counts dictionary
- Return type:
counts
- quantumaudio.utils.results.get_counts(results_obj, result_id=0)[source]
Extract counts from a results object.
- Parameters:
results_obj – An instance of PrimitiveResult or Result object from which to extract counts.
result_id – The index of the result to extract if the results object contains multiple results.
- Returns:
The counts of measurements from the results object.
- Return type:
counts
- quantumaudio.utils.results.get_metadata(results_obj, result_id=0)[source]
Extract metadata from a results object.
- Parameters:
results_obj – An instance of PrimitiveResult or Result object from which to extract metadata.
result_id – The index of the result to extract if the results object contains multiple results.
- Returns:
The metadata associated with the result.
- Return type:
metadata
- quantumaudio.utils.results.get_counts_and_metadata(results_obj, result_id=0)[source]
Extract counts and metadata from a results object.
- Parameters:
results_obj – An instance of PrimitiveResult or Result object from which to extract counts and metadata.
result_id – The index of the result to extract if the results object if it contains multiple results.
- Returns:
The counts of measurements from the results object. metadata: The metadata associated with the result.
- Return type:
counts
- quantumaudio.utils.results.pick_key_from_instance(instance, key)[source]
Search for given key in an instance used at decoding.
- Parameters:
instance – Can be Qiskit Circuit or Result object.
key – Key to find in the encoded metadata.
- quantumaudio.utils.results.pick_key(kwargs, instance, key)[source]
Search for given key in key words dictionary first if user manually specified or continue searching for key using instances
- Parameters:
kwargs – Keyword arguments dictionary.
instance – Can be Qiskit Circuit or Result object.
key – Key to find in the encoded metadata.