|
@@ -1,188 +0,0 @@
|
|
|
-{
|
|
|
- "cells": [
|
|
|
- {
|
|
|
- "cell_type": "code",
|
|
|
- "execution_count": 1,
|
|
|
- "metadata": {},
|
|
|
- "outputs": [],
|
|
|
- "source": [
|
|
|
- "import sys\n",
|
|
|
- "import time\n",
|
|
|
- "import pandas as pd\n",
|
|
|
- "import numpy as np\n",
|
|
|
- "\n",
|
|
|
- "# QCGPU Imports\n",
|
|
|
- "import qcgpu\n",
|
|
|
- "\n",
|
|
|
- "# ProjectQ Imports\n",
|
|
|
- "from projectq import MainEngine\n",
|
|
|
- "import projectq.ops as ops\n",
|
|
|
- "from projectq.backends import Simulator\n",
|
|
|
- "from projectq.types import Qureg\n",
|
|
|
- "\n",
|
|
|
- "# Qiskit Imports\n",
|
|
|
- "from qiskit import ClassicalRegister, QuantumRegister\n",
|
|
|
- "from qiskit import QuantumCircuit, execute"
|
|
|
- ]
|
|
|
- },
|
|
|
- {
|
|
|
- "cell_type": "code",
|
|
|
- "execution_count": 2,
|
|
|
- "metadata": {},
|
|
|
- "outputs": [],
|
|
|
- "source": [
|
|
|
- "def bench_qcgpu(n, depth):\n",
|
|
|
- " state = qcgpu.State(n)\n",
|
|
|
- "\n",
|
|
|
- " h = qcgpu.gate.h()\n",
|
|
|
- " x = qcgpu.gate.x()\n",
|
|
|
- " t = qcgpu.gate.t()\n",
|
|
|
- "\n",
|
|
|
- " start = time.time()\n",
|
|
|
- "\n",
|
|
|
- " for level in range(depth):\n",
|
|
|
- " for q in range(n):\n",
|
|
|
- " \n",
|
|
|
- " state.apply_gate(h, q)\n",
|
|
|
- " state.apply_gate(t, q)\n",
|
|
|
- "\n",
|
|
|
- " if q != 0:\n",
|
|
|
- " state.apply_controlled_gate(x, q, 0)\n",
|
|
|
- " \n",
|
|
|
- " runtime = time.time() - start\n",
|
|
|
- " return runtime\n",
|
|
|
- " \n",
|
|
|
- "def bench_projectq(n, depth):\n",
|
|
|
- " eng = MainEngine(backend=Simulator(gate_fusion=True), engine_list=[])\n",
|
|
|
- " qbits = eng.allocate_qureg(n)\n",
|
|
|
- "\n",
|
|
|
- " start = time.time()\n",
|
|
|
- "\n",
|
|
|
- " for level in range(depth):\n",
|
|
|
- " for q in qbits:\n",
|
|
|
- " ops.H | q\n",
|
|
|
- " ops.T | q\n",
|
|
|
- " if q != qbits[0]:\n",
|
|
|
- " ops.CNOT | (q, qbits[0])\n",
|
|
|
- "\n",
|
|
|
- " runtime = time.time() - start\n",
|
|
|
- "\n",
|
|
|
- " for q in qbits:\n",
|
|
|
- " ops.Measure | q\n",
|
|
|
- " eng.flush()\n",
|
|
|
- " return runtime\n",
|
|
|
- "\n",
|
|
|
- "def bench_qiskit(n, depth):\n",
|
|
|
- " q = QuantumRegister(n)\n",
|
|
|
- " c = ClassicalRegister(n)\n",
|
|
|
- " qc = QuantumCircuit(q, c)\n",
|
|
|
- "\n",
|
|
|
- " \n",
|
|
|
- " \n",
|
|
|
- " for level in range(depth):\n",
|
|
|
- " for i in range(n):\n",
|
|
|
- " qc.h(q[i])\n",
|
|
|
- " qc.t(q[i])\n",
|
|
|
- "\n",
|
|
|
- " if i != 0:\n",
|
|
|
- " qc.cx(q[i], q[0])\n",
|
|
|
- "\n",
|
|
|
- " start = time.time()\n",
|
|
|
- " \n",
|
|
|
- " job_sim = execute(qc, \"local_statevector_simulator\")\n",
|
|
|
- " job_sim.result()\n",
|
|
|
- " \n",
|
|
|
- " runtime = time.time() - start\n",
|
|
|
- " return runtime\n"
|
|
|
- ]
|
|
|
- },
|
|
|
- {
|
|
|
- "cell_type": "code",
|
|
|
- "execution_count": 3,
|
|
|
- "metadata": {},
|
|
|
- "outputs": [
|
|
|
- {
|
|
|
- "data": {
|
|
|
- "text/plain": [
|
|
|
- "0.016415119171142578"
|
|
|
- ]
|
|
|
- },
|
|
|
- "execution_count": 3,
|
|
|
- "metadata": {},
|
|
|
- "output_type": "execute_result"
|
|
|
- }
|
|
|
- ],
|
|
|
- "source": [
|
|
|
- "bench_qcgpu(20,3)"
|
|
|
- ]
|
|
|
- },
|
|
|
- {
|
|
|
- "cell_type": "code",
|
|
|
- "execution_count": 4,
|
|
|
- "metadata": {},
|
|
|
- "outputs": [
|
|
|
- {
|
|
|
- "data": {
|
|
|
- "text/plain": [
|
|
|
- "0.20844078063964844"
|
|
|
- ]
|
|
|
- },
|
|
|
- "execution_count": 4,
|
|
|
- "metadata": {},
|
|
|
- "output_type": "execute_result"
|
|
|
- }
|
|
|
- ],
|
|
|
- "source": [
|
|
|
- "bench_projectq(20,3)"
|
|
|
- ]
|
|
|
- },
|
|
|
- {
|
|
|
- "cell_type": "code",
|
|
|
- "execution_count": 5,
|
|
|
- "metadata": {},
|
|
|
- "outputs": [
|
|
|
- {
|
|
|
- "data": {
|
|
|
- "text/plain": [
|
|
|
- "2.865260124206543"
|
|
|
- ]
|
|
|
- },
|
|
|
- "execution_count": 5,
|
|
|
- "metadata": {},
|
|
|
- "output_type": "execute_result"
|
|
|
- }
|
|
|
- ],
|
|
|
- "source": [
|
|
|
- "bench_qiskit(20,3)"
|
|
|
- ]
|
|
|
- },
|
|
|
- {
|
|
|
- "cell_type": "code",
|
|
|
- "execution_count": null,
|
|
|
- "metadata": {},
|
|
|
- "outputs": [],
|
|
|
- "source": []
|
|
|
- }
|
|
|
- ],
|
|
|
- "metadata": {
|
|
|
- "kernelspec": {
|
|
|
- "display_name": "Python 3",
|
|
|
- "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.6.6"
|
|
|
- }
|
|
|
- },
|
|
|
- "nbformat": 4,
|
|
|
- "nbformat_minor": 2
|
|
|
-}
|