# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # 1.1 Exercise 1 - Our first Quantum Program: Hello Quantum World

# ---
# ## 1.1.0 Import of libraries for the program

# Full import of Qiskit library
from qiskit import *

# ---
# ## 1.1.1 The Quantum Circuit
# For our first Quantum Program, we will input 2x |0<b>⟩</b> Qubits, then measure the output of the Qubits, which should yield the output: 00.<br>
#
# When we initiate our quantum program, we need three components:<br>
# **Quantum Registers:** Registers which consist of Qubits.<br>
# **Classical Registers:** Registers containing classical bits.<br>
# **Quantum Circuit:** A circuit to setup the experiment.<br>
#
# <strong style="color: orange;">Firstly</strong>, we create a quantum register with 2 Qubits and a classical register with 2 bits and set them into the circuit using the script below:

# +
try:
    # Create a Quantum Register with 2 Qubits.
    qr = QuantumRegister(2)

    # Create a classical register with 2 bits
    cr = ClassicalRegister(2)

    # Create a Quantum Circuit containing our QR and CR. 
    circuit = QuantumCircuit(qr,cr)

    # Prepare the method to draw our quantum program
    circuit.draw();
    
except NameError:
    print("ERROR: You have not run the library import block above correctly\n"*10)
# -

# <div class="alert alert-block alert-warning">
#     <b>Note:</b> When we execute our Quantum Program and measure the Qubits in the end, always reading either 1 or 0, the information is stored in the Classical Register and consequently returned to us as the output of the Quantum Program.
# </div>
#

# ---
# ## 1.1.2 Adding operations to the Quantum Circuit
# <strong style="color: orange;">Secondly</strong>, we add the measurement operations.

# +
# Add a measurement gate here as presented on stage or if you are at home, write "circuit.measure(qr, cr)"
#TODO: ⚠️⚠️⚠️⚠️⚠️ Add a Measurement Operation with two bits here ⚠️⚠️⚠️⚠️⚠️
# -

# ---
# ## 1.1.3 Visualising the Quantum Circuit 
# <strong style="color: orange;">Thirdly</strong>, as we want to view our circuit, we call the circuit.draw() function, which prints the Quantum Register (represented as single lines), the Classical Register (represented as double lines) and all the operations that have been added to the circuit (Which in this case is only measuring operations).

circuit.draw(output='mpl')

# ---
# ## 1.1.4 Run the Quantum Program
# <strong style="color: orange;">Lastly</strong>, to measure the Qubit, we need to run the Quantum Program using a tool from Qiskit called the BasicAer module. From the BasicAer module, we will import a Quantum Simulator, which simulates how our Quantum Computer would process the Quantum Program. *(Don't worry: The real thing comes later)*

# +
# Load the backend to run our Quantum Program
backend = BasicAer.get_backend('statevector_simulator')

# Execute the Quantum Program
job = qiskit.execute(circuit, backend)

# Get the results from the job
result = job.result()

# Print the result
result.get_counts(circuit)
# -

# ---
# ## Extra: Online IBM Q Composer 
# IBM Offers an interactive tool online, which can be seen below.<br> 
# It too has a Quantum Register with Qubits in it (q[0], q[1]) and a Classical Register that stores the measured values (the bottom line with a "c" in front of it).
#
# To the right of the cuircuit you may notice some colorful boxes with letters in them, these are Quantum Gates which containes one specific operation each that can be applied to a Qubit by drag-and-drop.

# ![Sk%C3%A6rmbillede%202019-04-01%20kl.%2011.11.59.png](attachment:Sk%C3%A6rmbillede%202019-04-01%20kl.%2011.11.59.png)

# ---
# ## Next Jupyter notebook - Now let's perform some operations on the Qubit!
# [1.2 Exercise - [x]-gate operation on Qubit](1.2%20-%20Gate%20operation%20-%20X-gate.ipynb)

StarcoderdataJupyterScriptsDedupFiltered