<jupyter_start><jupyter_text>Build Quantum Circuit<jupyter_code># 2 Qubit Qauntum Register
qr = QuantumRegister(2)
# 2 Classical Register to take measurement from the 2 Quantum Bits above
cr = ClassicalRegister(2)
# Circuit that uses both qr and cr
circuit = QuantumCircuit(qr, cr)<jupyter_output><empty_output><jupyter_text>Visualize the Circuit<jupyter_code>%matplotlib inline
# 2 Quantum Bits (q0) and 2 Classical Bits (c0) in the circuit
circuit.draw()<jupyter_output><empty_output><jupyter_text>Build GatesCreate entaglement<jupyter_code># Apply a Hadamard Gate on the first Qubit
circuit.h(qr[0])
# Better visualization with (output = 'mpl')
circuit.draw(output = 'mpl')<jupyter_output><empty_output><jupyter_text>Two Qubit Operation<jupyter_code># If this Then that
circuit.cx([0], qr[1])  # (Control, Target)
# Circuit is now composed of a Hadamard Gate and a Controlled Node
circuit.draw(output = 'mpl')
# This now creates Entangelement between q0_0 and q0_1<jupyter_output><empty_output><jupyter_text>Measure the QubitsStore them into Classical Bits<jupyter_code># Apply measurement
circuit.measure(qr, cr)
circuit.draw(output = 'mpl')<jupyter_output><empty_output><jupyter_text>Simulate the Circuit<jupyter_code># Aer is what we use when we run simulations on our local computer
simulator = Aer.get_backend('qasm_simulator')  # Quantum Assembly Language
# Executing the circuit using the simulator as a backend
result = execute(circuit, backend = simulator).result()<jupyter_output><empty_output><jupyter_text>Visualize the Result<jupyter_code>from qiskit.tools.visualization import plot_histogram
plot_histogram(result.get_counts(circuit))
# 51.7% probability of getting 00
# 48.3% probability of getting 11
# Small error margin due to running a limited number of shots on our simulation, instead of an infinite number of shots<jupyter_output><empty_output><jupyter_text>Access IBMQ<jupyter_code># Load account
IBMQ.load_account()
# Choose the provider on which to run our code
provider = IBMQ.get_provider('ibm-q')
# The Quantum Computer with which we want to work with
qcomp = provider.get_backend('ibmq_16_melbourne')
job = execute(circuit, backend = qcomp)
# Import job_monitor to queue our job to a real public device at IBM
from qiskit.tools.monitor import job_monitor
job_monitor(job)  # The "Job Status" text below will update in a few minutes
# Once the "Job Status" says "successfully run" then:
result = job.result()
# Visualize the result
plot_histogram(result.get_counts(circuit))
# On a real Quantum device more probabilities can appear, such as 01 and 10 == small Quantum errors can still appear
circuit.draw(output = 'mpl')
circuit.draw()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08568249258160238, 'fraction_numerical': 0.011869436201780416, 'mean_word_length': 6.909090909090909, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, '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}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '131341', 'license': 'Unlicense', 'n_tokens_mistral': 910, 'n_tokens_neox': 842, 'n_words': 278, 'path': 'Qiskit-MyFirstCircuit-v1.ipynb', 'repo_name': 'DavidJKTofan/IBMQ-Qiskit-FirstCircuit', 'size': '2696'}