<jupyter_start><jupyter_text>prepared by <NAME> (<EMAIL>) | November 07, 2018 I have some macros here. If there is a problem with displaying mathematical formulas, please run me to load these macros.$ \newcommand{\bra}[1]{\langle 1|} $$ \newcommand{\ket}[1]{|1\rangle} $$ \newcommand{\braket}[2]{\langle 1|2\rangle} $$ \newcommand{\inner}[2]{\langle 1,2\rangle} $$ \newcommand{\biginner}[2]{\left\langle 1,2\right\rangle} $$ \newcommand{\mymatrix}[2]{\left( \begin{array}{1} 2\end{array} \right)} $$ \newcommand{\myvector}[1]{\mymatrix{c}{1}} $$ \newcommand{\myrvector}[1]{\mymatrix{r}{1}} $$ \newcommand{\mypar}[1]{\left( 1 \right)} $$ \newcommand{\mybigpar}[1]{ \Big( 1 \Big)} $$ \newcommand{\sqrttwo}{\frac{1}{\sqrt{2}}} $$ \newcommand{\dsqrttwo}{\dfrac{1}{\sqrt{2}}} $$ \newcommand{\onehalf}{\frac{1}{2}} $$ \newcommand{\donehalf}{\dfrac{1}{2}} $$ \newcommand{\hadamard}{ \mymatrix{rr}{ \sqrttwo & \sqrttwo \\ \sqrttwo & -\sqrttwo }} $$ \newcommand{\vzero}{\myvector{1\\0}} $$ \newcommand{\vone}{\myvector{0\\1}} $$ \newcommand{\vhadamardzero}{\myvector{ \sqrttwo \\  \sqrttwo } } $$ \newcommand{\vhadamardone}{ \myrvector{ \sqrttwo \\ -\sqrttwo } } $$ \newcommand{\myarray}[2]{ \begin{array}{1}2\end{array}} $$ \newcommand{\X}{ \mymatrix{cc}{0 & 1 \\ 1 & 0}  } $$ \newcommand{\Z}{ \mymatrix{rr}{1 & 0 \\ 0 & -1}  } $$ \newcommand{\Htwo}{ \mymatrix{rrrr}{ \frac{1}{2} & \frac{1}{2} & \frac{1}{2} & \frac{1}{2} \\ \frac{1}{2} & -\frac{1}{2} & \frac{1}{2} & -\frac{1}{2} \\ \frac{1}{2} & \frac{1}{2} & -\frac{1}{2} & -\frac{1}{2} \\ \frac{1}{2} & -\frac{1}{2} & -\frac{1}{2} & \frac{1}{2} } } $$ \newcommand{\CNOT}{ \mymatrix{cccc}{1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0} } $$ \newcommand{\norm}[1]{ \left\lVert 1 \right\rVert } $ HadamardThe operator for quantum coin-flipping is called Hadamard. It is referred as h-gate in Qiskit.  The first experimentLet's implement the first experiment.Our quantum bit (qubit) starts in state 0, which is shown as $ \ket{0} $. $ \ket{\cdot} $ is called ket-notation:  Ket-notation was introduced to simplify the calculations in quantum mechanics.  The circuit with a single Hadamard Let's desing a circuit with one qubit, and apply quantum coin-flipping once.<jupyter_code># import all necessary objects and methods for quantum circuits
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, execute, Aer
from qiskit.tools.visualization import matplotlib_circuit_drawer as drawer

# define a quantum register with one qubit
qreg1 =  QuantumRegister(1)

# define a classical register with one bit
# it stores the measurement result of the quantum part
creg1 = ClassicalRegister(1)

# define our quantum circuit
mycircuit1 = QuantumCircuit(qreg1,creg1)

# apply h-gate (Hadamard: quantum coin-flipping) to the first qubit
mycircuit1.h(qreg1[0])

# measure the first qubit, and store the result in the first classical bit
mycircuit1.measure(qreg1,creg1)

print("Everything looks fine, let's continue ...")
# draw the circuit

drawer(mycircuit1)
# reexecute me if you DO NOT see the circuit diagram<jupyter_output><empty_output><jupyter_text><jupyter_code># execute the circuit 10000 times in the local simulator

job = execute(mycircuit1,Aer.get_backend('qasm_simulator'),shots=10000)
counts1 = job.result().get_counts(mycircuit1)
print(counts1) # print the outcomes<jupyter_output><empty_output><jupyter_text>The numbers of outcomes '0's and '1's are expected to be close to each other. As we have observed after this implementation, quantum systems are probabilistic.  The third experiment Currently, the intermediate measurements are not possible to implement.Therefore, we (skip the second experiment and) implement the third experiment.  The circuit with two Hadamards We design a circuit with one qubit, and apply quantum coin-flipping twice.<jupyter_code># import all necessary objects and methods for quantum circuits
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, execute, Aer
from qiskit.tools.visualization import matplotlib_circuit_drawer as drawer

# define a quantum register with one qubit
qreg2 =  QuantumRegister(1)

# define a classical register with one bit
# it stores the measurement result of the quantum part
creg2 = ClassicalRegister(1)

# define our quantum circuit
mycircuit2 = QuantumCircuit(qreg2,creg2)

# apply h-gate (Hadamard: quantum coin-flipping) to the first qubit
mycircuit2.h(qreg2[0])

# apply h-gate (Hadamard: quantum coin-flipping) to the first qubit once more
mycircuit2.h(qreg2[0])

# measure the first qubit, and store the result in the first classical bit
mycircuit2.measure(qreg2,creg2)

print("Everyhing looks fine, let's continue ...")
# draw the circuit

drawer(mycircuit2)
# reexecute me if you DO NOT see the circuit diagram
# execute the circuit 10000 times in the local simulator

job = execute(mycircuit2,Aer.get_backend('qasm_simulator'),shots=10000)
counts2 = job.result().get_counts(mycircuit2)
print(counts2)<jupyter_output><empty_output><jupyter_text>The only outcome must be '0'.  Task 1 Remember that x-gate flips the value of a qubit.Design a quantum circuit with a single qubit.The qubit is initially set to $ \ket{0} $.Set the value of qubit to $ \ket{1} $ by using x-gate.Experiment 1: Apply one Hadamard gate, make measurement, and execute your program 10000 times.Experiment 2: Apply two Hadamard gates, make measurement, and execute your program 10000 times.Compare your results.The following two diagrams represent two different experiments.<jupyter_code># import all necessary objects and methods for quantum circuits
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, execute, Aer
from qiskit.tools.visualization import matplotlib_circuit_drawer as drawer

#
# your code is here
#<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13468825353083017, 'fraction_numerical': 0.031346882535308304, 'mean_word_length': 5.087002096436058, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '350780', 'license': 'Apache-2.0', 'n_tokens_mistral': 1967, 'n_tokens_neox': 1787, 'n_words': 593, 'path': 'community/awards/teach_me_quantum_2018/bronze/bronze/B42_Hadamard.ipynb', 'repo_name': 'Chibikuri/qiskit-tutorials', 'size': '5822'}