{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Verbatim compilation" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "# Use Braket SDK Cost Tracking to estimate the cost to run this example\n", "from braket.tracking import Tracker\n", "t = Tracker().start()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Usually, when you run a circuit on a QPU, behind the scenes, Amazon Braket will do a series of compilation steps to optimize your circuit and map the abstract circuit to the physical qubits on the QPU. However, in many situations, such as for error mitigation or benchmarking experiments, researchers require full control of the qubits and the gates that are being applied. In a [previous notebook](https://github.com/aws/amazon-braket-examples/blob/main/examples/braket_features/Allocating_Qubits_on_QPU_Devices.ipynb), we showed you how to manually allocate the qubits of your circuit, i.e., how you can exactly define which logical qubit maps to which physical qubit. In this notebook, you will learn how to use _verbatim compilation_ to run your circuits exactly as defined without any modification during the compilation process.\n", "\n", "### Table of contents:\n", "\n", "* [Recap: Running circuits on Amazon Braket](#Recap)\n", "* [Using verbatim compilation to run circuits without further compilation](#Verbatim)\n", "* [Programming verbatim circuits onto the Rigetti device](#Rigetti)\n", "* [Programming verbatim circuits onto the Oxford Quantum Circuits device](#OQC)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Recap: Running circuits on Amazon Braket " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let us begin with importing the usual dependencies. Verbatim compilation is supported by all Rigetti devices, and we will use the Aspen-M-3 device for this demonstration." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# general imports\n", "import boto3\n", "from braket.aws import AwsDevice\n", "from braket.circuits import Circuit\n", "from math import pi\n", "import networkx as nx\n", "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "When you run a circuit on Amazon Braket, different compilation and optimization steps occur before the circuit is executed on the selected QPU. First, the gates of your circuit are decomposed into the _native gates_ of the QPU. Let's first remember what the native gates of the Aspen-M-3 device are:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The native gates for the Aspen-M device are:\n", "rx\n", "rz\n", "cz\n", "cphaseshift\n", "xy\n" ] } ], "source": [ "# set up the Rigetti Aspen-M-3 device\n", "device = AwsDevice(\"arn:aws:braket:us-west-1::device/qpu/rigetti/Aspen-M-3\")\n", "\n", "# list the native gate set\n", "print(\"The native gates for the\", device.name, \"device are:\")\n", "for gate in device.properties.paradigm.nativeGateSet:\n", " print(gate)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If we create a circuit with gates that are not part of that list, the gates will automatically be decomposed into a gate set that can be executed on the device." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
add_verbatim_box
is currently only supported on Rigetti, OQC, and IonQ devices.\n",
"disable_qubit_rewiring
flag must be set to True
\n",
"