Skip to content

Commit

Permalink
Added compiler demonstration
Browse files Browse the repository at this point in the history
  • Loading branch information
powerssc committed Oct 19, 2020
1 parent 22442b6 commit 18bba82
Show file tree
Hide file tree
Showing 7 changed files with 453 additions and 11 deletions.
172 changes: 172 additions & 0 deletions examples/.ipynb_checkpoints/Compiler Demonstration-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -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
}
172 changes: 172 additions & 0 deletions examples/Compiler Demonstration.ipynb
Original file line number Diff line number Diff line change
@@ -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
}
Loading

0 comments on commit 18bba82

Please sign in to comment.