From cee94710e2fc3d7e538cb5a99fef85094ef403c6 Mon Sep 17 00:00:00 2001 From: jordandsullivan Date: Fri, 27 Sep 2024 15:28:51 -0700 Subject: [PATCH] Remove dupulicate notebooks --- .../custom_compile_heisenberg_ring.ipynb | 242 ------------------ .../custom_compile_qcnn.ipynb | 226 ---------------- .../custom_compile_qft.ipynb | 204 --------------- 3 files changed, 672 deletions(-) delete mode 100644 custom_compiler_experiments/custom_compile_heisenberg_ring.ipynb delete mode 100644 custom_compiler_experiments/custom_compile_qcnn.ipynb delete mode 100644 custom_compiler_experiments/custom_compile_qft.ipynb diff --git a/custom_compiler_experiments/custom_compile_heisenberg_ring.ipynb b/custom_compiler_experiments/custom_compile_heisenberg_ring.ipynb deleted file mode 100644 index 17c50953..00000000 --- a/custom_compiler_experiments/custom_compile_heisenberg_ring.ipynb +++ /dev/null @@ -1,242 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Evolution under Hamiltonian of Heisenberg interaction in an external field, nearest neighbor line" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We are choosing a circuit that has a linear connectivity map which is the simplest possible. The implemented circuit uses a lot of single qubit gates to implement spin interaction along the different axes and the goal is to see whether a custom compiler does better at reducing these gates than the default one." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from qiskit import QuantumCircuit\n", - "\n", - "import time\n", - "import numpy as np" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Define circuit" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "num_qubits = 5\n", - "num_layers = 3\n", - "qc=QuantumCircuit(num_qubits)\n", - "for i_layer in range(num_layers):\n", - " for i in range(num_qubits-1): \n", - " j = (i + 1)\n", - " \n", - " qc.rz(np.random.rand(), i)\n", - " qc.rz(np.random.rand(), j)\n", - " \n", - " qc.cx(i, j)\n", - " qc.rz(0.1, j)\n", - " qc.cx(i, j)\n", - " \n", - " qc.h(i)\n", - " qc.h(j)\n", - " qc.cx(i, j)\n", - " qc.rz(0.1, j)\n", - " qc.cx(i, j)\n", - " qc.h(i)\n", - " qc.h(j)\n", - " \n", - " qc.ry(np.pi/2, i)\n", - " qc.ry(np.pi/2, j)\n", - " qc.cx(i, j)\n", - " qc.rz(0.1, j)\n", - " qc.cx(i, j)\n", - " qc.ry(-np.pi/2, i)\n", - " qc.ry(-np.pi/2, j)\n", - "# Get gate counts\n", - "gate_counts = qc.count_ops()\n", - "print(gate_counts)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Define backend" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from qiskit.providers.fake_provider import GenericBackendV2\n", - "\n", - "backend = GenericBackendV2(num_qubits=num_qubits, basis_gates = ['rz', 'rx', 'ry', 'cx'])" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Optionally print out the circuit" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# qc.draw()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Compile with default passes" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager\n", - "default_pm = generate_preset_pass_manager(backend=backend, optimization_level=3)\n", - "\n", - "t1 = time.time()\n", - "default_qc = default_pm.run(qc)\n", - "t2 = time.time()\n", - "print(\"Time taken: \", t2-t1)\n", - "\n", - "# Get gate counts\n", - "gate_counts = default_qc.count_ops()\n", - "print(gate_counts)\n", - "print(\"Number of 2-qubit gates: \", gate_counts.get(\"cx\", 0)) \n", - "print(\"Number of 1-qubit gates: \", gate_counts.get(\"rx\", 0) + gate_counts.get(\"rz\", 0) + gate_counts.get(\"ry\", 0) + gate_counts.get(\"h\", 0))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# default_qc.draw()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "#Test with UCC transpiler\n", - "\n", - "import sys\n", - "sys.path.append('../')\n", - "\n", - "from ucc import compile\n", - "\n", - "t1 = time.time()\n", - "ucc_qc, gate_counts = compile(qc, mode=\"ucc\", get_gate_counts = True)\n", - "t2 = time.time()\n", - "print(\"Time taken: \", t2-t1)\n", - "\n", - "# # Get gate counts\n", - "print(gate_counts)\n", - "print(\"Number of 2-qubit gates: \", gate_counts.get(\"cx\", 0))\n", - "print(\"Number of 1-qubit gates: \", gate_counts.get(\"rz\", 0) + gate_counts.get(\"rx\", 0) + gate_counts.get(\"ry\", 0) + gate_counts.get(\"h\", 0))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Create custom compiler" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# from qiskit.transpiler import PassManager\n", - "# import qiskit.transpiler.passes as passes \n", - "\n", - "\n", - "# custom_pm = PassManager()\n", - "\n", - "# custom_pm.append(passes.Optimize1qGatesDecomposition())\n", - "\n", - "# custom_pm.append(passes.Collect2qBlocks())\n", - "# custom_pm.append(passes.ConsolidateBlocks())\n", - "\n", - "# # custom_pm.append(passes.Decompose())\n", - "# # custom_pm.append(passes.Optimize1qGates())\n", - "\n", - "# custom_qc = custom_pm.run(qc)\n", - "\n", - "# # Get gate counts\n", - "# gate_counts = custom_qc.count_ops()\n", - "# print(gate_counts)\n", - "\n", - "# # custom_qc.draw()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# # Get gate counts\n", - "# gate_counts = custom_qc.count_ops()\n", - "# print(gate_counts)\n", - "# print(\"Number of 2-qubit gates: \", gate_counts.get(\"cz\", 0) + gate_counts.get(\"cx\", 0))\n", - "# print(\"Number of 1-qubit gates: \", gate_counts.get(\"sx\", 0) + gate_counts.get(\"rz\", 0) + gate_counts.get(\"x\", 0))\n" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "qml", - "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.4" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/custom_compiler_experiments/custom_compile_qcnn.ipynb b/custom_compiler_experiments/custom_compile_qcnn.ipynb deleted file mode 100644 index 10a8ff34..00000000 --- a/custom_compiler_experiments/custom_compile_qcnn.ipynb +++ /dev/null @@ -1,226 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Quantum Convolutional Neural Network" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "This is a circuit that requires a connectivity map where the distance between the qubits increases exponentially with depth" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from qiskit import QuantumCircuit\n", - "\n", - "import time\n", - "import numpy as np" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Define QCNN circuit" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "num_qubits = 4\n", - "num_layers = int(np.ceil(np.log2(num_qubits)))\n", - "\n", - "qc=QuantumCircuit(num_qubits)\n", - "i_conv=0\n", - "for i_layer in range(num_layers):\n", - " for i_sub_layer in [0 , 2**i_layer]: \n", - " for i_q1 in range(i_sub_layer, num_qubits, 2**(i_layer+1)):\n", - " i_q2=2**i_layer+i_q1\n", - " if i_q2