quantumaudio.schemes.Scheme

class quantumaudio.schemes.base_scheme.Scheme[source]

Bases: ABC

Abstract base class for Quantum Audio Schemes.

This class defines the bare minimum interface that any specific modulation scheme must follow. Subclasses should provide implementations of the encode and decode methods according to the specifics of their modulation schemes.

abstract encode(data)[source]

Encode the input data using the scheme.

Parameters:

data (ndarray) – A numpy array containing the data to be encoded.

Returns:

A qiskit.QuantumCircuit representing the encoded data.

Return type:

QuantumCircuit

abstract decode(circuit)[source]

Decode the quantum circuit using the scheme.

Parameters:

circuit (QuantumCircuit) – A qiskit.QuantumCircuit that contains the encoded data.

Returns:

A numpy array containing the decoded data.

Return type:

ndarray

quantumaudio.schemes.qpam

class quantumaudio.schemes.qpam.QPAM[source]

Bases: Scheme

Quantum Probability Amplitude Modulation (QPAM).

QPAM class implements encoding and decoding of Digital Audio as Quantum Probability Amplitudes. It’s the simplest of Schemes and uses Qiskit circuit’s initialize method to set the Quantum States based on provided values. The values are normalized before encoding using the convert method.

calculate(data, verbose=True)[source]

Returns necessary information required for Encoding and Decoding:

  • Number of qubits required to encode both Time and Amplitude information.

  • Original number of samples required for decoding.

Parameters:
  • data (ndarray) – Array representing Digital Audio Samples.

  • verbose (int | bool) – Prints the Qubit information if True or int > 0.

Returns:

A Tuple of (num_samples, qubit_shape).

qubit_shape is a Tuple (int, int) consisting of:
  • num_index_qubits to encode Time Information (x-axis).

  • num_value_qubits to encode Amplitude Information (y-axis).

Return type:

Tuple[int, Tuple[int, int]]

prepare_data(data, num_index_qubits)[source]

Prepares the data with appropriate dimensions for encoding:

  • It pads the length of data with zeros to fit the number of states that can be represented with num_index_qubits.

  • It also removes redundant dimension if the shape is (1,num_samples).

Parameters:
  • data (ndarray) – Array representing Digital Audio Samples

  • num_index_qubits (int) – Number of qubits used to encode the sample indices.

Returns:

Array with dimensions suitable for encoding.

Return type:

ndarray

Note

This method should be followed by convert() method to convert the values suitable for encoding.

initialize_circuit(num_index_qubits, num_value_qubits)[source]

Initializes the circuit with Index and Value Registers.

Parameters:
  • num_index_qubits (int) – Number of qubits used to encode the sample indices.

  • num_value_qubits (int) – Number of qubits used to encode the sample values.

Returns:

Qiskit Circuit with the registers

Return type:

QuantumCircuit

value_setting(circuit, values)[source]

Encodes the prepared, converted values to the initialised circuit.

Parameters:
  • circuit (QuantumCircuit) – Initialized Qiskit Circuit

  • values (ndarray) – Array of probability amplitudes to encode

Return type:

None

measure(circuit)[source]

Adds classical measurements to all qubits of the Quantum Circuit if the circuit is not already measured.

Parameters:

circuit (QuantumCircuit) – Encoded Qiskit Circuit

Return type:

None

encode(data, measure=True, verbose=1)[source]

Given audio data, prepares a Qiskit Circuit representing it.

Parameters:
  • data (ndarray) – Array representing Digital Audio Samples

  • measure (bool) – Adds measurement to the circuit if set True or int > 0.

  • verbose (int | bool) –

    Level of information to print.

    • >1: Prints number of qubits required.

    • >2: Displays the encoded circuit.

Returns:

A Qiskit Circuit representing the Digital Audio

Return type:

QuantumCircuit

decode_components(counts)[source]

The first stage of decoding is extracting required components from counts.

Parameters:

counts (dict | Counts) – a dictionary with the outcome of measurements performed on the quantum circuit.

Returns:

Array of components for further decoding.

Return type:

ndarray

reconstruct_data(counts, shots, norm)[source]

Given counts, Extract components and restore the conversion did at encoding stage.

Parameters:
  • counts (dict | Counts) – a dictionary with the outcome of measurements performed on the quantum circuit.

  • shots (int) – total number of times the quantum circuit is measured.

  • norm (float) – the norm factor used to normalize the decoding in QPAM.

Returns:

Array of restored values

Return type:

ndarray

decode_counts(counts, metadata, shots=4000, norm=None, keep_padding=False)[source]

Given a Qiskit counts object or Dictionary, Extract components and restore the conversion did at encoding stage.

Parameters:
  • counts (dict | Counts) – a qiskit Counts object or Dictionary obtained from a job result.

  • metadata (dict) – metadata required for decoding.

  • shots (int | None) – total number of times the quantum circuit is measured.

  • norm (float | None) – Override the norm factor used to normalize the decoding.

  • keep_padding (bool) – Undos the padding set at Encoding stage if set to False.

Returns:

Array of restored values with original dimensions

Return type:

ndarray

decode_result(result, metadata=None, shots=8000, norm=None, keep_padding=False)[source]

Given a Qiskit Result object, Extract components and restore the conversion did at encoding stage.

Parameters:
  • result (Result) – a qiskit Result object that contains counts along with metadata that was held by the original circuit.

  • metadata (dict | None) – optionally pass metadata as argument.

  • shots (int | None) – total number of times the quantum circuit is measured.

  • norm (float | None) – Override the norm factor used to normalize the decoding.

  • keep_padding (bool) – Undos the padding set at Encoding stage if set to False.

Returns:

Array of restored values with original dimensions

Return type:

ndarray

decode(circuit, metadata=None, shots=8000, norm=None, keep_padding=False, execute_function=<function execute>, **kwargs)[source]

Given a qiskit circuit, decodes and returns back the Original Audio Array.

Parameters:
  • circuit (QuantumCircuit) – A Qiskit Circuit representing the Digital Audio.

  • metadata (dict | None) – optionally pass metadata as argument.

  • shots (int | None) – Total number of times the quantum circuit is measured.

  • norm (float | None) – The norm factor used to normalize the decoding in QPAM.

  • keep_padding (bool) – Undo the padding set at Encoding stage if set to False.

  • execute_function (Callable[[QuantumCircuit, dict], Any]) –

    Function to execute the circuit for decoding.

    • Defaults to utils.execute which accepts any additional **kwargs.

    • The keyword argument shots (int) is a metadata for QPAM decoding and accepted by execute_function. (Defaults to 8000)

Returns:

Array of decoded values

Return type:

ndarray

quantumaudio.schemes.sqpam

class quantumaudio.schemes.sqpam.SQPAM[source]

Bases: Scheme

Single-Qubit Probability Amplitude Modulation (SQPAM).

SQPAM class implements an encoding and decoding scheme where the amplitude of a Digital signal is encoded through rotation gates acting on a single-qubit. It is controlled by qubits of register that represent the corresponding time index.

calculate(data, verbose=True)[source]

Returns necessary information required for Encoding and Decoding:

  • Number of qubits required to encode both Time and Amplitude information.

  • Original number of samples required for decoding.

Parameters:
  • data (ndarray) – Array representing Digital Audio Samples.

  • verbose (int | bool) – Prints the Qubit information if True or int > 0.

Returns:

A Tuple of (num_samples, qubit_shape)

qubit_shape is a Tuple (int, int) consisting of:
  • num_index_qubits to encode Time Information (x-axis).

  • num_value_qubits to encode Amplitude Information (y-axis).

Return type:

Tuple[int, Tuple[int, int]]

prepare_data(data, num_index_qubits)[source]

Prepares the data with appropriate dimensions for encoding:

  • It pads the length of data with zeros to fit the number of states that can be represented with num_index_qubits.

  • It also removes redundant dimension if the shape is (1,num_samples).

Parameters:
  • data (ndarray) – Array representing Digital Audio Samples

  • num_index_qubits (int) – Number of qubits used to encode the sample indices.

Returns:

Array with dimensions suitable for encoding.

Return type:

ndarray

Note

This method should be followed by convert() method to convert the values suitable for encoding.

initialize_circuit(num_index_qubits, num_value_qubits)[source]

Initializes the circuit with Index and Value Registers.

Parameters:
  • num_index_qubits (int) – Number of qubits used to encode the sample indices.

  • num_value_qubits (int) – Number of qubits used to encode the sample values.

Returns:

Qiskit Circuit with the registers

Return type:

QuantumCircuit

value_setting(circuit, index, value)[source]

Encodes the prepared, converted values to the initialised circuit. This function is used to set a single value at a single index. The decorator with_indexing applies the necessary control qubits corresponding to the given index.

Parameters:
  • circuit (QuantumCircuit) – Initialized Qiskit Circuit

  • index (int) – position to set the value

  • value (float) – value to be set at the index

Return type:

None

measure(circuit)[source]

Adds classical measurements to all registers of the Quantum Circuit if the circuit is not already measured.

Parameters:

circuit (QuantumCircuit) – Encoded Qiskit Circuit

Return type:

None

encode(data, measure=True, verbose=1)[source]

Given an audio data, prepares a Qiskit Circuit representing it.

Parameters:
  • data (ndarray) – Array representing Digital Audio Samples

  • measure (bool) – Adds measurement to the circuit if set True or int > 0.

  • verbose (int | bool) –

    Level of information to print.

    • >1: Prints number of qubits required.

    • >2: Displays the encoded circuit.

Returns:

A Qiskit Circuit representing the Digital Audio

Return type:

QuantumCircuit

decode_components(counts, qubit_shape)[source]

The first stage of decoding is extracting required components from counts.

Parameters:
  • counts (dict | Counts) – a dictionary with the outcome of measurements performed on the quantum circuit.

  • qubit_shape ([<class 'int'>, <class 'int'>]) – Tuple to determine the number of cosine and sine components to get.

Returns:

Array of components for further decoding.

Return type:

ndarray

reconstruct_data(counts, qubit_shape, inverted=False)[source]

Given counts, Extract components and restore the conversion did at encoding stage.

Parameters:
  • counts (dict | Counts) – a dictionary with the outcome of measurements performed on the quantum circuit.

  • qubit_shape ([<class 'int'>, <class 'int'>]) – Tuple to determine the number of cosine and sine components to get.

  • inverted (bool) – retrieves cosine components of the signal.

Returns:

Array of restored values

Return type:

ndarray

decode_counts(counts, metadata, inverted=False, keep_padding=False)[source]

Given a Qiskit counts object or Dictionary, Extract components and restore the conversion did at encoding stage.

Parameters:
  • counts (dict | Counts) – a qiskit Counts object or Dictionary obtained from a job result.

  • metadata (dict) – metadata required for decoding.

  • inverted (bool) – retrieves cosine components of the signal.

  • keep_padding (bool) – Undo the padding set at Encoding stage if set False.

Returns:

Array of restored values with original dimensions

Return type:

ndarray

decode_result(result, metadata=None, inverted=False, keep_padding=False)[source]

Given a result object. Extract components and restore the conversion did in encoding stage.

Parameters:
  • result (Result) – a qiskit Result object that contains counts along with metadata that was held by the original circuit.

  • metadata (dict | None) – optionally pass metadata as argument.

  • inverted (bool) – retrieves cosine components of the signal.

  • keep_padding (bool) – Undo the padding set at Encoding stage if set False.

Returns:

Array of restored values with original dimensions

Return type:

ndarray

decode(circuit, metadata=None, inverted=False, keep_padding=False, execute_function=<function execute>, **kwargs)[source]

Given a qiskit circuit, decodes and returns back the Original Audio Array.

Parameters:
  • circuit (QuantumCircuit) – A Qiskit Circuit representing the Digital Audio.

  • metadata (dict | None) – optionally pass metadata as argument.

  • inverted (bool) – retrieves cosine components of the signal.

  • keep_padding (bool) – Undo the padding set at Encoding stage if set False.

  • execute_function (Callable[[QuantumCircuit, dict], Any]) –

    Function to execute the circuit for decoding.

    • Defaults to utils.execute which accepts any additional **kwargs.

Returns:

Array of decoded values

Return type:

ndarray

quantumaudio.schemes.qsm

class quantumaudio.schemes.qsm.QSM(qubit_depth=None)[source]

Bases: Scheme

Quantum State Modulation (QSM).

QSM class implements an encoding and decoding scheme where the amplitude of a Digital signal is encoded as qubit states controlled by qubits of time register that represent the corresponding time index.

Parameters:

qubit_depth (int | None)

calculate(data, verbose=True)[source]

Returns necessary information required for Encoding and Decoding:

  • Number of qubits required to encode both Time and Amplitude information.

  • Original number of samples required for decoding.

Parameters:
  • data (ndarray) – Array representing Digital Audio Samples.

  • verbose (int | bool) – Prints the Qubit information if True or int > 0.

Returns:

A Tuple of (num_samples, qubit_shape).

qubit_shape is a Tuple (int, int) consisting of:
  • num_index_qubits to encode Time Information (x-axis).

  • num_value_qubits to encode Amplitude Information (y-axis).

Return type:

Tuple[int, Tuple[int, int]]

prepare_data(data, num_index_qubits)[source]

Prepares the data with appropriate dimensions for encoding:

  • It pads the length of data with zeros to fit the number of states that can be represented with num_index_qubits.

  • It also removes redundant dimension if the shape is (1,num_samples).

Parameters:
  • data (ndarray) – Array representing Digital Audio Samples

  • num_index_qubits (int) – Number of qubits used to encode the sample indices.

Returns:

Array with dimensions suitable for encoding.

Return type:

ndarray

Note

This method should be followed by convert() method to convert the values suitable for encoding.

initialize_circuit(num_index_qubits, num_value_qubits)[source]

Initializes the circuit with Index and Value Registers.

Parameters:
  • num_index_qubits (int) – Number of qubits used to encode the sample indices.

  • num_value_qubits (int) – Number of qubits used to encode the sample values.

Returns:

Qiskit Circuit with the registers

Return type:

QuantumCircuit

value_setting(circuit, index, value)[source]

Encodes the prepared, converted values to the initialised circuit.

This function is used to set a single value at a single index. The decorator with_indexing applies the necessary control qubits corresponding to the given index.

Parameters:
  • circuit (QuantumCircuit) – Initialized Qiskit Circuit

  • index (int) – position to set the value

  • value (float) – value to be set at the index

Return type:

None

measure(circuit)[source]

Adds classical measurements to all registers of the Quantum Circuit if the circuit is not already measured.

Parameters:

circuit (QuantumCircuit) – Encoded Qiskit Circuit

Return type:

None

encode(data, measure=True, verbose=1)[source]

Given an audio data, prepares a Qiskit Circuit representing it.

Parameters:
  • data (ndarray) – Array representing Digital Audio Samples

  • measure (bool) – Adds measurement to the circuit if set True or int > 0.

  • verbose (int | bool) –

    Level of information to print.

    • >1: Prints number of qubits required.

    • >2: Displays the encoded circuit.

Returns:

A Qiskit Circuit representing the Digital Audio

Return type:

QuantumCircuit

decode_components(counts, qubit_shape)[source]

The first stage of decoding is extracting required components from counts.

Parameters:
  • counts (dict | Counts) – a dictionary with the outcome of measurements performed on the quantum circuit.

  • qubit_shape ([<class 'int'>, <class 'int'>]) – Tuple to determine the number of components to get.

Returns:

Array of components for further decoding.

Return type:

ndarray

reconstruct_data(counts, qubit_shape)[source]

Given counts, Extract components and restore the conversion did at encoding stage.

Parameters:
  • counts (dict | Counts) – a dictionary with the outcome of measurements performed on the quantum circuit.

  • qubit_shape (int) – Tuple to determine the number of components to get.

  • qubit_depth – number of qubits in amplitude register.

Returns:

Array of restored values

Return type:

ndarray

decode_counts(counts, metadata, keep_padding=False)[source]

Given a result object. Extract components and restore the conversion did in encoding stage.

Parameters:
  • counts (dict | Counts) – a qiskit Counts object or Dictionary obtained from a job result.

  • metadata (dict) – metadata required for decoding.

  • keep_padding (bool) – Undo the padding set at Encoding stage if set False.

Returns:

Array of restored values with original dimensions

Return type:

ndarray

decode_result(result, metadata=None, keep_padding=False)[source]

Given a result object. Extract components and restore the conversion did in encoding stage.

Parameters:
  • result (Result) – a qiskit Result object that contains counts along with metadata that was held by the original circuit.

  • metadata (dict | None) – optionally pass metadata as argument.

  • keep_padding (bool) – Undo the padding set at Encoding stage if set False.

Returns:

Array of restored values with original dimensions

Return type:

ndarray

decode(circuit, metadata=None, keep_padding=False, execute_function=<function execute>, **kwargs)[source]

Given a qiskit circuit, decodes and returns back the Original Audio Array.

Parameters:
  • circuit (QuantumCircuit) – A Qiskit Circuit representing the Digital Audio.

  • metadata (dict | None) – optionally pass metadata as argument.

  • keep_padding (bool) – Undo the padding set at Encoding stage if set False.

  • execute_function (Callable[[QuantumCircuit, dict], Any]) –

    Function to execute the circuit for decoding.

    • Defaults to utils.execute which accepts any additional **kwargs.

Returns:

Array of decoded values

Return type:

ndarray

quantumaudio.schemes.mqsm

class quantumaudio.schemes.mqsm.MQSM(qubit_depth=None, num_channels=None)[source]

Bases: Scheme

Multi-channel Quantum State Modulation (MQSM).

MQSM class implements an encoding and decoding scheme where the amplitude of a Digital signal is encoded as qubit states. These states are controlled by qubits of time register that encodes the corresponding time index information. Additionally, another register is used to represent the channel information.

Parameters:
  • qubit_depth (int | None)

  • num_channels (int | None)

calculate(data, verbose=True)[source]

Returns necessary information required for Encoding and Decoding:

  • Number of qubits required to encode Channel, Time and Amplitude information.

  • Original shape of the data required for decoding.

Parameters:
  • data (ndarray) – Array representing Digital Audio Samples.

  • verbose (int | bool) – Prints the Qubit information if True or int > 0.

Returns:

A Tuple of (data_shape, qubit_shape)

data_shape is a Tuple (int, int) consisting of:
  • num_samples

  • num_channels

qubit_shape is a Tuple (int, int, int) consisting of:
  • num_index_qubits to encode Time Information.

  • num_channel_qubits to encode Channel Information.

  • num_value_qubits to encode Amplitude Information.

Return type:

Tuple[Tuple[int, int], Tuple[int, int, int]]

prepare_data(data, num_index_qubits, num_channel_qubits)[source]

Prepares the data with appropriate dimensions for encoding:

  • It pads the length of data with zeros on both dimensions to fit the number of states that can be represented with time and channel registers.

  • It flattens the array for encoding. The default arrangement of samples is made in an alternating manner using utils.interleave_channels.

Parameters:
  • data (ndarray) – Array representing Digital Audio Samples

  • num_index_qubits (int) – Number of qubits used to encode the sample indices.

  • num_channel_qubits (int) – Number of qubits used to encode the channels.

Returns:

Array with dimensions suitable for encoding.

Return type:

ndarray

Note

This method should be followed by convert() method to convert the values suitable for encoding.

initialize_circuit(num_index_qubits, num_channel_qubits, num_value_qubits)[source]

Initializes the circuit with Index, Channel and Value Registers.

Parameters:
  • num_index_qubits (int) – Number of qubits used to encode the sample indices.

  • num_channel_qubits (int) – Number of qubits used to encode the channels.

  • num_value_qubits (int) – Number of qubits used to encode the sample values.

Returns:

Qiskit Circuit with the registers

Return type:

QuantumCircuit

value_setting(circuit, index, value)[source]

Encodes the prepared, converted values to the initialised circuit.

This function is used to set a single value at a single index. The decorator with_indexing applies the necessary control qubits corresponding to the given index.

Parameters:
  • circuit (QuantumCircuit) – Initialized Qiskit Circuit

  • index (int) – position to set the value

  • value (float) – value to be set at the index

Return type:

None

Note

This method is used in a loop where each value is iterated and set at its corresponding index.

measure(circuit)[source]

Adds classical measurements to all registers of the Quantum Circuit if the circuit is not already measured.

Parameters:

circuit (QuantumCircuit) – Encoded Qiskit Circuit

Return type:

None

encode(data, measure=True, verbose=1)[source]

Given audio data, prepares a Qiskit Circuit representing it.

Parameters:
  • data (ndarray) – Array representing Digital Audio Samples

  • measure (bool) – Adds measurement to the circuit if set True or int > 0.

  • verbose (int | bool) –

    Level of information to print.

    • >1: Prints the number of qubits required.

    • >2: Displays the encoded circuit.

Returns:

A Qiskit Circuit representing the Digital Audio

Return type:

QuantumCircuit

decode_components(counts, qubit_shape)[source]

The first stage of decoding is extracting the required components from counts.

Parameters:
  • counts (dict | Counts) – a dictionary with the outcome of measurements performed on the quantum circuit.

  • qubit_shape (Tuple[int, int, int]) – Tuple to determine the number of (channels, samples) to get.

Returns:

2-D Array of shape (num_channels, num_samples) for further decoding.

Return type:

ndarray

reconstruct_data(counts, qubit_shape)[source]

Given counts, Extract components and restore the conversion at encoding stage.

Parameters:
  • counts (dict | Counts) – a dictionary with the outcome of measurements performed on the quantum circuit.

  • qubit_shape (Tuple[int, int, int]) – Tuple to determine the number of (channels, samples) to get.

  • qubit_depth – number of qubits in amplitude register.

Returns:

Array of restored values

Return type:

ndarray

decode_counts(counts, metadata, keep_padding=(False, False))[source]

Given a Qiskit counts object or Dictionary, Extract components and restore the conversion did at encoding stage.

Parameters:
  • counts (dict | Counts) – a qiskit Counts object or Dictionary obtained from a job result.

  • metadata (dict) – metadata required for decoding.

  • keep_padding (Tuple[int, int]) –

    Undo the padding set at Encoding stage if set to False.

    • Dimension 0 for Channels.

    • Dimension 1 for Time.

Returns:

Array of restored values with original dimensions

Return type:

ndarray

decode_result(result, metadata=None, keep_padding=(False, False))[source]

Given a result object. Extract components and restore the conversion did in the encoding stage.

Parameters:
  • result (Result) – a qiskit Result object that contains counts along with metadata that was held by the original circuit.

  • metadata (dict | None) – optionally pass metadata as argument.

  • keep_padding (Tuple[int, int]) –

    Undo the padding set at Encoding stage if set to False.

    • Dimension 0 for Channels.

    • Dimension 1 for Time.

Returns:

Array of restored values with original dimensions

Return type:

ndarray

decode(circuit, metadata=None, keep_padding=(False, False), execute_function=<function execute>, **kwargs)[source]

Given a qiskit circuit, decodes and returns the Original Audio Array.

Parameters:
  • circuit (QuantumCircuit) – A Qiskit Circuit representing the Digital Audio.

  • metadata (dict | None) – optionally pass metadata as argument.

  • keep_padding (Tuple[int, int]) – Undo the padding set at Encoding stage if set False.

  • execute_function (Callable[[QuantumCircuit, dict], Any]) –

    Function to execute the circuit for decoding.

    • Defaults to utils.execute which accepts any additional **kwargs.

Returns:

Array of decoded values

Return type:

ndarray

quantumaudio.schemes.msqpam

class quantumaudio.schemes.msqpam.MSQPAM(num_channels=None)[source]

Bases: Scheme

Multi-channel Single-Qubit Probability Amplitude Modulation (MSQPAM).

MSQPAM class implements an encoding and decoding scheme where the amplitude of a Digital signal is encoded through rotation gates acting on a single-qubit. This qubit is controlled by qubits of time register that encodes the corresponding time index information. Additionally, another register is used to represent the channel information.

Parameters:

num_channels (int | None)

calculate(data, verbose=True)[source]

Returns necessary information required for Encoding and Decoding:

  • Number of qubits required to encode Channel, Time and Amplitude information.

  • Original shape of the data required for decoding.

Parameters:
  • data (ndarray) – Array representing Digital Audio Samples.

  • verbose (int | bool) – Prints the Qubit information if True or int > 0.

Returns:

A Tuple of (data_shape, qubit_shape).

data_shape is a Tuple (int, int) consisting of:
  • num_samples

  • num_channels

qubit_shape is a Tuple (int, int, int) consisting of:
  • num_index_qubits to encode Time Information.

  • num_channel_qubits to encode Channel Information.

  • num_value_qubits to encode Amplitude Information.

Return type:

Tuple[Tuple[int, int], Tuple[int, int, int]]

prepare_data(data, num_index_qubits, num_channel_qubits)[source]

Prepares the data with appropriate dimensions for encoding:

  • It pads the length of data with zeros on both dimensions to fit the number of states that can be represented with time and channel registers.

  • It flattens the array for encoding. The default arrangement of samples is made in an alternating manner using utils.interleave_channels.

Parameters:
  • data (ndarray) – Array representing Digital Audio Samples

  • num_index_qubits (int) – Number of qubits used to encode the sample indices.

  • num_channel_qubits (int) – Number of qubits used to encode the channels.

Returns:

Array with dimensions suitable for encoding.

Return type:

ndarray

Note

This method should be followed by convert() method to convert the values suitable for encoding.

initialize_circuit(num_index_qubits, num_channel_qubits, num_value_qubits)[source]

Initializes the circuit with Index, Channel and Value Registers.

Parameters:
  • num_index_qubits (int) – Number of qubits used to encode the sample indices.

  • num_channel_qubits (int) – Number of qubits used to encode the channels.

  • num_value_qubits (int) – Number of qubits used to encode the sample values.

Returns:

Qiskit Circuit with the registers

Return type:

QuantumCircuit

value_setting(circuit, index, value)[source]

Encodes the prepared, converted values to the initialised circuit. This function is used to set a single value at a single index. The decorator with_indexing applies the necessary control qubits corresponding to the given index.

Parameters:
  • circuit (QuantumCircuit) – Initialized Qiskit Circuit

  • index (int) – position to set the value

  • value (float) – value to be set at the index

Return type:

None

measure(circuit)[source]

Adds classical measurements to all registers of the Quantum Circuit if the circuit is not already measured.

Parameters:

circuit (QuantumCircuit) – Encoded Qiskit Circuit

Return type:

None

encode(data, measure=True, verbose=1)[source]

Given audio data, prepares a Qiskit Circuit representing it.

Parameters:
  • data (ndarray) – Array representing Digital Audio Samples

  • measure (bool) – Adds measurement to the circuit if set True or int > 0.

  • verbose (int | bool) –

    Level of information to print.

    • >1: Prints the number of qubits required.

    • >2: Displays the encoded circuit.

Returns:

A Qiskit Circuit representing the Digital Audio

Return type:

QuantumCircuit

decode_components(counts, qubit_shape)[source]

The first stage of decoding is extracting required components from counts.

Parameters:
  • counts (dict | Counts) – a dictionary with the outcome of measurements performed on the quantum circuit.

  • qubit_shape (Tuple[int, int]) – Tuple to determine the number of (channels, samples) to get.

Returns:

2-D Array of shape (num_channels, num_samples) for further decoding.

Return type:

ndarray

reconstruct_data(counts, qubit_shape, inverted=False)[source]

Given counts, Extract components and restore the conversion did at encoding stage.

Parameters:
  • counts (dict | Counts) – a dictionary with the outcome of measurements performed on the quantum circuit.

  • qubit_shape (Tuple[int, int]) – Tuple to determine the number of (channels, samples) to get.

  • inverted (bool) – retrieves cosine components of the signal.

Returns:

Array of restored values

Return type:

ndarray

decode_counts(counts, metadata, inverted=False, keep_padding=(False, False))[source]

Given a Qiskit counts object or Dictionary, Extract components and restore the conversion did at encoding stage.

Parameters:
  • counts (dict | Counts) – a qiskit Counts object or Dictionary obtained from a job result.

  • metadata (dict) – metadata required for decoding.

  • inverted (bool) – retrieves cosine components of the signal.

  • keep_padding (Tuple[int, int]) –

    Undo the padding set at Encoding stage if set to False.

    • Dimension 0 for Channels.

    • Dimension 1 for Time.

Returns:

Array of restored values with original dimensions

Return type:

ndarray

decode_result(result, metadata=None, inverted=False, keep_padding=(False, False))[source]

Given a result object. Extract components and restore the conversion did in the encoding stage.

Parameters:
  • result (Result) – a qiskit Result object that contains counts along with metadata that was held by the original circuit.

  • metadata (dict | None) – optionally pass metadata as argument.

  • inverted (bool) – retrieves cosine components of the signal.

  • keep_padding (Tuple[int, int]) –

    Undo the padding set at Encoding stage if set to False.

    • Dimension 0 for Channels.

    • Dimension 1 for Time.

Returns:

Array of restored values with original dimensions

Return type:

ndarray

decode(circuit, metadata=None, inverted=False, keep_padding=(False, False), execute_function=<function execute>, **kwargs)[source]

Given a qiskit circuit, decodes and returns the Original Audio Array.

Parameters:
  • circuit (QuantumCircuit) – A Qiskit Circuit representing the Digital Audio.

  • metadata (dict | None) – optionally pass metadata as argument.

  • inverted (bool) – retrieves cosine components of the signal.

  • keep_padding (Tuple[int, int]) –

    Undo the padding set at Encoding stage if set to False.

    • Dimension 0 for Channels.

    • Dimension 1 for Time.

  • execute_function (Callable[[QuantumCircuit, dict], Any]) –

    Function to execute the circuit for decoding.

    • Defaults to utils.execute which accepts any additional **kwargs.

Returns:

Array of decoded values

Return type:

ndarray