{ "cells": [ { "cell_type": "markdown", "id": "48c6731f-5188-41c1-afc4-123c6ed796ae", "metadata": {}, "source": [ "# Basic circuit execution\n", "This notebooks illustrates how you can run your qiskit code on the Quantum Inspire 2 platform.\n", "\n", "## This notebook makes the following assumptions:\n", "- quantuminspire2 sdk installed\n", "- account exists in the QI2 platform\n", "- Pennylane plugin installed in the same environment as this notebook" ] }, { "cell_type": "code", "execution_count": null, "id": "93fe4f56-4ced-41fc-b778-14d6c95e2434", "metadata": {}, "outputs": [], "source": [ "# Be sure to have logged in to the QI2 platform via the SDK. If you have installed it in the same environment as\n", "# this notebook, you may run this cell.\n", "\n", "!qi login \"https://staging.qi2.quantum-inspire.com\"" ] }, { "cell_type": "markdown", "id": "0d8ba9f9-9b38-4a86-9252-0b9b9fcdc83f", "metadata": {}, "source": [ "## The necessary imports" ] }, { "cell_type": "code", "execution_count": null, "id": "3d4b3950-fe75-47cf-afb5-2286be7c01b4", "metadata": {}, "outputs": [], "source": [ "import pennylane as qml\n", "\n", "from pennylane_quantuminspire2.qi_device import QI2Device" ] }, { "cell_type": "markdown", "id": "0b464f03-9573-4c3c-852c-3ea4477b59ec", "metadata": {}, "source": [ "## What QI Backends are available?" ] }, { "cell_type": "code", "execution_count": null, "id": "df119aa6-6b48-43a5-aa68-ecf4f7c0dc38", "metadata": {}, "outputs": [], "source": [ "# Show all current supported backends:\n", "print(QI2Device.backends())" ] }, { "cell_type": "markdown", "id": "b7ef5531", "metadata": {}, "source": [ "## Choose your backend\n", "\n", "We will choose the QX emulator" ] }, { "cell_type": "code", "execution_count": null, "id": "72f3d7dc", "metadata": {}, "outputs": [], "source": [ "# Get Quantum Inspire's simulator backend:\n", "emulator_backend = QI2Device.get_backend(\"QX emulator\")\n", "\n", "# Instantiate a Pennylane device based on chosen backend\n", "demo_device = QI2Device(emulator_backend)" ] }, { "cell_type": "markdown", "id": "a9f9b123-9b11-4d62-a4ab-8af8f08f7153", "metadata": {}, "source": [ "## Create your Circuit\n", "Let's create a bell state circuit." ] }, { "cell_type": "code", "execution_count": null, "id": "e6bbe6af-9908-46cb-8638-8f29966fbf61", "metadata": {}, "outputs": [], "source": [ "@qml.qnode(demo_device)\n", "def bell_state():\n", " qml.Hadamard(wires=0)\n", " qml.CNOT(wires=[0, 1])\n", " return [qml.expval(qml.Z(x)) for x in range(2)]" ] }, { "cell_type": "markdown", "id": "a638262c-c785-4a4f-9ba2-32cc534225f3", "metadata": {}, "source": [ "## Run the job and get results\n", "Let's run the circuit! Be aware that if your circuit contains gates that are not supported by the target, compilation errors may arise." ] }, { "cell_type": "code", "execution_count": null, "id": "1f446ddc-7fe6-4731-9840-da1775e10e0f", "metadata": {}, "outputs": [], "source": [ "# Execute the circuit\n", "result = bell_state()\n", "print(result)" ] } ], "metadata": { "kernelspec": { "display_name": "qiskit-quantuminspire-C0W6c0G_-py3.12", "language": "python", "name": "python3" }, "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.12.5" } }, "nbformat": 4, "nbformat_minor": 5 }