{ "cells": [ { "cell_type": "markdown", "id": "0", "metadata": {}, "source": [ "Using the Qiskit simulator in new QAT\n", "========================================\n", "\n", "The Qiskit simulator is available with QAT pipelines, however it is just the legacy version of it wrapped so fit the pipeline API. See below for how it can be used to easily execute programs." ] }, { "cell_type": "code", "execution_count": null, "id": "1", "metadata": { "tags": [ "remove-cell" ] }, "outputs": [], "source": [ "# used to disable output from logs; not shown in the docs because of the\n", "# remove-cell tag\n", "import logging\n", "\n", "logging.disable(logging.CRITICAL)" ] }, { "cell_type": "markdown", "id": "2", "metadata": {}, "source": [ "Let's start by writing a simple program that we'd like to execute." ] }, { "cell_type": "code", "execution_count": null, "id": "3", "metadata": {}, "outputs": [], "source": [ "from compiler_config.config import CompilerConfig, QuantumResultsFormat\n", "\n", "config = CompilerConfig(results_format=QuantumResultsFormat().binary_count())\n", "qasm = \"\"\"\n", "OPENQASM 2.0;\n", "include \"qelib1.inc\";\n", "qreg q[2];\n", "creg c[2];\n", "h q[0];\n", "cx q[0], q[1];\n", "measure q -> c;\n", "\"\"\"" ] }, { "cell_type": "markdown", "id": "4", "metadata": {}, "source": [ "Now we can create a Qiskit simulator pipeline and execute the program." ] }, { "cell_type": "code", "execution_count": null, "id": "5", "metadata": {}, "outputs": [], "source": [ "from qat import QAT\n", "from qat.model.loaders.purr.qiskit import QiskitModelLoader\n", "from qat.pipelines.legacy.qiskit import LegacyQiskitPipeline\n", "\n", "loader = QiskitModelLoader(qubit_count=20)\n", "pipeline = LegacyQiskitPipeline(config=dict(name=\"qiskit\"), loader=loader)\n", "\n", "results, metrics = QAT().run(qasm, pipeline=pipeline, compiler_config=config)\n", "print(results)" ] } ], "metadata": { "jupytext": { "main_language": "python", "notebook_metadata_filter": "-kernelspec" }, "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.10.12" } }, "nbformat": 4, "nbformat_minor": 5 }