{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "8a16ed64", "metadata": { "execution": { "iopub.execute_input": "2024-04-26T18:16:41.090652Z", "iopub.status.busy": "2024-04-26T18:16:41.090357Z", "iopub.status.idle": "2024-04-26T18:16:41.093999Z", "shell.execute_reply": "2024-04-26T18:16:41.093570Z" }, "nbsphinx": "hidden" }, "outputs": [], "source": [ "# Copyright 2024 Keysight Technologies Inc." ] }, { "cell_type": "raw", "id": "8040db05", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "Example: Interfacing with Other Software\n", "========================================\n", "\n", "You can use the unique functionality of |True-Q| for projects developed in other\n", "quantum computing software libraries by converting objects created by those projects\n", "to |True-Q|. You can also use functionality from other quantum computing software\n", "libraries by converting |True-Q| objects into their format. |True-Q| can natively\n", "convert to and from:\n", "\n", "#. QASM\n", " A quantum assembly language used by many quantum hardware makers.\n", "#. Qiskit\n", " IBM's quantum computing software package.\n", "#. Cirq\n", " Google's quantum computing software package.\n", "#. PyQuil\n", " Rigetti's quantum computing software package.\n", "\n", "Before converting a circuit to/from a software package, the first thing to consider is\n", "what gates you want the outputted circuit to use---since each software package is\n", "independently written, the primitive gates they each use may differ. By default,\n", "|True-Q| will recompile using only the gates supported by the software package.\n", "However, more advanced users can specify a subset of supported gates to compile into\n", "when converting between software platforms by using a custom configuration, as shown\n", "below.\n", "\n", ".. note:: Before starting, make sure that you have installed the software that you\n", " want to convert from, by trying to import it into your Python notebook. If they are\n", " successfully installed, continue on to the next section. |True-Q| does not\n", " automatically install the third-party libraries from above, so if you want to use\n", " them you need to install them separately.\n", "\n", "Examples of Back and Forth Conversions\n", "--------------------------------------\n", "To get a feel for converting between |True-Q| and other software packages, we will\n", "show an example converting from |True-Q| to Cirq and back. Try constructing a circuit\n", "in |True-Q| then running :py:func:`~trueq.Circuit.to_cirq`\\, like this:" ] }, { "cell_type": "code", "execution_count": 2, "id": "b6b46ab2", "metadata": { "execution": { "iopub.execute_input": "2024-04-26T18:16:41.095904Z", "iopub.status.busy": "2024-04-26T18:16:41.095616Z", "iopub.status.idle": "2024-04-26T18:16:44.038202Z", "shell.execute_reply": "2024-04-26T18:16:44.037734Z" } }, "outputs": [ { "data": { "text/html": [ "
(0, 0): ───@───\n",
" │\n",
"(1, 0): ───@───"
],
"text/plain": [
"(0, 0): ───@───\n",
" │\n",
"(1, 0): ───@───"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import trueq as tq\n",
"\n",
"# True-Q does not attempt to load the third party module---in this example, Cirq---until\n",
"# it is needed, for example by to_cirq(), or until load() is called. the method\n",
"# to_trueq() is attached to the third party library's circuit object at this time.\n",
"tq.interface.cirq.load()\n",
"\n",
"circuit = tq.Circuit({(0, 1): tq.Gate.cz})\n",
"circuit.draw(interactive=False)\n",
"\n",
"cirq_circuit = circuit.to_cirq()\n",
"cirq_circuit"
]
},
{
"cell_type": "raw",
"id": "03a071f1",
"metadata": {
"raw_mimetype": "text/restructuredtext"
},
"source": [
"Notice that the ``cirq_circuit`` object is a Cirq circuit, so the output for that\n",
"object is drawn using Cirq's visualization tools. If we want to convert back to\n",
"|True-Q|, we can use the following code and use :py:meth:`~trueq.Circuit.draw` to draw\n",
"a circuit diagram."
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "4a657b41",
"metadata": {
"execution": {
"iopub.execute_input": "2024-04-26T18:16:44.040466Z",
"iopub.status.busy": "2024-04-26T18:16:44.040192Z",
"iopub.status.idle": "2024-04-26T18:16:44.044281Z",
"shell.execute_reply": "2024-04-26T18:16:44.043841Z"
}
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
"DisplayWrapper(