{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Connect to system"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from py4lexis.session import LexisSession\n",
    "from qaas.client import QProvider, QBackend, QJob\n",
    "\n",
    "\n",
    "# 1. Authentication\n",
    "lexis_session = LexisSession()\n",
    "token = lexis_session.get_access_token()\n",
    "\n",
    "# 2. Configure resources\n",
    "PROJECT = \"\"\n",
    "RESOURCE = \"VLQ-XX\"\n",
    "\n",
    "# 3. Initialize QaaS\n",
    "provider = QProvider(token, PROJECT)\n",
    "backend:QBackend = provider.get_backend(RESOURCE)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Prepare circuit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from qiskit import QuantumCircuit\n",
    "\n",
    "# Define quantum circuit\n",
    "num_qb = 5\n",
    "qc = QuantumCircuit(num_qb)\n",
    "qc.h(0)\n",
    "for qb in range(1, num_qb):\n",
    "    qc.cx(0, qb)\n",
    "\n",
    "qc.barrier()\n",
    "qc.measure_all()\n",
    "\n",
    "qc.draw(output='mpl')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from iqm.qiskit_iqm import  transpile_to_IQM\n",
    "\n",
    "# Transpile circuit\n",
    "qc_transpiled = transpile_to_IQM(qc, backend)\n",
    "qc_transpiled.draw(output=\"mpl\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Run circuit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from qiskit.visualization import plot_histogram\n",
    "\n",
    "# Run circuit\n",
    "SHOTS = 5000\n",
    "\n",
    "job = backend.run(qc_transpiled, shots=SHOTS)\n",
    "results = job.result().get_counts()\n",
    "\n",
    "\n",
    "# Plot result\n",
    "print(results)\n",
    "\n",
    "result_clean = {key: count for key, count in results.items() if count > 15}\n",
    "display(plot_histogram(result_clean))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.11.15"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
