{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "3eea6d3e", "metadata": { "execution": { "iopub.execute_input": "2024-03-26T18:57:17.353790Z", "iopub.status.busy": "2024-03-26T18:57:17.353414Z", "iopub.status.idle": "2024-03-26T18:57:17.356286Z", "shell.execute_reply": "2024-03-26T18:57:17.355845Z" }, "nbsphinx": "hidden" }, "outputs": [], "source": [ "# Copyright 2024 Keysight Technologies Inc." ] }, { "cell_type": "raw", "id": "56d3c914", "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": "cff71dc9", "metadata": { "execution": { "iopub.execute_input": "2024-03-26T18:57:17.358248Z", "iopub.status.busy": "2024-03-26T18:57:17.357904Z", "iopub.status.idle": "2024-03-26T18:57:20.277007Z", "shell.execute_reply": "2024-03-26T18:57:20.276544Z" } }, "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": "ff71540f", "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": "86266366", "metadata": { "execution": { "iopub.execute_input": "2024-03-26T18:57:20.279392Z", "iopub.status.busy": "2024-03-26T18:57:20.278893Z", "iopub.status.idle": "2024-03-26T18:57:20.282843Z", "shell.execute_reply": "2024-03-26T18:57:20.282422Z" } }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "DisplayWrapper(