{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b64f0863",
   "metadata": {},
   "outputs": [],
   "source": [
    "# current quantum computers don't have enough qubits to do\n",
    "# meaningful work. So let's horizontally scale and network them\n",
    "# together. So the network becomes part of the compute. So the\n",
    "# network must be considered during compilation. so we need to\n",
    "# build out a comprehensive and accurate network model\n",
    "\n",
    "from qiskit import QuantumCircuit\n",
    "from qndk.transpile.transpile import TranspiledCircuit\n",
    "\n",
    "qc = QuantumCircuit(4)\n",
    "qc.h(0)\n",
    "qc.cx(0, 1)\n",
    "qc.cx(1, 2)\n",
    "qc.cx(2, 3)\n",
    "\n",
    "tc = TranspiledCircuit(qc, decompose=False)\n",
    "tc.draw(scale=1.2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c3cb5ca3",
   "metadata": {},
   "outputs": [],
   "source": [
    "tc.draw_qiskit_dag(figsize=(4, 4), dpi=200)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "02561160",
   "metadata": {},
   "outputs": [],
   "source": [
    "from qndk.quantum_network import QPUSpec, build_clos\n",
    "from qndk.partition.kl import KernighanLinPartitioner\n",
    "from qndk.compile.distributed import new_exec_plan, simulate_circuit\n",
    "\n",
    "network = build_clos(\n",
    "    num_levels=2,\n",
    "    qpus_per_rack=1,\n",
    "    qpu_spec=QPUSpec(comp_qubits=2, connectivity=\"all2all\"))\n",
    "\n",
    "pr = KernighanLinPartitioner(circuit=qc, network=network).partition()\n",
    "_ = network.plot(qubits=True, partition_result=pr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "eb5e8f3c",
   "metadata": {},
   "outputs": [],
   "source": [
    "from qndk.simulator.dqc import DQCScheduler\n",
    "\n",
    "sim_result = DQCScheduler(pr).run_simulation()\n",
    "print(sim_result.execution_log_summary_table())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "53d282fb",
   "metadata": {},
   "outputs": [],
   "source": [
    "sim_result.dag_timestep_animation(show_qubits=True, scale=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d8852408",
   "metadata": {},
   "outputs": [],
   "source": [
    "_ = sim_result.plot_gantt_by_device()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5284580c",
   "metadata": {},
   "outputs": [],
   "source": [
    "tc.draw_qiskit_dag(figsize=(4, 4), dpi=200)\n",
    "\n",
    "exec_plan = new_exec_plan(pr)\n",
    "exec_plan.draw_qiskit_dag(figsize=(16, 16), dpi=200)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "env (3.13.5)",
   "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.13.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
