|
@@ -0,0 +1,119 @@
|
|
|
|
+{
|
|
|
|
+ "cells": [
|
|
|
|
+ {
|
|
|
|
+ "cell_type": "code",
|
|
|
|
+ "execution_count": 5,
|
|
|
|
+ "metadata": {},
|
|
|
|
+ "outputs": [],
|
|
|
|
+ "source": [
|
|
|
|
+ "%matplotlib inline\n",
|
|
|
|
+ "\n",
|
|
|
|
+ "import matplotlib.pyplot as plt\n",
|
|
|
|
+ "from IPython.display import set_matplotlib_formats\n",
|
|
|
|
+ "import numpy as np\n",
|
|
|
|
+ "import qcgpu\n",
|
|
|
|
+ "\n",
|
|
|
|
+ "set_matplotlib_formats('png', 'pdf')\n",
|
|
|
|
+ "plt.style.use('ggplot')"
|
|
|
|
+ ]
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ "cell_type": "code",
|
|
|
|
+ "execution_count": 6,
|
|
|
|
+ "metadata": {},
|
|
|
|
+ "outputs": [],
|
|
|
|
+ "source": [
|
|
|
|
+ "def plot_state(state):\n",
|
|
|
|
+ " labels = map(\n",
|
|
|
|
+ " lambda i: np.binary_repr(i, state.num_qubits), \n",
|
|
|
|
+ " range(0, 2**state.num_qubits)\n",
|
|
|
|
+ " )\n",
|
|
|
|
+ "\n",
|
|
|
|
+ " y_pos = np.arange(len(labels))\n",
|
|
|
|
+ " performance = list(state.probabilities())\n",
|
|
|
|
+ " \n",
|
|
|
|
+ " plt.bar(y_pos, performance, align='center')\n",
|
|
|
|
+ " plt.xticks(y_pos, labels)\n",
|
|
|
|
+ " plt.ylabel('Amplitude')\n",
|
|
|
|
+ " plt.title('Probability Amplitudes')\n",
|
|
|
|
+ "\n",
|
|
|
|
+ " plt.show()"
|
|
|
|
+ ]
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ "cell_type": "code",
|
|
|
|
+ "execution_count": 9,
|
|
|
|
+ "metadata": {},
|
|
|
|
+ "outputs": [
|
|
|
|
+ {
|
|
|
|
+ "data": {
|
|
|
|
+ "text/plain": [
|
|
|
|
+ "20"
|
|
|
|
+ ]
|
|
|
|
+ },
|
|
|
|
+ "execution_count": 9,
|
|
|
|
+ "metadata": {},
|
|
|
|
+ "output_type": "execute_result"
|
|
|
|
+ }
|
|
|
|
+ ],
|
|
|
|
+ "source": [
|
|
|
|
+ "h = qcgpu.gate.h()\n",
|
|
|
|
+ "x = qcgpu.gate.x()\n",
|
|
|
|
+ "s = qcgpu.gate.s()\n",
|
|
|
|
+ "t = qcgpu.gate.t()\n",
|
|
|
|
+ "y = qcgpu.gate.y()\n",
|
|
|
|
+ "z = qcgpu.gate.z()\n",
|
|
|
|
+ "\n",
|
|
|
|
+ "# Random Circuit\n",
|
|
|
|
+ "state = qcgpu.State(18)\n",
|
|
|
|
+ "\n",
|
|
|
|
+ "state.apply_gate(h, 0)\n",
|
|
|
|
+ "state.apply_gate(t, 0)\n",
|
|
|
|
+ "state.apply_gate(y, 0)\n",
|
|
|
|
+ "state.apply_gate(z, 0)\n",
|
|
|
|
+ "state.apply_gate(h, 0)\n",
|
|
|
|
+ "\n",
|
|
|
|
+ "state.num_qubits"
|
|
|
|
+ ]
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ "cell_type": "code",
|
|
|
|
+ "execution_count": null,
|
|
|
|
+ "metadata": {
|
|
|
|
+ "scrolled": true
|
|
|
|
+ },
|
|
|
|
+ "outputs": [],
|
|
|
|
+ "source": [
|
|
|
|
+ "plot_state(state)"
|
|
|
|
+ ]
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ "cell_type": "code",
|
|
|
|
+ "execution_count": null,
|
|
|
|
+ "metadata": {},
|
|
|
|
+ "outputs": [],
|
|
|
|
+ "source": []
|
|
|
|
+ }
|
|
|
|
+ ],
|
|
|
|
+ "metadata": {
|
|
|
|
+ "kernelspec": {
|
|
|
|
+ "display_name": "Python 2",
|
|
|
|
+ "language": "python",
|
|
|
|
+ "name": "python2"
|
|
|
|
+ },
|
|
|
|
+ "language_info": {
|
|
|
|
+ "codemirror_mode": {
|
|
|
|
+ "name": "ipython",
|
|
|
|
+ "version": 2
|
|
|
|
+ },
|
|
|
|
+ "file_extension": ".py",
|
|
|
|
+ "mimetype": "text/x-python",
|
|
|
|
+ "name": "python",
|
|
|
|
+ "nbconvert_exporter": "python",
|
|
|
|
+ "pygments_lexer": "ipython2",
|
|
|
|
+ "version": "2.7.15rc1"
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ "nbformat": 4,
|
|
|
|
+ "nbformat_minor": 2
|
|
|
|
+}
|