<jupyter_start><jupyter_text><jupyter_code>!pip3 install qiskit<jupyter_output>Requirement already satisfied: qiskit in /home/r0x6f736f646f/.local/lib/python3.6/site-packages
Collecting qiskit-aer==0.3.2 (from qiskit)
  Using cached https://files.pythonhosted.org/packages/18/2f/63ee86a48d131f0d6772ed9aba947d2e8457d17408add32c1d0d44822c84/qiskit_aer-0.3.2-cp36-cp36m-manylinux1_x86_64.whl
Collecting qiskit-ibmq-provider==0.3.3 (from qiskit)
Requirement already satisfied: qiskit-ignis==0.2.0 in /home/r0x6f736f646f/.local/lib/python3.6/site-packages (from qiskit)
Collecting qiskit-terra==0.10.0 (from qiskit)
  Using cached https://files.pythonhosted.org/packages/09/97/1be77cc1b22f3bd341024b1bae89d71ca9ee147ac047f793364cadc873a8/qiskit_terra-0.10.0-cp36-cp36m-manylinux1_x86_64.whl
Requirement already satisfied: qiskit-aqua==0.6.1 in /home/r0x6f736f646f/.local/lib/python3.6/site-packages (from qiskit)
Requirement already satisfied: numpy>=1.13 in /home/r0x6f736f646f/.local/lib/python3.6/site-packages (from qiskit-aer==0.3.2->qiskit)
Collecting nest-asyncio==1.0.0 (from[...]<jupyter_text>Getting started with qiskitHere we will get the overview of qiskit and build a fundamental unit of qiskit, quantum circuit.We need to build the execute<jupyter_code>import numpy as np
from qiskit import *
%matplotlib inline
# We create q quantum circuit on a quantum register with 4 qubits
circuit = QuantumCircuit(4)<jupyter_output><empty_output><jupyter_text>We can now add gates to manipulate the register.eg Hadamard, Controlled not<jupyter_code># we have added a Hadamard gate to the first qubit (Superposition)
circuit.h(0)
# we add a CNOT gate on 0 and 1 (Bell state)
circuit.cx(0,1)
# CNOT on 0 and 2
circuit.cx(0,2)
# Lets see what we have made
circuit.draw()<jupyter_output><empty_output><jupyter_text>Note: If you don't have matplotlib set up as your default in '~/.qiskit/settings.conf' it will use a text-based drawer over matplotlib. To set the default to matplotlib, use the following in the settings.conf[default]circuit_drawer = mpl  Simulating circuit using qiskit Aer which provides many backendsWe will use `statevector_simulator` which is the most common which returns quantum states<jupyter_code>from qiskit import Aer

# Run the circuit
backend = Aer.get_backend('statevector_simulator')

#Create execution
job = execute(circuit, backend)
#Monitor our job with
job.status()
# get results
result = job.result()
outputs = result.get_statevector(circuit)
print(outputs)<jupyter_output>[0.70710678+0.j 0.        +0.j 0.        +0.j 0.        +0.j
 0.        +0.j 0.        +0.j 0.        +0.j 0.70710678+0.j
 0.        +0.j 0.        +0.j 0.        +0.j 0.        +0.j
 0.        +0.j 0.        +0.j 0.        +0.j 0.        +0.j]<jupyter_text>OpenQASM backendIt provides information about the state output by the ideal circuit and the matrix representation of the circuit<jupyter_code>circuit1 = QuantumCircuit(3,3)
circuit1.h(0)
circuit1.cx(0,1)
circuit1.cx(1,2)
circuit1.barrier(range(3))
# map quantum measurements to the classical bits
circuit1.measure(range(3), range(3))
circuit1.draw()
backend2 = Aer.get_backend('qasm_simulator')
# we repeate the circuit 2048 times
job2 = execute(circuit1, backend2, shots= 2048)
result2 = job2.result()
from qiskit.visualization import plot_histogram
plot_histogram(result2.get_counts(circuit1))<jupyter_output><empty_output><jupyter_text>Running on IBMQ<jupyter_code>from qiskit import IBMQ<jupyter_output><empty_output><jupyter_text>After generating your API token, call: IBMQ.save_account('MY_TOKEN').This will store your IBM Q credentials in a local file.<jupyter_code>IBMQ.load_account()
IBMQ.providers()
provider = IBMQ.get_provider(group='open')
provider.backends()
backend3 = provider.get_backend('ibmq_16_melbourne')
from qiskit.tools.monitor import job_monitor

job3 = execute(circuit1, backend=backend3)
job_monitor(job3)
result3 = job3.result()
counts3= result3.get_counts(circuit1)
plot_histogram([counts3,result3.get_counts(circuit1)], legend=['Device', 'Simulator'])
backend4 = provider.get_backend('ibmq_qasm_simulator')
job4 = execute(circuit1, backend=backend4)
result4 = job4.result()
counts4 = result4.get_counts(circuit1)
plot_histogram(counts4)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10711768851303735, 'fraction_numerical': 0.06788818416725394, 'mean_word_length': 5.393393393393393, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 29, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '177377', 'license': 'MIT', 'n_tokens_mistral': 1696, 'n_tokens_neox': 1555, 'n_words': 360, 'path': 'QuantumMachineLearning/1quantum_circuits.ipynb', 'repo_name': '0x6f736f646f/AI_LABS', 'size': '4257'}