<commit_before>{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img src=\"../images/QISKit-c.gif\" alt=\"Note: In order for images to show up in this jupyter notebook you need to select File => Trusted Notebook\" width=\"250 px\" align=\"left\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The latest version of this notebook is available [here.](https://github.com/QISKit/qiskit-tutorial) For more information about how to use the IBM Q experience (QX), see \n",
    "[this](https://quantumexperience.ng.bluemix.net/qstage/#/tutorial?sectionId=c59b3710b928891a142) link.\n",
    "\n",
    "\n",
    "## Running Quantum Examples Using IBM Data Science Experience\n",
    "\n",
    "This example is copied from the original [getting_started.ipynb](https://github.com/QISKit/qiskit-tutorial/blob/master/1_introduction/getting_started.ipynb). It is tweaked (changes in the first code cell), so that it can be directly run using [IBM Data Science Experience](datascience.ibm.com) (IBM DSX). If you want to run other Quantum notebooks using IBM DSX, simply copy the first *code cell* and paste it at the beginning of your *other* notebook.\n",
    "\n",
    "***\n",
    "\n",
    "### About IBM Data Science Experience\n",
    "\n",
    "IBM Data Science Experience (IBM DSX) is an interactive, collaborative, cloud-based environment where data scientists can use multiple tools to activate their insights.  \n",
    "\n",
    "If you just starting with QISkit and looking for a webhosted Jupyter notebook environment, IBM DSX is an excellent option. It is fairly easy to get your quantum notebook running in the Jupyter notebook environment provided by IBM DSX. Moreover, it provides a platform where you can create your Quantum notebooks, invite fellow researchers to collaborate or simply share your work within the community.\n",
    "\n",
    "\n",
    "\n",
    "### What you need to do\n",
    "\n",
    "This example illustrates how to tweak your notebook so that it is ready to be run using IBM DSX. \n",
    "\n",
    "* In the first code cell, make sure to update the value of **`QX_API_token`** See the heading below that instructs how to get this information. \n",
    "* To run any other Quantum experience notebooks in IBM  DSX, just copy the first *code cell* of this notebook and paste it as the first *code cell* of your '*other*' notebook then just run it. \n",
    "\n",
    "\n",
    "### Getting your API token\n",
    "\n",
    "The API access token allows you to connect to the IBM Quantum Experience API.  Here is how you can obtain this personal API access token.\n",
    "\n",
    "1. If you do not have an account for [IBM Q experience](https://quantumexperience.ng.bluemix.net) yet, sign up for one by following the instructions . \n",
    "2. Login to [IBM Q experience](https://quantumexperience.ng.bluemix.net).\n",
    "3. Click on your username that is displayed near the top right corner, and select *My Account*\n",
    "4. The *My Account* page has a section called *Personal Access Token* . Just copy the token displayed there. \n",
    "5. Update the value of **`QX_API_TOKEN`** in the first code cell with this API token you just copied in previous step.\n",
    "  \n",
    "\n",
    "### Credits and Contributions\n",
    "1. <NAME>, <NAME>, <NAME>. See: [getting_started.ipynb](https://github.com/QISKit/qiskit-tutorial/blob/master/1_introduction/getting_started.ipynb).\n",
    "2. See this [public gist](https://gist.github.com/dtmcclure/a1299fc99d12f5dc37ad6400fb8bbf2a) which has been used as a reference while preparing this notebook. (Github user [dtmcclure](https://github.com/dtmcclure) ) \n",
    "3. <NAME> (code changes for running the notebook on IBM Data Science Experience)\n",
    "\n",
    "## The 'first code cell' follows (customization for IBM DSX):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# This cell does some preparatory work to run this Jupyter notebook using \n",
    "# IBM Data Science Experience (datascience.ibm.com). All the other cells remain the same as in the original example. \n",
    "\n",
    "# --------------------------------------------------------------------------------------------------\n",
    "# IMPORTANT: Log on to your QX account and get your API token. You can get it from the Accounts page \n",
    "# (the top-right icon on QX website) Copy-Paste the API token below.BE SURE TO ENCLOSE IN QUOTES (\"\")\n",
    "# --------------------------------------------------------------------------------------------------\n",
    "QX_API_TOKEN = \"PUT_YOUR_API_TOKEN_HERE\"\n",
    "\n",
    "import sys\n",
    "import os\n",
    "\n",
    "try:\n",
    "    assert(sys.version_info.major > 2)\n",
    "except AssertionError:          \n",
    "    print(\"This code requires Python 3.x. Your version: {}.{}\".format(sys.version_info.major,sys.version_info.minor))\n",
    "    raise\n",
    "\n",
    "# DO NOT CHANGE THE FOLLOWING assertion\n",
    "try:\n",
    "    assert(QX_API_TOKEN != \"PUT_YOUR_API_TOKEN_HERE\")\n",
    "except AssertionError:\n",
    "    print(\"Update the value of QX_API_TOKEN first!\")\n",
    "    raise\n",
    "    \n",
    "# importlib.reload is used to reload the Qconfig module. Fixes any update problems with Qconfig.APItoken \n",
    "import importlib\n",
    "\n",
    "# We need visibility to Qconfig.py module add current dir your sys.path\n",
    "sys.path.append(\"./\")\n",
    "\n",
    "# Install qiskit package\n",
    "!pip install qiskit\n",
    "!rm -rf Qconfig.py \n",
    "!touch Qconfig.py\n",
    "\n",
    "apitoken_str = 'APItoken=\\\"{}\\\"'.format(QX_API_TOKEN)\n",
    "config_str = \"config = { \\\"url\\\": 'https://quantumexperience.ng.bluemix.net/api'}\"\n",
    "\n",
    "with open('Qconfig.py', 'w') as fil:\n",
    "    fil.write(apitoken_str + \"\\n\")\n",
    "    fil.write(config_str + \"\\n\")\n",
    "    \n",
    "# Now import the required modules\n",
    "from qiskit import QuantumProgram\n",
    "import Qconfig\n",
    "\n",
    "try:\n",
    "    # Reload Qconfig module again to make sure the APItoken is updated\n",
    "    importlib.reload(Qconfig)\n",
    "except NameError as e:\n",
    "    print(\"Name error: \", e.args)\n",
    "except:\n",
    "    print(\"unable to reload the module, continuing the execution..\")\n",
    "    \n",
    "print(\"Qconfig.APItoken = \", Qconfig.APItoken)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Basic Concept\n",
    "\n",
    "The basic concept of our quantum program is an array of quantum circuits. The program workflow consists of three stages: [Build](#sectionB), [Compile](#sectionC), and [Run](#sectionR). Build allows you to make different quantum circuits that represent the problem you are solving; Compile allows you to rewrite them to run on different backends (simulators/real chips of different [quantum volumes](http://ibm.biz/qiskit-quantum-volume), sizes, fidelity, etc); and Run launches the jobs.  After the jobs have been run, the data is collected. There are methods for putting this data together, depending on the program. This either gives you the answer you wanted, or allows you to make a better program for the next instance.\n",<commit_msg>further improvements to the qx using dsx tutorial<commit_after>{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img src=\"../images/QISKit-c.gif\" alt=\"Note: In order for images to show up in this jupyter notebook you need to select File => Trusted Notebook\" width=\"250 px\" align=\"left\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The latest version of this notebook is available [here.](https://github.com/QISKit/qiskit-tutorial) For more information about how to use the IBM Q experience (QX), see \n",
    "[this](https://quantumexperience.ng.bluemix.net/qstage/#/tutorial?sectionId=c59b3710b928891a142) link.\n",
    "\n",
    "\n",
    "## Running Quantum Examples Using IBM Data Science Experience\n",
    "\n",
    "This example is copied from the original [getting_started.ipynb](https://github.com/QISKit/qiskit-tutorial/blob/master/1_introduction/getting_started.ipynb). It is tweaked (changes in the first code cell), so that it can be directly run using [IBM Data Science Experience](datascience.ibm.com) (IBM DSX). If you want to run other Quantum notebooks using IBM DSX, simply copy the first *code cell* and paste it at the beginning of your *other* notebook.\n",
    "\n",
    "***\n",
    "\n",
    "### About IBM Data Science Experience\n",
    "\n",
    "IBM Data Science Experience (IBM DSX) is an interactive, collaborative, cloud-based environment where data scientists can use multiple tools to activate their insights.  \n",
    "\n",
    "If you just starting with QISkit and looking for a webhosted Jupyter notebook environment, IBM DSX is an excellent option. It is fairly easy to get your quantum notebook running in the Jupyter notebook environment provided by IBM DSX. Moreover, it provides a platform where you can create your Quantum notebooks, invite fellow researchers to collaborate or simply share your work within the community.\n",
    "\n",
    "\n",
    "\n",
    "### What you need to do\n",
    "\n",
    "This example illustrates how to tweak your notebook so that it is ready to be run using IBM DSX. \n",
    "\n",
    "* In the first code cell, make sure to update the value of **`QX_API_token`** See the heading below that instructs how to get this information. \n",
    "* To run any other Quantum experience notebooks in IBM  DSX, just copy the first *code cell* of this notebook and paste it as the first *code cell* of your '*other*' notebook then just run it. \n",
    "\n",
    "\n",
    "### Getting your API token\n",
    "\n",
    "The API access token allows you to connect to the IBM Quantum Experience API.  Here is how you can obtain this personal API access token.\n",
    "\n",
    "1. If you do not have an account for [IBM Q experience](https://quantumexperience.ng.bluemix.net) yet, sign up for one by following the instructions . \n",
    "2. Login to [IBM Q experience](https://quantumexperience.ng.bluemix.net).\n",
    "3. Click on your username that is displayed near the top right corner, and select *My Account*\n",
    "4. The *My Account* page has a section called *Personal Access Token* . Just copy the token displayed there. \n",
    "5. Update the value of **`QX_API_TOKEN`** in the first code cell with this API token you just copied in previous step.\n",
    "  \n",
    "\n",
    "### Credits and Contributions\n",
    "1. <NAME>, <NAME>, <NAME>. See: [getting_started.ipynb](https://github.com/QISKit/qiskit-tutorial/blob/master/1_introduction/getting_started.ipynb).\n",
    "2. See this [public gist](https://gist.github.com/dtmcclure/a1299fc99d12f5dc37ad6400fb8bbf2a) which has been used as a reference while preparing this notebook. (Github user [dtmcclure](https://github.com/dtmcclure) ) \n",
    "3. <NAME> (code changes for running the notebook on IBM Data Science Experience)\n",
    "\n",
    "## The 'first code cell' follows (customization for IBM DSX):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# This cell does some preparatory work to run this Jupyter notebook using \n",
    "# IBM Data Science Experience (datascience.ibm.com). All the other cells remain the same as in the original example. \n",
    "\n",
    "# --------------------------------------------------------------------------------------------------\n",
    "# IMPORTANT NOTES: \n",
    "# 1) Log on to your QX account and get your API token. You can get it from the Accounts page \n",
    "# (the top-right icon on QX website) Copy-Paste the API token below.BE SURE TO ENCLOSE IN QUOTES (\"\")\n",
    "# 2) If you are sharing this notebook, MAKE SURE TO REMOVE the API token string before sharing! \n",
    "#   Alternatively, you can modify the code below and separately create and save Qconfig.py file with \n",
    "#   API token.\n",
    "# --------------------------------------------------------------------------------------------------\n",
    "QX_API_TOKEN = \"PUT_YOUR_API_TOKEN_HERE\"\n",
    "\n",
    "import sys\n",
    "import os\n",
    "\n",
    "try:\n",
    "    assert(sys.version_info.major > 2)\n",
    "except AssertionError:          \n",
    "    print(\"This code requires Python 3.5 or beyond. Your version: {}.{}\".format(sys.version_info.major,sys.version_info.minor))\n",
    "    raise\n",
    "\n",
    "# DO NOT CHANGE THE FOLLOWING assertion\n",
    "try:\n",
    "    assert(QX_API_TOKEN != \"PUT_YOUR_API_TOKEN_HERE\")\n",
    "except AssertionError:\n",
    "    print(\"Update the value of QX_API_TOKEN first!\")\n",
    "    raise\n",
    "    \n",
    "# importlib.reload is used to reload the Qconfig module. Fixes any update problems with Qconfig.APItoken \n",
    "import importlib\n",
    "\n",
    "# We need visibility to Qconfig.py module add current dir your sys.path\n",
    "sys.path.append(\"./\")\n",
    "\n",
    "# Install qiskit package\n",
    "!pip install qiskit\n",
    "!rm -rf Qconfig.py \n",
    "!touch Qconfig.py\n",
    "\n",
    "apitoken_str = 'APItoken=\\\"{}\\\"'.format(QX_API_TOKEN)\n",
    "config_str = \"config = { \\\"url\\\": 'https://quantumexperience.ng.bluemix.net/api'}\"\n",
    "\n",
    "with open('Qconfig.py', 'w') as fil:\n",
    "    fil.write(apitoken_str + \"\\n\")\n",
    "    fil.write(config_str + \"\\n\")\n",
    "    \n",
    "# Now import all the modules from qiskit such as QuantumProgram, QuantumCircuit, QuantumRegister etc.\n",
    "# Optionally, you can modify the qiskit import line below to do specific module imports. \n",
    "from qiskit import *\n",
    "import Qconfig\n",
    "\n",
    "try:\n",
    "    # Reload Qconfig module again to make sure the APItoken is updated\n",
    "    importlib.reload(Qconfig)\n",
    "except NameError as e:\n",
    "    print(\"Name error: \", e.args)\n",
    "except:\n",
    "    print(\"unable to reload the module, continuing the execution..\")\n",
    "    \n",
    "print(\"Qconfig.APItoken = \", Qconfig.APItoken)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Basic Concept\n",
    "\n",
    "The basic concept of our quantum program is an array of quantum circuits. The program workflow consists of three stages: [Build](#sectionB), [Compile](#sectionC), and [Run](#sectionR). Build allows you to make different quantum circuits that represent the problem you are solving; Compile allows you to rewrite them to run on different backends (simulators/real chips of different [quantum volumes](http://ibm.biz/qiskit-quantum-volume), sizes, fidelity, etc); and Run launches the jobs.  After the jobs have been run, the data is collected. There are methods for putting this data together, depending on the program. This either gives you the answer you wanted, or allows you to make a better program for the next instance.\n",
{'fraction_non_alphanumeric': 0.1618012828904307, 'fraction_numerical': 0.006348998560020945, 'mean_word_length': 2.8140289565651524, 'pattern_counts': {'":': 34, '<': 13, '<?xml version=': 0, '>': 17, 'https://': 18, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1068219', 'n_tokens_mistral': 4839, 'n_tokens_neox': 4673, 'n_words': 1732}