{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "6f4d78c9",
"metadata": {
"execution": {
"iopub.execute_input": "2024-04-26T18:20:56.091025Z",
"iopub.status.busy": "2024-04-26T18:20:56.090599Z",
"iopub.status.idle": "2024-04-26T18:20:56.094401Z",
"shell.execute_reply": "2024-04-26T18:20:56.093965Z"
},
"nbsphinx": "hidden"
},
"outputs": [],
"source": [
"# Copyright 2024 Keysight Technologies Inc."
]
},
{
"cell_type": "raw",
"id": "35f34998",
"metadata": {
"raw_mimetype": "text/restructuredtext"
},
"source": [
"\n",
"Example: Quantum Circuits with Qudits\n",
"=====================================\n",
"Quantum systems used for quantum computing contain quantized energy levels which can\n",
"be used to define computational states. Most quantum computing devices follow the\n",
"standard classical convention of using a two-level system with basis states labeled by\n",
"``0`` and ``1``, that is a canonical qubit.\n",
"\n",
"Since quantum systems generally have more than two energy levels available,\n",
"the restriction to only two of them does not allow the quantum device to fully\n",
"leverage the available state space. Additionally, the presence of unused levels can\n",
"lead to loss of information as the state can \"leak\" into unused energy levels.\n",
"For this reason, some hardware developers choose to design their quantum computing\n",
"devices to use more than the standard two levels. In these cases, the multi-level\n",
"unit is referred to as a *qudit*. Many of our tutorials refer only to qubits for\n",
"simplicity. However, our protocols apply more generally to qudits.\n",
"\n",
"The dimension of a qudit refers to the number of energy levels used to store\n",
"information. |True-Q| supports qudit systems of dimensions 2, 3, 5 and 7. These prime\n",
"dimensions are compatible with the stabilizer formalism and measurements for these\n",
"dimensions produce single-digit outputs.\n",
"\n",
"In this tutorial, we provide a basic introduction to qudits and show how to start\n",
"creating |True-Q| circuits for qudits. We direct users to\n",
":doc:`../../guides/fundamentals/qudit_math` for a more in-depth introduction to the\n",
"mathematical framework used to model qudit computations and an overview of the classes\n",
"used to represent the operations defined for that framework."
]
},
{
"cell_type": "raw",
"id": "23d0bb62",
"metadata": {
"raw_mimetype": "text/restructuredtext"
},
"source": [
"We define the computational basis of a qudit to be an orthogonal set of states, each\n",
"of which corresponds to a single energy level,\n",
"\n",
".. math::\n",
" \\{\\ket{0}, \\ket{1}, ..., \\ket{d-1}\\}.\n",
"\n",
"A qudit state :math:`\\ket{\\psi}` can then be expressed as a linear combination of\n",
"these basis states,\n",
"\n",
".. math::\n",
" \\ket{\\psi}=\\sum_{a=0}^{d-1}c_a(\\psi)\\ket{a},\n",
"\n",
"where :math:`c_a(\\psi)` are constants.\n",
"\n",
"Using Qudits in |True-Q|\n",
"------------------------\n",
"\n",
"Qudit circuits can be constructed in the same way as regular qubit circuits, and in\n",
"fact most of the |True-Q| tools work with no or very minor syntax modifications for\n",
"qudits.\n",
"\n",
"We provide gate aliases for standard qudit gates that follow the same naming\n",
"convention as the qubit gates but with the dimension attached to their name, e.g.\n",
"the alias ``tq.Gate.x3`` represents a qutrit :math:`X` gate. Using these aliases,\n",
"defining circuits is straight-forward:\n",
"\n",
"We can specify the qudit dimension we want to work in by setting the global\n",
"dimensional parameter:"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "fe8fde91",
"metadata": {
"execution": {
"iopub.execute_input": "2024-04-26T18:20:56.096276Z",
"iopub.status.busy": "2024-04-26T18:20:56.095995Z",
"iopub.status.idle": "2024-04-26T18:20:58.376116Z",
"shell.execute_reply": "2024-04-26T18:20:58.375609Z"
}
},
"outputs": [],
"source": [
"import trueq as tq\n",
"\n",
"# set the global dimension to 3\n",
"tq.settings.set_dim(3)"
]
},
{
"cell_type": "raw",
"id": "e014f1ec",
"metadata": {
"raw_mimetype": "text/restructuredtext"
},
"source": [
"To start off, let's define a simple circuit for a two-qutrit\n",
"system that consists of a single-qutrit :math:`X` gate, a single-qutrit :math:`F` or\n",
"Fourier gate (the higher-dimensional generalization of the Hadamard gate), and a\n",
"two-qutrit controlled-:math:`X` gate. Note that we define gate aliases for standard\n",
"qudit gates following the same convention of qubit gates but with the dimension\n",
"appended (e.g. the alias ``tq.Gate.x3`` represents a qutrit :math:`X` gate)."
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "58e2f665",
"metadata": {
"execution": {
"iopub.execute_input": "2024-04-26T18:20:58.378699Z",
"iopub.status.busy": "2024-04-26T18:20:58.378446Z",
"iopub.status.idle": "2024-04-26T18:20:58.410148Z",
"shell.execute_reply": "2024-04-26T18:20:58.409714Z"
},
"lines_to_next_cell": 0
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
"DisplayWrapper("
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"sim = tq.Simulator()\n",
"sim.run(circuit)\n",
"\n",
"circuit.results.plot()"
]
},
{
"cell_type": "raw",
"id": "f7fe7364",
"metadata": {
"raw_mimetype": "text/restructuredtext"
},
"source": [
"Notice that since the circuit we ran acts on 2 qutrits, the results are in\n",
":math:`\\mathbb{Z}_3^2 = \\{00, 01, ..., 22\\}` because the computational state space for\n",
"a single :math:`d`\\-dimensional qudit spans :math:`\\mathbb{Z}_d=\\{0, 1, ... d-1\\}`\\.\n",
"\n",
"Qudit Protocols\n",
"---------------\n",
"\n",
"As mentioned above, our |True-Q| protocols generalize seamlessly to qudits of\n",
"dimension larger than :math:`2`\\. For example, take a look at how the following\n",
"protocols work for qudits:\n",
"\n",
"* :doc:`../error_diagnostics/srb`\n",
"* :doc:`../error_diagnostics/xrb`\n",
"* :doc:`../error_diagnostics/cb`\n",
"* :doc:`../error_diagnostics/knr`\n",
"* :doc:`../error_suppression/rc_simple_intro`\n",
"* :doc:`../error_suppression/rcal`"
]
}
],
"metadata": {
"jupytext": {
"cell_metadata_filter": "nbsphinx,raw_mimetype,-all",
"main_language": "python",
"notebook_metadata_filter": "-all",
"text_representation": {
"extension": ".py",
"format_name": "percent"
}
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
}
},
"nbformat": 4,
"nbformat_minor": 5
}