diff --git a/examples/.ipynb_checkpoints/Compiler Demonstration-checkpoint.ipynb b/examples/.ipynb_checkpoints/Compiler Demonstration-checkpoint.ipynb new file mode 100644 index 0000000..a949a68 --- /dev/null +++ b/examples/.ipynb_checkpoints/Compiler Demonstration-checkpoint.ipynb @@ -0,0 +1,172 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 1) Imports" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "scrolled": false + }, + "outputs": [], + "source": [ + "import sys\n", + "sys.path.insert(1, '/mnt/c/Users/conno/Documents/GitHub/MISTIQS/src')\n", + "\n", + "from Heisenberg import Heisenberg\n", + "from ds_compiler import ds_compile" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 2) Create Heisenberg object\n", + "This object solely takes in your input file, so it contains the information about the system you are simulating and your preferences including backend choice, compilation method, and others." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "ibmqfactory.load_account:WARNING:2020-10-19 01:09:33,143: Credentials are already in use. The existing account in the session will be replaced.\n" + ] + } + ], + "source": [ + "\n", + "#First, create the Heisenberg object using the parameters specified in the input file. This defines the system to simulate\n", + "#and allows for the generation of circuits to simulate the time evolution of this system.\n", + "test_object=Heisenberg(\"compiler_input_file.txt\")\n", + "\n", + "\n", + "\n", + "#Because we are working in the IBM backend in this example, run the connect_IBM() method of the object to connect to IBM's\n", + "#backend. This is required for both compilation and circuit execution, if desired.\n", + "\n", + "#First time user of IBM's Quantum Experience API? Run the line below\n", + "# test_object.connect_IBM(api_key=\"insert your IBM Quantum Experience API key here\")\n", + "\n", + "#If you already run IBM Quantum Experience API jobs, run the following instead:\n", + "test_object.connect_IBM()\n", + "\n", + "\n", + " \n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 3) Generate Quantum Circuits for Quantum Simulation of Your Physical System\n", + "\n", + "Note: any warning messages about gate error values are due to qiskit's noise model building, not MISTIQS" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Generating timestep 0 circuit\n", + "Generating timestep 1 circuit\n", + "Generating timestep 2 circuit\n", + "Generating timestep 3 circuit\n", + "Generating timestep 4 circuit\n", + "Generating timestep 5 circuit\n", + "Generating timestep 6 circuit\n", + "Generating timestep 7 circuit\n", + "Generating timestep 8 circuit\n", + "Generating timestep 9 circuit\n", + "Generating timestep 10 circuit\n", + "Generating timestep 11 circuit\n", + "Generating timestep 12 circuit\n", + "Generating timestep 13 circuit\n", + "Generating timestep 14 circuit\n", + "Generating timestep 15 circuit\n", + "Generating timestep 16 circuit\n", + "Generating timestep 17 circuit\n", + "Generating timestep 18 circuit\n", + "Generating timestep 19 circuit\n", + "Generating timestep 20 circuit\n", + "Generating timestep 21 circuit\n", + "Generating timestep 22 circuit\n", + "Generating timestep 23 circuit\n", + "Generating timestep 24 circuit\n", + "Generating timestep 25 circuit\n", + "Generating timestep 26 circuit\n", + "Generating timestep 27 circuit\n", + "Generating timestep 28 circuit\n", + "Generating timestep 29 circuit\n", + "Generating timestep 30 circuit\n", + "Creating IBM quantum circuit objects...\n", + "IBM quantum circuit objects created\n" + ] + } + ], + "source": [ + "test_object.generate_circuits()\n", + "uncompiled_circuits=test_object.return_circuits()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 4) Run the circuits through the domain-specific quantum compiler" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "scrolled": true + }, + "outputs": [], + "source": [ + "compiled_circuits=[]\n", + "for circuit in uncompiled_circuits:\n", + " compiled_circuits.append(ds_compile(circuit,'ibm'))\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3.8", + "language": "python", + "name": "py38" + }, + "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.8.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/examples/Compiler Demonstration.ipynb b/examples/Compiler Demonstration.ipynb new file mode 100644 index 0000000..a949a68 --- /dev/null +++ b/examples/Compiler Demonstration.ipynb @@ -0,0 +1,172 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 1) Imports" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "scrolled": false + }, + "outputs": [], + "source": [ + "import sys\n", + "sys.path.insert(1, '/mnt/c/Users/conno/Documents/GitHub/MISTIQS/src')\n", + "\n", + "from Heisenberg import Heisenberg\n", + "from ds_compiler import ds_compile" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 2) Create Heisenberg object\n", + "This object solely takes in your input file, so it contains the information about the system you are simulating and your preferences including backend choice, compilation method, and others." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "ibmqfactory.load_account:WARNING:2020-10-19 01:09:33,143: Credentials are already in use. The existing account in the session will be replaced.\n" + ] + } + ], + "source": [ + "\n", + "#First, create the Heisenberg object using the parameters specified in the input file. This defines the system to simulate\n", + "#and allows for the generation of circuits to simulate the time evolution of this system.\n", + "test_object=Heisenberg(\"compiler_input_file.txt\")\n", + "\n", + "\n", + "\n", + "#Because we are working in the IBM backend in this example, run the connect_IBM() method of the object to connect to IBM's\n", + "#backend. This is required for both compilation and circuit execution, if desired.\n", + "\n", + "#First time user of IBM's Quantum Experience API? Run the line below\n", + "# test_object.connect_IBM(api_key=\"insert your IBM Quantum Experience API key here\")\n", + "\n", + "#If you already run IBM Quantum Experience API jobs, run the following instead:\n", + "test_object.connect_IBM()\n", + "\n", + "\n", + " \n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 3) Generate Quantum Circuits for Quantum Simulation of Your Physical System\n", + "\n", + "Note: any warning messages about gate error values are due to qiskit's noise model building, not MISTIQS" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Generating timestep 0 circuit\n", + "Generating timestep 1 circuit\n", + "Generating timestep 2 circuit\n", + "Generating timestep 3 circuit\n", + "Generating timestep 4 circuit\n", + "Generating timestep 5 circuit\n", + "Generating timestep 6 circuit\n", + "Generating timestep 7 circuit\n", + "Generating timestep 8 circuit\n", + "Generating timestep 9 circuit\n", + "Generating timestep 10 circuit\n", + "Generating timestep 11 circuit\n", + "Generating timestep 12 circuit\n", + "Generating timestep 13 circuit\n", + "Generating timestep 14 circuit\n", + "Generating timestep 15 circuit\n", + "Generating timestep 16 circuit\n", + "Generating timestep 17 circuit\n", + "Generating timestep 18 circuit\n", + "Generating timestep 19 circuit\n", + "Generating timestep 20 circuit\n", + "Generating timestep 21 circuit\n", + "Generating timestep 22 circuit\n", + "Generating timestep 23 circuit\n", + "Generating timestep 24 circuit\n", + "Generating timestep 25 circuit\n", + "Generating timestep 26 circuit\n", + "Generating timestep 27 circuit\n", + "Generating timestep 28 circuit\n", + "Generating timestep 29 circuit\n", + "Generating timestep 30 circuit\n", + "Creating IBM quantum circuit objects...\n", + "IBM quantum circuit objects created\n" + ] + } + ], + "source": [ + "test_object.generate_circuits()\n", + "uncompiled_circuits=test_object.return_circuits()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 4) Run the circuits through the domain-specific quantum compiler" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "scrolled": true + }, + "outputs": [], + "source": [ + "compiled_circuits=[]\n", + "for circuit in uncompiled_circuits:\n", + " compiled_circuits.append(ds_compile(circuit,'ibm'))\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3.8", + "language": "python", + "name": "py38" + }, + "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.8.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/examples/Domain Wall Quench Demonstration.ipynb b/examples/Domain Wall Quench Demonstration.ipynb index 7036f6d..4667226 100644 --- a/examples/Domain Wall Quench Demonstration.ipynb +++ b/examples/Domain Wall Quench Demonstration.ipynb @@ -31,7 +31,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 2, "metadata": { "scrolled": true }, @@ -77,7 +77,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 3, "metadata": { "scrolled": true }, @@ -107,6 +107,36 @@ "Generating timestep 18 circuit\n", "Generating timestep 19 circuit\n", "Generating timestep 20 circuit\n", + "Generating timestep 21 circuit\n", + "Generating timestep 22 circuit\n", + "Generating timestep 23 circuit\n", + "Generating timestep 24 circuit\n", + "Generating timestep 25 circuit\n", + "Generating timestep 26 circuit\n", + "Generating timestep 27 circuit\n", + "Generating timestep 28 circuit\n", + "Generating timestep 29 circuit\n", + "Generating timestep 30 circuit\n", + "Generating timestep 31 circuit\n", + "Generating timestep 32 circuit\n", + "Generating timestep 33 circuit\n", + "Generating timestep 34 circuit\n", + "Generating timestep 35 circuit\n", + "Generating timestep 36 circuit\n", + "Generating timestep 37 circuit\n", + "Generating timestep 38 circuit\n", + "Generating timestep 39 circuit\n", + "Generating timestep 40 circuit\n", + "Generating timestep 41 circuit\n", + "Generating timestep 42 circuit\n", + "Generating timestep 43 circuit\n", + "Generating timestep 44 circuit\n", + "Generating timestep 45 circuit\n", + "Generating timestep 46 circuit\n", + "Generating timestep 47 circuit\n", + "Generating timestep 48 circuit\n", + "Generating timestep 49 circuit\n", + "Generating timestep 50 circuit\n", "Creating IBM quantum circuit objects...\n", "IBM quantum circuit objects created\n", "Transpiling circuits...\n", @@ -127,7 +157,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 4, "metadata": {}, "outputs": [ { diff --git a/examples/compiler_input_file.txt b/examples/compiler_input_file.txt new file mode 100644 index 0000000..e661570 --- /dev/null +++ b/examples/compiler_input_file.txt @@ -0,0 +1,49 @@ +*JZ +0.01183898 + + +*h_ext +0.01183898 + +*ext_dir +X + +#any desired comments + +*initial_spins +1,1,1,1 + + +*delta_t +3 + + +*steps +30 + + +*shots +1024 + + +*num_qubits +4 + + +*device +ibmq_16_melbourne + +*backend +ibm + +*QCQS +QS + +*time_dep_flag +y + +*auto_ds_compile +n + +*compile +n \ No newline at end of file diff --git a/examples/domain_wall_input_file.txt b/examples/domain_wall_input_file.txt index 7b7180b..47da8c9 100644 --- a/examples/domain_wall_input_file.txt +++ b/examples/domain_wall_input_file.txt @@ -18,7 +18,7 @@ *steps -20 +50 *shots diff --git a/src/Heisenberg.py b/src/Heisenberg.py index 5d1af0a..a72bcd4 100644 --- a/src/Heisenberg.py +++ b/src/Heisenberg.py @@ -10,7 +10,7 @@ #Create data directory current=os.getcwd() newdir="data" -path = os.path.join(current, newdir) +path = os.path.join(current, newdir) if not os.path.isdir(path): os.makedirs(path) @@ -585,10 +585,20 @@ def run_circuits(self): # time_vec=np.linspace(0,total_t,steps) # time_vec=time_vec*JX/H_BAR if "y" in self.plot_flag: - plt.figure() + fig, ax = plt.subplots() plt.plot(range(self.steps+1), avg_mag_sim[0]) - plt.xlabel("Simulation Timestep") - plt.ylabel("Average Magnetization") + plt.xlabel("Simulation Timestep",fontsize=14) + plt.ylabel("Average Magnetization",fontsize=14) + plt.tight_layout() + every_nth = 2 + for n, label in enumerate(ax.xaxis.get_ticklabels()): + if (n+1) % every_nth != 0: + label.set_visible(False) + every_nth = 2 + for n, label in enumerate(ax.yaxis.get_ticklabels()): + if (n+1) % every_nth != 0: + label.set_visible(False) + # plt.yticks(np.arange(-1, 1, step=0.2)) # Set label locations. plt.savefig("data/Simulator_result_qubit{}.png".format(j+1)) plt.close() self.result_out_list.append(avg_mag_sim[0]) @@ -619,10 +629,19 @@ def run_circuits(self): # QC if "y" in self.plot_flag: - plt.figure() + fig, ax = plt.subplots() plt.plot(range(self.steps+1), avg_mag_qc[0]) - plt.xlabel("Simulation Timestep") - plt.ylabel("Average Magnetization") + plt.xlabel("Simulation Timestep",fontsize=14) + plt.ylabel("Average Magnetization",fontsize=14) + plt.tight_layout() + every_nth = 2 + for n, label in enumerate(ax.xaxis.get_ticklabels()): + if (n+1) % every_nth != 0: + label.set_visible(False) + every_nth = 2 + for n, label in enumerate(ax.yaxis.get_ticklabels()): + if (n+1) % every_nth != 0: + label.set_visible(False) plt.savefig("data/QC_result_qubit{}.png".format(j+1)) plt.close() self.result_out_list.append(avg_mag_qc[0]) diff --git a/src/__pycache__/Heisenberg.cpython-38.pyc b/src/__pycache__/Heisenberg.cpython-38.pyc index cef9187..fa5e6d9 100644 Binary files a/src/__pycache__/Heisenberg.cpython-38.pyc and b/src/__pycache__/Heisenberg.cpython-38.pyc differ