quantumaudio


Namequantumaudio JSON
Version 0.1.0 PyPI version JSON
download
home_pageNone
SummaryA Python package for building Quantum Representations of Digital Audio. Developed by Moth Quantum.
upload_time2024-11-01 15:43:03
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseNone
keywords audio quantum computing signal processing
VCS
bugtrack_url
requirements qiskit qiskit_aer numpy bitstring matplotlib pylatexenc tqdm packaging
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <div align="center">
  
# Quantum Audio


![Python version](https://img.shields.io/badge/python-3.9+-important) [![PyPI](https://img.shields.io/pypi/v/quantumaudio)](https://pypi.org/project/quantumaudio/) [![Read the Docs (version)](https://img.shields.io/readthedocs/quantumaudio/latest?label=API%20docs)](https://quantumaudio.readthedocs.io/en/latest/) [![LICENSE](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/moth-quantum/quantum-audio/blob/main/LICENSE) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.14012134.svg)](https://doi.org/10.5281/zenodo.14012134) [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1qGWhTLWoxnJsR7tINR6MVGDvk56CX2uE?ts=66c70dcd)

An open-source Python package for building Quantum Representations of Digital Audio using _Qiskit_ circuits.

<img width="600" alt="QSM Example" src="https://github.com/moth-quantum/quantum-audio/blob/main/demos/media/qsm_example.png?raw=true"><br>
</div>

## 💿 What is Quantum Audio ?

Quantum audio refers to the application of principles from quantum mechanics to the creation, processing, and analysis of sound or audio signals. 

> Here, the information is processed using <i>quantum bits</i>, or <i>qubits</i>, instead of classical bits (0s and 1s).

#### New Paradigm 🎵

Audio plays a vital role in carrying information and music, traversing through domains — from **Analog** and **Digital** formats to engaging our senses in a profound way. With the advent of Quantum Computing, **Quantum Audio** formulate ways of representing Audio in the Quantum Domain, enabling new explorations in artistic and research contexts 💫

#### The Package 📦

The `quantumaudio` package provides fundamental operations for representing audio samples as Quantum States that can be processed on a Quantum computer (or a Simulator) and played back 🔊

```python
quantumaudio.encode(audio)   # returns a quantum circuit
quantumaudio.decode(circuit) # returns audio samples
```

>  Quantum Audio represents Audio in terms of Quantum Circuits and does not require Quantum Memory for storage.

## 🗒️ Table of Contents

- [Overview](#overview)
- [Version Information](#version)
- [Installation](#installation)
- [Usage](#usage)
- [Additional Resources](#materials)
- [Contributing](#contributing)
- [Future Releases](#future-releases)
- [Citing](#citation)
- [Contact](#contact)

## 🔍 Overview <a id="overview"></a>

Modulation Schemes are essential methods for encoding Audio signals in both Analog (such as **FM** 📻) and Digital (such as **PCM** 💻) formats. The same is extended for Quantum Audio.
The package contains different schemes to encode audio and necessary utilities. 

The following subpackages can be accessed from ``quantumaudio``:

- ``schemes``: Quantum Audio Representation Methods. The following are included in the package:
  
| Acronym | Representation Name | Original Reference |
|---------|---------------------|--------------------|
| **QPAM**    | Quantum Probability Amplitude Modulation | [Real-Ket](https://doi.org/10.1007/s11128-015-1208-5)          |
| **SQPAM**   | Single-Qubit Probability Amplitude Modulation | [FRQI](http://dx.doi.org/10.1007/s11128-010-0177-y)  |
| **MSQPAM**  | Multi-channel Single-Qubit Probability Amplitude Modulation | [PMQA](https://doi.org/10.1007/s11128-022-03435-7)  |
| **QSM**     | Quantum State Modulation | [FRQA](https://doi.org/10.1016/j.tcs.2017.12.025) |
| **MQSM**    | Multi-channel Quantum State Modulation | [QRMA](https://doi.org/10.1007/s11128-019-2317-3)  |

- ``utils`` : Common utilary functions for data processing, analysis, circuit preparation, etc.

Additionally, ``tools`` contain extension functions that support basic visual analysis and audio processing.

> For a quick tour of Quantum Audio, try [Colab](https://colab.research.google.com/drive/1qGWhTLWoxnJsR7tINR6MVGDvk56CX2uE?ts=66c70dcd) 🚀

### Documentation
For more details of the package, please refer to the [Documentation](https://quantumaudio.readthedocs.io) site.

## 🧩 Version Information <a id="version"></a>

### Pre-release original version: ```v0.0.2```
This project is derived from research output on Quantum Representations of Audio, carried by <b>Interdisciplinary Centre for Computer Music Research ([ICCMR](https://www.plymouth.ac.uk/research/iccmr))</b>, University of Plymouth, UK, namely:

- Itaboraí, P.V., Miranda, E.R. (2022). Quantum Representations of Sound: From Mechanical Waves to Quantum Circuits. In: Miranda, E.R. (eds) Quantum Computer Music. Springer, Cham. https://doi.org/10.1007/978-3-031-13909-3_10
  
- Itaboraí, P. V. (2022). Quantumaudio Module (Version 0.0.2) [Computer software]. https://github.com/iccmr-quantum/quantumaudio
  
- Itaboraí, P. V. (2023) Towards Quantum Computing for Audio and Music Expression. Thesis. University of Plymouth. Available at: https://doi.org/10.24382/5119

For more details, see the [NOTICE](NOTICE) file.

### Redevelopment: ```v0.1.0```
This project has been completely re-developed and is now maintained by <b>[Moth Quantum](https://mothquantum.com)</b>.

- **New Architecture:**

  - This project has been restructured for better flexibility and scalability.
  - Instead of _QuantumAudio_ Instances, the package begins at the level of _Scheme_ Instances that perform encoding and decoding functions independent of the data.
    
- **Feature Updates:**
  
  - Introducing 2 Additional Schemes that can encode and decode Multi-channel Audio.
  - Supports Faster encoding and decoding of long audio files using Batch processing.
    
- **Dependency Change:**
  
  - Support for _Qiskit_ is updated from `v0.22` to `v1.0+`
    
- **Improvements:**
  
  - Improved organisation of code for Readability and Modularity.
  - Key metadata information is preserved during the encoding operation, making the decoding process independent.
    
- **License Change:**
  
  - The License is updated from **MIT** to **Apache 2.0**

### Migration Guide
If you're transitioning from the previous version, please check the [Migration Guide](https://github.com/moth-quantum/quantum-audio/blob/main/docs/guides/MIGRATION.md) for an overview of the package usability.


##  🪄 Installation <a id="installation"></a>
To install the Quantum Audio Package, you can use ```pip``` (included with Python) which installs it from [PyPI](https://pypi.org/project/quantumaudio/) package manager. Run the following command in Terminal or Command Prompt: 
```console
pip install quantumaudio
```
For local installation by [cloning](https://docs.github.com/en/repositories/creating-and-managing-repositories/cloning-a-repository), navigate to the cloned directory in Terminal or Command Prompt and run:<br>
```pip install .``` or  ```pip install -r requirements.txt``` <br>

> [!Note]
 > When using `pip` commands to install packages and dependencies, it's recommended to use a **virtual environment** to keep them isolated from the system's Python. This will avoid any dependency conflicts. Instructions on using a virtual environment are provided [here](https://github.com/moth-quantum/quantum-audio/blob/main/docs/guides/ENVIRONMENT.md).

### Optional Dependencies
All additional dependencies required that support the demos provided in the repository can be installed using `pip`:
  ```
  pip install "quantumaudio[demos]"
  ```
It includes the following collection of dependencies, also mentioned in the folder ``demos/requirements``:

  - **Digital Audio Dependencies**
    The core package operates with _numpy_ arrays. Dependencies for audio file handling to run audio examples in notebook and scripts in the repository can be separately installed using ```pip install soundfile==0.12.1 librosa==0.10.2.post1```
  
> [!Tip]
> If using your own choice of libraries for digital audio processing, please be aware that Multi-channel Quantum Audio is processed with _Channels First_ data structure. e.g. `(2, N)` for a Stereo Audio of `N` samples.
  
  - **Notebook Dependencies**
    The [Demo Notebook](https://github.com/moth-quantum/quantum-audio/blob/main/demos/1_Basics_Walkthrough.ipynb) features interactive elements that require additional dependency. It can be installed using ```pip install ipywidgets```


## 🎛️ Usage <a id="usage"></a>

### Using Schemes
Get started on creating Quantum Audio Representations with just a few lines of code.
```python
# An instance of a scheme can be created using:
import quantumaudio
qpam = quantumaudio.load_scheme("qpam") # or directly access from quantumaudio.schemes.QPAM()

# Define an Input
original_data = quantumaudio.tools.test_signal() # for a random array of samples (range: -1.0 to 1.0)

# Encoding
encoded_circuit = qpam.encode(original_data)

# ... optionally do some analysis or processing

# Decoding
decoded_data  = qpam.decode(encoded_circuit,shots=4000)    
```

> [!Note]
> The `encode` function returns a circuit with attached classical measurements by default. In Qiskit, it is not possible to directly modify a circuit after these measurements are added. If you wish to return a circuit without measurements, you can specify `measure=False` while encoding.

### Using Functions
The core functions are also directly accessible without declaring a Scheme object. (Refer to [Documentation](https://quantumaudio.readthedocs.io/) for all the available functions)
```python
circuit = quantumaudio.encode(data, scheme="qpam")
decoded_data = quantumaudio.decode(circuit)
```
Here, any remaining arguments can be passed as keywords e.g. ```quantumaudio.encode(data, scheme="qsm", measure="False")```.

> [!Note]
> The circuit depth can grow complex for a long array of samples which is the case with Digital Audio. It is optimal to represent a short length of samples per Circuit when using the `encode()` method.<br>

### Working with Digital Audio
For faster processing of longer arrays, the `stream` method is preferred. 
```python
quantumaudio.stream(data)
```
It wraps the functions provided in the module `quantumaudio.tools.stream` that help process large arrays as chunks for efficient handling. Examples of its usage can be found in the [Demos](https://github.com/moth-quantum/quantum-audio/tree/main/demos) provided in the repository.

### Running on Native Backends

A Scheme's ```decode()``` method uses local [_AerSimulator_](https://github.com/Qiskit/qiskit-aer) as the default backend. Internally, the function calls `utils.execute()` method that performs ```backend.run()```. Any such backend object compatible with Qiskit can be passed to the ```backend=``` parameter of the `decode()` function. To configure this further or to use primitives, please refer to custom [execute functions](#custom_functions).

### Running on External Quantum Backends

The package allows flexible use of Quantum Hardware from different Providers as the execution of circuits can be done independently. Depending on the results, there are two ways to decode quantum audio:

- **Results Object:** If the result obtained follow the format of [qiskit.result.Result](https://docs.quantum.ibm.com/api/qiskit/qiskit.result.Result) or [qiskit.primitives.PrimitiveResult](https://docs.quantum.ibm.com/api/qiskit/qiskit.primitives.PrimitiveResult),
  - The audio can be decoded with ```scheme.decode_result(result_object)``` method.
  - In this case, relevant metadata information is automatically extracted and applied at decoding. It can also be manually passed using `metadata=` parameter.
<br><br>
- **Counts Dictionary:** If the result is in form of a counts dictionary or [qiskit.result.Counts](https://docs.quantum.ibm.com/api/qiskit/qiskit.result.Counts) object,
  - The audio can be decoded using ```scheme.decode_counts(counts, metadata)``` method.
  - Here, the metadata dictionary is required which can be obtained from the encoded circuit's `.metadata` attribute.
    
> [!Tip]
> **Dictionaries** are data type in python to store {key : _value_} pairs.
> - **Counts Dicitonary** contains keys representing classical measurement outcomes and values indicating the number of times the outcome was observed. Example: `{'00': 77, '01': 79, '10': 84, '11': 72}`.
> - **Metadata Dictionary** stores the key information that is required at decoding, which is commonly the original data dimensions to restore and layout of qubits. Both can be obtained from `scheme.calculate()` method.

### Viewing Metadata
The Metadata Information can be viewed from the encoded circuit's `.metadata` attribute. The common keys found in a metadata are: 
 - **num_samples** (_int_) : Original sample length to restore.
 - **num_channels** (_int_): Original number of channels to restore. (Applicable for multi-channel schemes)
 - **qubit_shape** (_tuple_): Stores the arrangement and number of qubits that encode each aspect of the audio information i.e. _Time_, _Channel_ (if applicable) and _Amplitude_. <br>

The _QPAM_ scheme's encoding only preserves **num_samples** (_int_) and the normalization factor - **norm_factor** (_float_) which is required to restore the values.
> [!Note]
> When passing metadata manually in any of the decode functions, _QPAM_ Scheme additionaly requires **shots** (_int_) information used for executing the circuit which can also be passed through the argument `shots=`.

> [!Tip]
> The essential keys required for decoding with any scheme can be checked from the scheme's `.keys` attribute.

### Using Custom Functions <a id="custom_functions"></a>
The `decode` and `stream` operations can be configured with the following custom functions. They require few mandatory arguments followed by custom preceding keyword arguments (denoted as `**kwargs`).
- **Process Function**:
The default process function of `stream()` simply encodes and decodes a chunk of data with default parameters. It can be overriden by passing a custom function to the `process_function=` parameter. The mandatory arguments for the custom process function are `data=` and `scheme=`.
```python
processed_data = process_function(data, scheme, **kwargs)
```
- **Execute Function** :
The default execute function for `decode()` can be overriden by passing a custom function to the `execute_function=` parameter. The mandatory argument for the custom execute function is `circuit=`. (QPAM also expects `shots=` since it's a metadata)
```python
result = execute_function(circuit, **kwargs)
``` 
**Example**: An optional execute function is included in the package which uses [Sampler Primitive](https://docs.quantum.ibm.com/api/qiskit-ibm-runtime/qiskit_ibm_runtime.SamplerV2): `quantumaudio.utils.execute_with_sampler` that can be passed to the `decode()` method. It requires the dependency `pip install qiskit-ibm-runtime`. <br>
 
## 📘 Additional Resources <a id="materials"></a>
### Notebook Examples
For examples of circuit preparation, signal reconstruction, and interactive demonstrations, please check the [Demo Notebook](https://github.com/moth-quantum/quantum-audio/blob/main/demos/1_Basics_Walkthrough.ipynb). It combines the core package with additional functions from the `demos/tools` folder to go through Visual and Digital Audio examples.

### Quick Export ⚡️
To quickly export quantumaudio from any audio file (e.g., _mp3_, _ogg_, _flac_, _m4a_), a script ```export.py``` is provided in the `demos/scripts` folder. Navigate to the directory and run:
  ```bash
  python export.py -i path/to/input/audio/file
  ```
  ```console
  usage: export.py [-h] -i [-o] [-v] [--scheme] [--shots] [--sr] [--stereo] [--buffer_size]

  Process quantum audio and export as .wav file.

  options:
    -h, --help            show this help message and exit
    -i, --input           Path to the input audio file.
    -o, --output          Path to the output audio file. (default: saves in same directory with a prefix `qa_`)
    -v, --verbose         Enable verbose mode.
    --scheme              Quantum Audio Scheme (default: `qpam` for mono audio, `mqsm` for stereo audio).
    --shots               Number of shots for measurement (default: 8000)
    --sr                  Sample rate of Digital audio (default: 22050)
    --stereo              Enable stereo
    --buffer_size         Length of each audio chunk (default: 256)
  ```

> [!Note]
 > Digital Audio [Dependencies](#installation) must be installed to run this script.

## 🤝 Contributing <a id="contributing"></a>
Contributions to Quantum Audio are welcome! This package is designed to be a versatile tool for both research and artistic exploration.

If you find any issues or have suggestions for improvements, please open an issue or submit a pull request on the GitHub repository. 

- **Code Contributions:** Add new features, fix bugs, or improve existing functionality and code.
- **Documentation:** Enhance the README, tutorials, or other project documentation.
- **Educational Use:** If you’re using this project for learning, teaching or research, we’d love to hear about your experiences and suggestions.
- **Feedback and Ideas:** Share your thoughts, feature requests, or suggest improvements by opening an issue.

For more information on contributing to Code and Documentation, please review [Contributing Guidelines](https://github.com/moth-quantum/quantum-audio/blob/main/docs/guides/CONTRIBUTING.md)

## 🚩 Future Releases <a id="future-releases"></a>
We're excited to keep the package updated with features and improvements! In future releases, we plan to introduce other schemes from Quantum Audio Literature along with Base Scheme Class Categories to support a generic structure for further contributions.

## ✅ Citing <a id="citation"></a>
If you use this code or find it useful in your research, please consider citing:
> Moth Quantum and collaborators. (2024). Quantum Audio (v0.1.0). Zenodo. https://doi.org/10.5281/zenodo.14012135
---
## 📧 Contact <a id="contact"></a>

We're here to help! If you have any questions or need further assistance, please feel free reach out to our team using the support options provided below:

- **General Questions**: Ask on [Stack Overflow](https://stackoverflow.com/tags/quantumaudio/) using the `quantumaudio` tag.
- **Direct Contact**: For private or specific issues, reach us at [qap.support@mothquantum.com](mailto:qap.support@mothquantum.com).
- **Bugs & Feature Requests**: Please [open an issue](https://github.com/moth-quantum/quantum-audio/issues) on GitHub.

Before posting, check the [Documentation](https://quantumaudio.readthedocs.io), or existing questions in [Stack Overflow](https://stackoverflow.com/tags/quantumaudio/) to see if your question has been answered.

## 📜 Copyright
Copyright 2024 Moth Quantum

Licensed under the [Apache License](LICENSE), Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the [License](LICENSE) for the specific language governing permissions and limitations under the License.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "quantumaudio",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "audio, quantum computing, signal processing",
    "author": null,
    "author_email": "Moth Quantum and collaborators <qap.support@mothquantum.com>",
    "download_url": "https://files.pythonhosted.org/packages/c2/c9/5408c23a489da103288a5d3565d273e6d4601e03a1509f6cfc8886504fe8/quantumaudio-0.1.0.tar.gz",
    "platform": null,
    "description": "<div align=\"center\">\n  \n# Quantum Audio\n\n\n![Python version](https://img.shields.io/badge/python-3.9+-important) [![PyPI](https://img.shields.io/pypi/v/quantumaudio)](https://pypi.org/project/quantumaudio/) [![Read the Docs (version)](https://img.shields.io/readthedocs/quantumaudio/latest?label=API%20docs)](https://quantumaudio.readthedocs.io/en/latest/) [![LICENSE](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/moth-quantum/quantum-audio/blob/main/LICENSE) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.14012134.svg)](https://doi.org/10.5281/zenodo.14012134) [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1qGWhTLWoxnJsR7tINR6MVGDvk56CX2uE?ts=66c70dcd)\n\nAn open-source Python package for building Quantum Representations of Digital Audio using _Qiskit_ circuits.\n\n<img width=\"600\" alt=\"QSM Example\" src=\"https://github.com/moth-quantum/quantum-audio/blob/main/demos/media/qsm_example.png?raw=true\"><br>\n</div>\n\n## \ud83d\udcbf What is Quantum Audio ?\n\nQuantum audio refers to the application of principles from quantum mechanics to the creation, processing, and analysis of sound or audio signals. \n\n> Here, the information is processed using <i>quantum bits</i>, or <i>qubits</i>, instead of classical bits (0s and 1s).\n\n#### New Paradigm \ud83c\udfb5\n\nAudio plays a vital role in carrying information and music, traversing through domains \u2014 from **Analog** and **Digital** formats to engaging our senses in a profound way. With the advent of Quantum Computing, **Quantum Audio** formulate ways of representing Audio in the Quantum Domain, enabling new explorations in artistic and research contexts \ud83d\udcab\n\n#### The Package \ud83d\udce6\n\nThe `quantumaudio` package provides fundamental operations for representing audio samples as Quantum States that can be processed on a Quantum computer (or a Simulator) and played back \ud83d\udd0a\n\n```python\nquantumaudio.encode(audio)   # returns a quantum circuit\nquantumaudio.decode(circuit) # returns audio samples\n```\n\n>  Quantum Audio represents Audio in terms of Quantum Circuits and does not require Quantum Memory for storage.\n\n## \ud83d\uddd2\ufe0f Table of Contents\n\n- [Overview](#overview)\n- [Version Information](#version)\n- [Installation](#installation)\n- [Usage](#usage)\n- [Additional Resources](#materials)\n- [Contributing](#contributing)\n- [Future Releases](#future-releases)\n- [Citing](#citation)\n- [Contact](#contact)\n\n## \ud83d\udd0d Overview <a id=\"overview\"></a>\n\nModulation Schemes are essential methods for encoding Audio signals in both Analog (such as **FM** \ud83d\udcfb) and Digital (such as **PCM** \ud83d\udcbb) formats. The same is extended for Quantum Audio.\nThe package contains different schemes to encode audio and necessary utilities. \n\nThe following subpackages can be accessed from ``quantumaudio``:\n\n- ``schemes``: Quantum Audio Representation Methods. The following are included in the package:\n  \n| Acronym | Representation Name | Original Reference |\n|---------|---------------------|--------------------|\n| **QPAM**    | Quantum Probability Amplitude Modulation | [Real-Ket](https://doi.org/10.1007/s11128-015-1208-5)          |\n| **SQPAM**   | Single-Qubit Probability Amplitude Modulation | [FRQI](http://dx.doi.org/10.1007/s11128-010-0177-y)  |\n| **MSQPAM**  | Multi-channel Single-Qubit Probability Amplitude Modulation | [PMQA](https://doi.org/10.1007/s11128-022-03435-7)  |\n| **QSM**     | Quantum State Modulation | [FRQA](https://doi.org/10.1016/j.tcs.2017.12.025) |\n| **MQSM**    | Multi-channel Quantum State Modulation | [QRMA](https://doi.org/10.1007/s11128-019-2317-3)  |\n\n- ``utils`` : Common utilary functions for data processing, analysis, circuit preparation, etc.\n\nAdditionally, ``tools`` contain extension functions that support basic visual analysis and audio processing.\n\n> For a quick tour of Quantum Audio, try [Colab](https://colab.research.google.com/drive/1qGWhTLWoxnJsR7tINR6MVGDvk56CX2uE?ts=66c70dcd) \ud83d\ude80\n\n### Documentation\nFor more details of the package, please refer to the [Documentation](https://quantumaudio.readthedocs.io) site.\n\n## \ud83e\udde9 Version Information <a id=\"version\"></a>\n\n### Pre-release original version: ```v0.0.2```\nThis project is derived from research output on Quantum Representations of Audio, carried by <b>Interdisciplinary Centre for Computer Music Research ([ICCMR](https://www.plymouth.ac.uk/research/iccmr))</b>, University of Plymouth, UK, namely:\n\n- Itabora\u00ed, P.V., Miranda, E.R. (2022). Quantum Representations of Sound: From Mechanical Waves to Quantum Circuits. In: Miranda, E.R. (eds) Quantum Computer Music. Springer, Cham. https://doi.org/10.1007/978-3-031-13909-3_10\n  \n- Itabora\u00ed, P. V. (2022). Quantumaudio Module (Version 0.0.2) [Computer software]. https://github.com/iccmr-quantum/quantumaudio\n  \n- Itabora\u00ed, P. V. (2023) Towards Quantum Computing for Audio and Music Expression. Thesis. University of Plymouth. Available at: https://doi.org/10.24382/5119\n\nFor more details, see the [NOTICE](NOTICE) file.\n\n### Redevelopment: ```v0.1.0```\nThis project has been completely re-developed and is now maintained by <b>[Moth Quantum](https://mothquantum.com)</b>.\n\n- **New Architecture:**\n\n  - This project has been restructured for better flexibility and scalability.\n  - Instead of _QuantumAudio_ Instances, the package begins at the level of _Scheme_ Instances that perform encoding and decoding functions independent of the data.\n    \n- **Feature Updates:**\n  \n  - Introducing 2 Additional Schemes that can encode and decode Multi-channel Audio.\n  - Supports Faster encoding and decoding of long audio files using Batch processing.\n    \n- **Dependency Change:**\n  \n  - Support for _Qiskit_ is updated from `v0.22` to `v1.0+`\n    \n- **Improvements:**\n  \n  - Improved organisation of code for Readability and Modularity.\n  - Key metadata information is preserved during the encoding operation, making the decoding process independent.\n    \n- **License Change:**\n  \n  - The License is updated from **MIT** to **Apache 2.0**\n\n### Migration Guide\nIf you're transitioning from the previous version, please check the [Migration Guide](https://github.com/moth-quantum/quantum-audio/blob/main/docs/guides/MIGRATION.md) for an overview of the package usability.\n\n\n##  \ud83e\ude84 Installation <a id=\"installation\"></a>\nTo install the Quantum Audio Package, you can use ```pip``` (included with Python) which installs it from [PyPI](https://pypi.org/project/quantumaudio/) package manager. Run the following command in Terminal or Command Prompt: \n```console\npip install quantumaudio\n```\nFor local installation by [cloning](https://docs.github.com/en/repositories/creating-and-managing-repositories/cloning-a-repository), navigate to the cloned directory in Terminal or Command Prompt and run:<br>\n```pip install .``` or  ```pip install -r requirements.txt``` <br>\n\n> [!Note]\n > When using `pip` commands to install packages and dependencies, it's recommended to use a **virtual environment** to keep them isolated from the system's Python. This will avoid any dependency conflicts. Instructions on using a virtual environment are provided [here](https://github.com/moth-quantum/quantum-audio/blob/main/docs/guides/ENVIRONMENT.md).\n\n### Optional Dependencies\nAll additional dependencies required that support the demos provided in the repository can be installed using `pip`:\n  ```\n  pip install \"quantumaudio[demos]\"\n  ```\nIt includes the following collection of dependencies, also mentioned in the folder ``demos/requirements``:\n\n  - **Digital Audio Dependencies**\n    The core package operates with _numpy_ arrays. Dependencies for audio file handling to run audio examples in notebook and scripts in the repository can be separately installed using ```pip install soundfile==0.12.1 librosa==0.10.2.post1```\n  \n> [!Tip]\n> If using your own choice of libraries for digital audio processing, please be aware that Multi-channel Quantum Audio is processed with _Channels First_ data structure. e.g. `(2, N)` for a Stereo Audio of `N` samples.\n  \n  - **Notebook Dependencies**\n    The [Demo Notebook](https://github.com/moth-quantum/quantum-audio/blob/main/demos/1_Basics_Walkthrough.ipynb) features interactive elements that require additional dependency. It can be installed using ```pip install ipywidgets```\n\n\n## \ud83c\udf9b\ufe0f Usage <a id=\"usage\"></a>\n\n### Using Schemes\nGet started on creating Quantum Audio Representations with just a few lines of code.\n```python\n# An instance of a scheme can be created using:\nimport quantumaudio\nqpam = quantumaudio.load_scheme(\"qpam\") # or directly access from quantumaudio.schemes.QPAM()\n\n# Define an Input\noriginal_data = quantumaudio.tools.test_signal() # for a random array of samples (range: -1.0 to 1.0)\n\n# Encoding\nencoded_circuit = qpam.encode(original_data)\n\n# ... optionally do some analysis or processing\n\n# Decoding\ndecoded_data  = qpam.decode(encoded_circuit,shots=4000)    \n```\n\n> [!Note]\n> The `encode` function returns a circuit with attached classical measurements by default. In Qiskit, it is not possible to directly modify a circuit after these measurements are added. If you wish to return a circuit without measurements, you can specify `measure=False` while encoding.\n\n### Using Functions\nThe core functions are also directly accessible without declaring a Scheme object. (Refer to [Documentation](https://quantumaudio.readthedocs.io/) for all the available functions)\n```python\ncircuit = quantumaudio.encode(data, scheme=\"qpam\")\ndecoded_data = quantumaudio.decode(circuit)\n```\nHere, any remaining arguments can be passed as keywords e.g. ```quantumaudio.encode(data, scheme=\"qsm\", measure=\"False\")```.\n\n> [!Note]\n> The circuit depth can grow complex for a long array of samples which is the case with Digital Audio. It is optimal to represent a short length of samples per Circuit when using the `encode()` method.<br>\n\n### Working with Digital Audio\nFor faster processing of longer arrays, the `stream` method is preferred. \n```python\nquantumaudio.stream(data)\n```\nIt wraps the functions provided in the module `quantumaudio.tools.stream` that help process large arrays as chunks for efficient handling. Examples of its usage can be found in the [Demos](https://github.com/moth-quantum/quantum-audio/tree/main/demos) provided in the repository.\n\n### Running on Native Backends\n\nA Scheme's ```decode()``` method uses local [_AerSimulator_](https://github.com/Qiskit/qiskit-aer) as the default backend. Internally, the function calls `utils.execute()` method that performs ```backend.run()```. Any such backend object compatible with Qiskit can be passed to the ```backend=``` parameter of the `decode()` function. To configure this further or to use primitives, please refer to custom [execute functions](#custom_functions).\n\n### Running on External Quantum Backends\n\nThe package allows flexible use of Quantum Hardware from different Providers as the execution of circuits can be done independently. Depending on the results, there are two ways to decode quantum audio:\n\n- **Results Object:** If the result obtained follow the format of [qiskit.result.Result](https://docs.quantum.ibm.com/api/qiskit/qiskit.result.Result) or [qiskit.primitives.PrimitiveResult](https://docs.quantum.ibm.com/api/qiskit/qiskit.primitives.PrimitiveResult),\n  - The audio can be decoded with ```scheme.decode_result(result_object)``` method.\n  - In this case, relevant metadata information is automatically extracted and applied at decoding. It can also be manually passed using `metadata=` parameter.\n<br><br>\n- **Counts Dictionary:** If the result is in form of a counts dictionary or [qiskit.result.Counts](https://docs.quantum.ibm.com/api/qiskit/qiskit.result.Counts) object,\n  - The audio can be decoded using ```scheme.decode_counts(counts, metadata)``` method.\n  - Here, the metadata dictionary is required which can be obtained from the encoded circuit's `.metadata` attribute.\n    \n> [!Tip]\n> **Dictionaries** are data type in python to store {key : _value_} pairs.\n> - **Counts Dicitonary** contains keys representing classical measurement outcomes and values indicating the number of times the outcome was observed. Example: `{'00': 77, '01': 79, '10': 84, '11': 72}`.\n> - **Metadata Dictionary** stores the key information that is required at decoding, which is commonly the original data dimensions to restore and layout of qubits. Both can be obtained from `scheme.calculate()` method.\n\n### Viewing Metadata\nThe Metadata Information can be viewed from the encoded circuit's `.metadata` attribute. The common keys found in a metadata are: \n - **num_samples** (_int_) : Original sample length to restore.\n - **num_channels** (_int_): Original number of channels to restore. (Applicable for multi-channel schemes)\n - **qubit_shape** (_tuple_): Stores the arrangement and number of qubits that encode each aspect of the audio information i.e. _Time_, _Channel_ (if applicable) and _Amplitude_. <br>\n\nThe _QPAM_ scheme's encoding only preserves **num_samples** (_int_) and the normalization factor - **norm_factor** (_float_) which is required to restore the values.\n> [!Note]\n> When passing metadata manually in any of the decode functions, _QPAM_ Scheme additionaly requires **shots** (_int_) information used for executing the circuit which can also be passed through the argument `shots=`.\n\n> [!Tip]\n> The essential keys required for decoding with any scheme can be checked from the scheme's `.keys` attribute.\n\n### Using Custom Functions <a id=\"custom_functions\"></a>\nThe `decode` and `stream` operations can be configured with the following custom functions. They require few mandatory arguments followed by custom preceding keyword arguments (denoted as `**kwargs`).\n- **Process Function**:\nThe default process function of `stream()` simply encodes and decodes a chunk of data with default parameters. It can be overriden by passing a custom function to the `process_function=` parameter. The mandatory arguments for the custom process function are `data=` and `scheme=`.\n```python\nprocessed_data = process_function(data, scheme, **kwargs)\n```\n- **Execute Function** :\nThe default execute function for `decode()` can be overriden by passing a custom function to the `execute_function=` parameter. The mandatory argument for the custom execute function is `circuit=`. (QPAM also expects `shots=` since it's a metadata)\n```python\nresult = execute_function(circuit, **kwargs)\n``` \n**Example**: An optional execute function is included in the package which uses [Sampler Primitive](https://docs.quantum.ibm.com/api/qiskit-ibm-runtime/qiskit_ibm_runtime.SamplerV2): `quantumaudio.utils.execute_with_sampler` that can be passed to the `decode()` method. It requires the dependency `pip install qiskit-ibm-runtime`. <br>\n \n## \ud83d\udcd8 Additional Resources <a id=\"materials\"></a>\n### Notebook Examples\nFor examples of circuit preparation, signal reconstruction, and interactive demonstrations, please check the [Demo Notebook](https://github.com/moth-quantum/quantum-audio/blob/main/demos/1_Basics_Walkthrough.ipynb). It combines the core package with additional functions from the `demos/tools` folder to go through Visual and Digital Audio examples.\n\n### Quick Export \u26a1\ufe0f\nTo quickly export quantumaudio from any audio file (e.g., _mp3_, _ogg_, _flac_, _m4a_), a script ```export.py``` is provided in the `demos/scripts` folder. Navigate to the directory and run:\n  ```bash\n  python export.py -i path/to/input/audio/file\n  ```\n  ```console\n  usage: export.py [-h] -i [-o] [-v] [--scheme] [--shots] [--sr] [--stereo] [--buffer_size]\n\n  Process quantum audio and export as .wav file.\n\n  options:\n    -h, --help            show this help message and exit\n    -i, --input           Path to the input audio file.\n    -o, --output          Path to the output audio file. (default: saves in same directory with a prefix `qa_`)\n    -v, --verbose         Enable verbose mode.\n    --scheme              Quantum Audio Scheme (default: `qpam` for mono audio, `mqsm` for stereo audio).\n    --shots               Number of shots for measurement (default: 8000)\n    --sr                  Sample rate of Digital audio (default: 22050)\n    --stereo              Enable stereo\n    --buffer_size         Length of each audio chunk (default: 256)\n  ```\n\n> [!Note]\n > Digital Audio [Dependencies](#installation) must be installed to run this script.\n\n## \ud83e\udd1d Contributing <a id=\"contributing\"></a>\nContributions to Quantum Audio are welcome! This package is designed to be a versatile tool for both research and artistic exploration.\n\nIf you find any issues or have suggestions for improvements, please open an issue or submit a pull request on the GitHub repository. \n\n- **Code Contributions:** Add new features, fix bugs, or improve existing functionality and code.\n- **Documentation:** Enhance the README, tutorials, or other project documentation.\n- **Educational Use:** If you\u2019re using this project for learning, teaching or research, we\u2019d love to hear about your experiences and suggestions.\n- **Feedback and Ideas:** Share your thoughts, feature requests, or suggest improvements by opening an issue.\n\nFor more information on contributing to Code and Documentation, please review [Contributing Guidelines](https://github.com/moth-quantum/quantum-audio/blob/main/docs/guides/CONTRIBUTING.md)\n\n## \ud83d\udea9 Future Releases <a id=\"future-releases\"></a>\nWe're excited to keep the package updated with features and improvements! In future releases, we plan to introduce other schemes from Quantum Audio Literature along with Base Scheme Class Categories to support a generic structure for further contributions.\n\n## \u2705 Citing <a id=\"citation\"></a>\nIf you use this code or find it useful in your research, please consider citing:\n> Moth Quantum and collaborators. (2024). Quantum Audio (v0.1.0). Zenodo. https://doi.org/10.5281/zenodo.14012135\n---\n## \ud83d\udce7 Contact <a id=\"contact\"></a>\n\nWe're here to help! If you have any questions or need further assistance, please feel free reach out to our team using the support options provided below:\n\n- **General Questions**: Ask on [Stack Overflow](https://stackoverflow.com/tags/quantumaudio/) using the `quantumaudio` tag.\n- **Direct Contact**: For private or specific issues, reach us at [qap.support@mothquantum.com](mailto:qap.support@mothquantum.com).\n- **Bugs & Feature Requests**: Please [open an issue](https://github.com/moth-quantum/quantum-audio/issues) on GitHub.\n\nBefore posting, check the [Documentation](https://quantumaudio.readthedocs.io), or existing questions in [Stack Overflow](https://stackoverflow.com/tags/quantumaudio/) to see if your question has been answered.\n\n## \ud83d\udcdc Copyright\nCopyright 2024 Moth Quantum\n\nLicensed under the [Apache License](LICENSE), Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the [License](LICENSE) for the specific language governing permissions and limitations under the License.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A Python package for building Quantum Representations of Digital Audio. Developed by Moth Quantum.",
    "version": "0.1.0",
    "project_urls": {
        "Documentation": "https://quantumaudio.readthedocs.io/",
        "Homepage": "https://mothquantum.com",
        "Repository": "https://github.com/moth-quantum/quantum-audio"
    },
    "split_keywords": [
        "audio",
        " quantum computing",
        " signal processing"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "82919a3f09516720f4eca5fe8aa02115d9749ea6d65157030ecf0ab465b72e3d",
                "md5": "599abe3d99dd09d557728c9a95428f7e",
                "sha256": "e929078d80aa407b3e035dfa60f35ca1165e63ee8b26fc1d2f61006baa3849e1"
            },
            "downloads": -1,
            "filename": "quantumaudio-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "599abe3d99dd09d557728c9a95428f7e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 56624,
            "upload_time": "2024-11-01T15:42:38",
            "upload_time_iso_8601": "2024-11-01T15:42:38.359583Z",
            "url": "https://files.pythonhosted.org/packages/82/91/9a3f09516720f4eca5fe8aa02115d9749ea6d65157030ecf0ab465b72e3d/quantumaudio-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c2c95408c23a489da103288a5d3565d273e6d4601e03a1509f6cfc8886504fe8",
                "md5": "c94b3b5551754e6555792d6bfa1f95e5",
                "sha256": "1a4a87ee4dbb54f4684712adbc0a02aa44a2952fd7404de1e660957c8ee3979a"
            },
            "downloads": -1,
            "filename": "quantumaudio-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "c94b3b5551754e6555792d6bfa1f95e5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 41964,
            "upload_time": "2024-11-01T15:43:03",
            "upload_time_iso_8601": "2024-11-01T15:43:03.536999Z",
            "url": "https://files.pythonhosted.org/packages/c2/c9/5408c23a489da103288a5d3565d273e6d4601e03a1509f6cfc8886504fe8/quantumaudio-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-01 15:43:03",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "moth-quantum",
    "github_project": "quantum-audio",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "qiskit",
            "specs": []
        },
        {
            "name": "qiskit_aer",
            "specs": [
                [
                    "==",
                    "0.13.3"
                ]
            ]
        },
        {
            "name": "numpy",
            "specs": []
        },
        {
            "name": "bitstring",
            "specs": []
        },
        {
            "name": "matplotlib",
            "specs": []
        },
        {
            "name": "pylatexenc",
            "specs": []
        },
        {
            "name": "tqdm",
            "specs": []
        },
        {
            "name": "packaging",
            "specs": []
        }
    ],
    "lcname": "quantumaudio"
}
        
Elapsed time: 0.44469s