@@ -55,12 +55,13 @@ Paddle Quantum aims at establishing a bridge between artificial intelligence (AI
## Features
- Easy-to-use
- Many online learning resources (16+ tutorials)
- Many online learning resources (17+ tutorials)
- High efficiency in building QNN with various QNN templates
- Automatic differentiation
- Versatile
- Multiple optimization tools and GPU mode
- Simulation with 25+ qubits
- Flexible noise models
- Featured Toolkits
- Toolboxes for Chemistry & Optimization
- LOCCNet for distributed quantum information processing
...
...
@@ -143,8 +144,9 @@ We provide tutorials covering combinatorial optimization, quantum chemistry, qua
14.[Entanglement Distillation -- Protocol design with LOCCNet](./tutorial/LOCC)
15.[Quantum Teleportation](./tutorial/LOCC)
16.[Quantum State Discrimination](./tutorial/LOCC)
17.[Noise Model and Quantum Channel](./tutorial/Noise)
With the latest LOCCNet module, Paddle Quantum can efficiently simulate distributed quantum information processing tasks. Interested readers can start with this [tutorial on LOCCNet](./tutorial/LOCC/LOCCNET_Tutorial_EN.ipynb). In addition, Paddle Quantum supports QNN training on GPU. For users who want to get into more details, please check out the tutorial [Use Paddle Quantum on GPU](./introduction/PaddleQuantum_GPU_EN.ipynb).
With the latest LOCCNet module, Paddle Quantum can efficiently simulate distributed quantum information processing tasks. Interested readers can start with this [tutorial on LOCCNet](./tutorial/LOCC/LOCCNET_Tutorial_EN.ipynb). In addition, Paddle Quantum supports QNN training on GPU. For users who want to get into more details, please check out the tutorial [Use Paddle Quantum on GPU](./introduction/PaddleQuantum_GPU_EN.ipynb). Moreover, Paddle Quantum could design robust quantum algorithms under noise. For more information, please see [Noise tutorial](./tutorial/Noise/Noise_EN.ipynb).
### API documentation
...
...
@@ -177,6 +179,8 @@ So far, we have done several projects with the help of Paddle Quantum as a power
[5] Wang, K., Song, Z., Zhao, X., Wang Z. & Wang, X. Detecting and quantifying entanglement on near-term quantum devices. arXiv:2012.14311 (2020). [[pdf]](https://arxiv.org/pdf/2012.14311.pdf)
[6] Zhao, X., Zhao, B., Wang, Z., Song, Z., & Wang, X. LOCCNet: a machine learning framework for distributed quantum information processing. arXiv:2101.12190 (2021). [[pdf]](https://arxiv.org/pdf/2101.12190.pdf)
## Frequently Asked Questions
1.**Question:** What is quantum machine learning? What are the applications?
[5] Wang, K., et al. Detecting and quantifying entanglement on near-term quantum devices. arXiv:2012.14311 (2020). [[pdf]](https://arxiv.org/pdf/2012.14311.pdf)
[6] Zhao, X., Zhao, B., Wang, Z., Song, Z., & Wang, X. LOCCNet: a machine learning framework for distributed quantum information processing. arXiv:2101.12190 (2021). [[pdf]](https://arxiv.org/pdf/2101.12190.pdf)
"[1] Iverson, J. K., & Preskill, J. Coherence in logical quantum channels. [New Journal of Physics, 22(7), 073066 (2020).](https://iopscience.iop.org/article/10.1088/1367-2630/ab8e5c)\n",
"\n",
"[2] Nielsen, M. A. & Chuang, I. L. Quantum computation and quantum information. Cambridge university press (2010).\n",
"\n",
"[3] Preskill, J. Quantum Information Lecture Notes. Chapter 3 (2018).\n",
"\n",
"[4] Chirolli, L., & Burkard, G. Decoherence in solid-state qubits. [Advances in Physics, 57(3), 225-285 (2008).](https://www.tandfonline.com/doi/abs/10.1080/00018730802218067)\n",
"\n",
"[5] Peruzzo, A. et al. A variational eigenvalue solver on a photonic quantum processor. [Nat. Commun. 5, 4213 (2014).](https://www.nature.com/articles/ncomms5213)"
"# Simulating noisy quantum circuits with Paddle Quantum\n",
"\n",
"<em> Copyright (c) 2021 Institute for Quantum Computing, Baidu Inc. All Rights Reserved. </em>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Introduction to quantum noises\n",
"\n",
"In ideal models, we usually assume that quantum circuits are operating on a **closed physical system**. However, real quantum devices suffer from **incoherent noises** introduced by unwanted interactions between the system and the environment. This type of noise can significantly change the performance of quantum computation tasks and hence can hardly be ignored for near-term quantum devices. Consequently, designing robust quantum algorithms under the presence of noise is crucial for utilizing quantum computation in the real world. With the noise module of Paddle Quantum, we can now not only design and simulate quantum algorithms but also examine various noises' influence and further develop error mitigation schemes.\n",
"\n",
"## Building noise models in Paddle Quantum\n",
"\n",
"### Noise model and quantum channel\n",
" \n",
"The evolution of a closed quantum system is always unitary. Mathematically, we can describe such a process as implementing a parameterized quantum circuit $U(\\vec{\\theta})$,\n",
"where $\\rho$ is the initial quantum state, $\\vec{\\theta}$ is a vector containing all the parameters. The most intuitive type of noise one can think of is the error that appears in these parameters, \n",
"$\\vec{\\epsilon}$ can be a white noise sampled from Gaussian distributions. This kind of noise is a specific example of **coherent noises**. Coherent noise usually occurs due to device calibration errors or quantum control errors. We want to emphasize that one also uses unitary transformation $U(\\vec{\\epsilon})$ to describe coherent noises. In certain cases, coherent noises can be more damaging than incoherent noises [1]. \n",
"\n",
"Most of the time, the real problem lies on the evolution of an **open quantum system** that is non-unitary. Under this circumstance, we need a more general description beyond the unitary transformation to characterize incoherent noises, the language of **quantum channels**. To keep the discussion precise, we use *operator-sum representation* [2] to introduce a quantum channel as \n",
"where $\\{E_k\\}$ are *Kraus* operators, and they satisfy the completeness condition $\\sum_k E_k^\\dagger E_k = I$. Mathematically, a quantum channel is completely positive and trace-preserving [2].\n",
"\n",
"Under this representation, we can explicitly observe the results of implementing a quantum channel: Suppose we start with a pure state $\\rho = |\\psi\\rangle\\langle \\psi|$, then we send it through a noisy quantum channel (e.g., $m = 2$ ). Eventually, we will get a mixed state $\\mathcal{E}(\\rho) = E_0 \\rho E_0^\\dagger + E_1 \\rho E_1^\\dagger$. Let's take the bit flip noise as an example: \n",
"\n",
"$$\n",
"\\mathcal{E}_{BF}(\\rho) = (1 - p) I \\rho I+ p X \\rho X,\n",
"\\tag{4}\n",
"$$\n",
"\n",
"where $X,I$ are Pauli operators. The corresponding *Kraus* operators are:\n",
"\n",
"$$\n",
"E_0 = \\sqrt{1-p}\n",
"\\begin{bmatrix}\n",
"1&0 \\\\\n",
"0&1\n",
"\\end{bmatrix},\n",
"E_1 = \\sqrt{p}\n",
"\\begin{bmatrix}\n",
"0& 1 \\\\\n",
"1 &0\n",
"\\end{bmatrix}.\n",
"\\tag{5}\n",
"$$\n",
"\n",
"The physical meaning of this quantum channel is there exist a probability $p$ that the state $|0\\rangle$ will flip into $|1\\rangle$, and vice versa. In Paddle Quantum, we can use this quantum channel by `UAnsatz.bit_flip(p, which_qubit)`, where `p` is the noise level.\n",
"\n",
"**Note:** For a quantum channel, the Kraus operator representation is not necessarily unique [3]."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Implementation with Paddle Quantum\n",
"\n",
"In this section, we will learn how to build a noise model in Paddle Quantum. First, we initialize a qubit to $|0\\rangle$. "
"Quantum state after the bit flip quantum channel:\n",
" [[0.9+0.j 0. +0.j]\n",
" [0. +0.j 0.1+0.j]]\n"
]
}
],
"source": [
"# Noise level\n",
"p = 0.1\n",
"\n",
"# Add the bit flip noisy channel\n",
"cir.bit_flip(p, 0)\n",
"\n",
"# Execute the circuit\n",
"# Note: Noisy module in Paddle Quantum only supports density matrix operation mode\n",
"fin_state = cir.run_density_matrix()\n",
"\n",
"# Measure in the computational basis\n",
"cir.measure(plot=True)\n",
"print('Quantum state after the bit flip quantum channel:\\n', fin_state.numpy())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As we can see, the quantum state has been transformed to a mixed state $0.9 | 0 \\rangle \\langle 0 | + 0.1 | 1 \\rangle \\langle 1 |$ (with probability $p=0.1$ ) after the bit flip channel.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Common quantum channels\n",
"\n",
"Paddle Quantum supports many other common noisy channels.\n",
"\n",
"- **Phase Flip Channel**\n",
"\n",
" Similar to the bit-flip channel, the phase flip channel flips the phase of a qubit with probability $p$, \n",
" \n",
" $$\n",
" \\mathcal{E}_{PF}(\\rho) = (1 - p) \\rho + p Z \\rho Z.\n",
" \\tag{6}\n",
" $$\n",
"\n",
"\n",
"- **Bit-Phase Flip Channel**\n",
"\n",
" $$\n",
" \\mathcal{E}_{BPF}(\\rho) = (1-p) \\rho + p Y \\rho Y.\n",
" \\tag{7}\n",
" $$\n",
"\n",
"\n",
"- **Depolarizing Channel**\n",
"\n",
" The quantum state will be in the maximally mixed state $I/2$ with probability $p$ or in the original state with probability $1-p$ after the single qubit depolarizing channel. The depolarizing channel can also be understood as applying Pauli noises symmetrically, \n",
" The generalized amplitude damping channel describes energy exchange between the system and the environment at **finite temperatures**. It is a common noise in superconducting quantum computations [4]. Interested readers can find more information here [API document](https://qml.baidu.com/api/paddle_quantum.circuit.uansatz.html).\n",
"\n",
"\n",
"**Note:** In Paddle Quantum, we can use these noisy channels through `UAnsatz.phase_flip()`, `UAnsatz.bit_phase_flip()`, `UAnsatz.depolarizing()`, `UAnsatz.pauli_channel()`, `UAnsatz.amplitude_damping()`, `UAnsatz.phase_damping()`, and `UAnsatz.generalized_amplitude_damping()`.\n",
"\n",
"**Note:** One usually choose the amplitude damping channel and the phase damping channel to model noises since they describe the physical process in real quantum systems (modeling $T_1$ and $T_2$ process)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Customized Channel\n",
"\n",
"One can also use `UAnsatz.customized_channel()` in Paddle Quantum to add customized noisy channels. This is accomplished through user-defined Kraus operators. Here, we provide an example to reproduce the bit flip channel using customized_channel function:"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"ExecuteTime": {
"end_time": "2021-04-09T02:54:20.758898Z",
"start_time": "2021-04-09T02:54:20.599327Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"quantum state after the customized channel:\n",
" [[0.9+0.j 0. +0.j]\n",
" [0. +0.j 0.1+0.j]]\n",
"\n",
" quantum state after the bit flip channel:\n",
" [[0.9+0.j 0. +0.j]\n",
" [0. +0.j 0.1+0.j]]\n",
"\n",
" are the two the same? True\n"
]
}
],
"source": [
"import paddle\n",
"import numpy as np\n",
"from paddle_quantum.circuit import UAnsatz\n",
"\n",
"# Noise level\n",
"p = 0.1\n",
"\n",
"# We use customized Kraus operator to represent the bit flip channel\n",
"# Note that the data type of a Kraus operator is complex_128\n",
"# Add customized channel, input is a list of Kraus operators\n",
"cir.customized_channel(Kraus_ops, 0)\n",
"\n",
"# Execute the circuit\n",
"fin_state = cir.run_density_matrix()\n",
"\n",
"\n",
"# Compare the results\n",
"cir_1 = UAnsatz(num_qubits)\n",
"cir_1.bit_flip(p, 0)\n",
"fin_state_1 = cir_1.run_density_matrix()\n",
"print('quantum state after the customized channel:\\n', fin_state.numpy())\n",
"print('\\n quantum state after the bit flip channel:\\n', fin_state_1.numpy())\n",
"print('\\n are the two the same?', bool((fin_state - fin_state_1).abs().sum() < 1e-8))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Discussion: Simulating noisy entanglement resources with Paddle Quantum\n",
"\n",
"Many important quantum technologies require pre-shared entanglement resources, including quantum teleportation, state transformation, and distributed quantum computing. For instance, we want the allocated entanglement resources are in **maximally entangled states** under ideal circumstances. But in reality, noise always exists due to interactions between the system and the environment during preparation stage, transmission, and preservation. Here, we use the depolarized channel to simulate how a white noise could affect Bell states: "
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"ExecuteTime": {
"end_time": "2021-04-09T02:58:30.352039Z",
"start_time": "2021-04-09T02:58:30.311223Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Fidelity between the initial state and the Bell state 1\n",
"after transmission (depolarized channel), the fidelity between the entangled state and Bell state 0.81333\n",
"after preservation (amplitude damping channel), the fidelity between the entangled state and Bell state 0.66752\n"
]
}
],
"source": [
"import paddle\n",
"from paddle import matmul, trace\n",
"from paddle_quantum.circuit import UAnsatz\n",
"from paddle_quantum.state import bell_state\n",
"\n",
"# Noise level\n",
"p_trans = 0.1\n",
"p_store = 0.01\n",
"\n",
"# Initialize the circuit\n",
"num_qubits = 2\n",
"cir = UAnsatz(num_qubits)\n",
"\n",
"# The initial state is Bell state\n",
"init_state = paddle.to_tensor(bell_state(2))\n",
"\n",
"# Apply the depolarized channel to each qubit, modeling the noise introduced by transmission\n",
"print(\"Fidelity between the initial state and the Bell state\", 1)\n",
"print(\"after transmission (depolarized channel), the fidelity between the entangled state and Bell state {:.5f}\".format(fidelity_mid.numpy()[0]))\n",
"print(\"after preservation (amplitude damping channel), the fidelity between the entangled state and Bell state {:.5f}\".format(fidelity_fin.numpy()[0]))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Note:** Interested readers can check tutorials on the LOCCNet module of Paddle Quantum, where we discuss the concept of [entanglement distillation](https://qml.baidu.com/tutorials/loccnet/entanglement-distillation-with-loccnet.html)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Application: Simulating noisy VQE with Paddle Quantum\n",
"\n",
"\n",
"Variational Quantum Eigensolver (VQE) [5] is designed to find the ground state energy of a given molecular Hamiltonian using variational quantum circuits. Interested readers can find more details from the previous tutorial [VQE](https://qml.baidu.com/tutorials/variational-quantum-eigensolver.html).\n",
"\n",
"For illustration purposes, we use VQE to find the ground state energy for the following Hamiltonian: \n",
"\n",
"$$ \n",
"H = 0.4 \\, Z \\otimes I + 0.4 \\, I \\otimes Z + 0.2 \\, X \\otimes X. \n",
"\\tag{14}\n",
"$$\n",
"\n",
"Then, we add the amplitude damping channel and compare the performance of the noisy circuit and the noiseless circuit on this task:"
"print('\\nGround state energy from noisy circuit: ', loss_list[-1], \"Ha\")\n",
"print('Ground state energy from noiseless circuit: ', loss_list_no_noise[-1], \"Ha\")\n",
"print('Actual ground state energy: ', np.linalg.eigh(H_matrix)[0][0], \"Ha\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As we can see, noisy VQE behaves much worse than the noiseless version as expected and couldn't satisfy chemical accuracy $\\varepsilon = 0.0016$ Ha."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Conclusion\n",
"\n",
"Noise is an unavoidable feature of quantum devices in the NISQ era. Therefore, designing robust quantum algorithms under the presence of noise and further developing error mitigation schemes are two important research directions. With the noise module in Paddle Quantum, we hope to provide a platform simulating real physical systems and help developing near-term quantum computation applications. Standing together with the research community, the noise module will help us explore what we can achieve with noisy devices, design more robust quantum algorithms, and eventually leads to trustworthy quantum solutions in areas including AI and quantum chemistry.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"---\n",
"\n",
"## References\n",
"\n",
"[1] Iverson, J. K., & Preskill, J. Coherence in logical quantum channels. [New Journal of Physics, 22(7), 073066 (2020).](https://iopscience.iop.org/article/10.1088/1367-2630/ab8e5c)\n",
"\n",
"[2] Nielsen, M. A. & Chuang, I. L. Quantum computation and quantum information. Cambridge university press (2010).\n",
"\n",
"[3] Preskill, J. Quantum Information Lecture Notes. Chapter 3 (2018).\n",
"\n",
"[4] Chirolli, L., & Burkard, G. Decoherence in solid-state qubits. [Advances in Physics, 57(3), 225-285 (2008).](https://www.tandfonline.com/doi/abs/10.1080/00018730802218067)\n",
"\n",
"[5] Peruzzo, A. et al. A variational eigenvalue solver on a photonic quantum processor. [Nat. Commun. 5, 4213 (2014).](https://www.nature.com/articles/ncomms5213)"
"/Users/v_yusizhuo/opt/anaconda3/envs/pq2.0.1/lib/python3.7/site-packages/ipykernel/ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above.\n",
"/Users/v_yusizhuo/opt/anaconda3/envs/pq2.0.1/lib/python3.7/site-packages/ipykernel/ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above.\n",