<jupyter_start><jupyter_text>prepared by <NAME> (QLatvia)                        updated by <NAME> | January 5, 2020                 This cell contains some macros. If there is a problem with displaying mathematical formulas, please run this cell to load these macros. $ \newcommand{\bra}[1]{\langle 1|} $$ \newcommand{\ket}[1]{|1\rangle} $$ \newcommand{\braket}[2]{\langle 1|2\rangle} $$ \newcommand{\dot}[2]{ 1 \cdot 2} $$ \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 } $  Executing Quantum Programs on IBMQ  We create a quantum circuit.<jupyter_code># import the objects from qiskit
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, execute, Aer

# create classical and quantum register objects a quantum circuit
qreg = QuantumRegister(2) # my quantum register
creg = ClassicalRegister(2) # my classical register 
circuit = QuantumCircuit(qreg,creg) # my quantum circuit

# apply a Hadamard gate to the first qubit

circuit.h(qreg[0])

# set the second qubit to |1>
circuit.x(qreg[1])

# apply CNOT(first_qubit,second_qubit)
circuit.cx(qreg[0],qreg[1])

# measure the both qubits
circuit.measure(qreg,creg)<jupyter_output><empty_output><jupyter_text>We draw the circuit.<jupyter_code>circuit.draw(output="mpl")<jupyter_output><empty_output><jupyter_text>IBM Q TestNow, we test our system for accesing to IBM Q. The remaining part requires internet connection.Our test circuit will be executed on IBM simulator, and then on one of IBM real qauntum computers. Please wait the execution of each cell to be completed, before executing the next cell. Joining IBM Q ExperienceIn order to use IBM services, one should be a member of IBM Q Experience.Sign up and then sign in hereAfter signing into the system, go to My Account (top-right icon)There you can copy your API key, which is used when connecting to IBM platforms.You can also see IBM Q Backend Access (available to you, under maintenance, etc.) and your Units. Save your API on the diskPlease write YOUR IBM API TOKEN in the following cell, and then run the cell.Once they are saved on the disk, they can be used directly later.<jupyter_code>from qiskit import IBMQ
IBMQ.save_account('write YOUR IBM API TOKEN here')

# Then, execute this cell<jupyter_output><empty_output><jupyter_text>See the stored account(s)<jupyter_code>IBMQ.stored_account()<jupyter_output><empty_output><jupyter_text>Load our account(s)<jupyter_code>IBMQ.load_account()<jupyter_output><empty_output><jupyter_text>See the active account(s)<jupyter_code>IBMQ.active_account()<jupyter_output><empty_output><jupyter_text>Get provider<jupyter_code>IBMQ.load_account()
provider = IBMQ.get_provider(hub='ibm-q')<jupyter_output><empty_output><jupyter_text>See available backends<jupyter_code>provider.backends()<jupyter_output><empty_output><jupyter_text>See the currently operational real quantum computer(s)<jupyter_code>provider.backends(operational=True, simulator=False)<jupyter_output><empty_output><jupyter_text>See the least busy real quantum computer<jupyter_code>from qiskit.providers.ibmq import least_busy

least_busy(provider.backends(simulator=False))<jupyter_output><empty_output><jupyter_text>IBMQ simulator   This is IBMQ's simulator. You can use the simulator as backend for running large circuits<jupyter_code>simulator_backend = provider.get_backend('ibmq_qasm_simulator')

simulator_backend.name()<jupyter_output><empty_output><jupyter_text>Execute the circuit<jupyter_code>job = execute(circuit, backend=simulator_backend, shots=1024)<jupyter_output><empty_output><jupyter_text>Check the result<jupyter_code>result = job.result()
counts = result.get_counts()
print(counts)<jupyter_output><empty_output><jupyter_text>IBMQ real quantum computers (Optional)   You can use the least busy real machine as backend<jupyter_code>backend_real = least_busy(provider.backends(simulator=False))

backend_real.name()

backend_real.status()<jupyter_output><empty_output><jupyter_text>You can also select a specific backend<jupyter_code>provider.backends()
vigo=provider.get_backend('ibmq_vigo')
vigo.status()<jupyter_output><empty_output><jupyter_text>Execute the same job on a real machine Depending on the number of pending jobs, it might take for a while to execute your job on the real machine. But, this is not a problem to complete our tutorial, because we use the local simulator during the tutorial.<jupyter_code>job_real = execute(circuit, backend=backend_real, shots=1024)
#job_real = execute(circuit, backend=vigo, shots=1024)

job_real.queue_position()<jupyter_output><empty_output><jupyter_text>Check the result<jupyter_code>result_real = job_real.result()
counts_real = result_real.get_counts()
print(counts_real)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14323475962332727, 'fraction_numerical': 0.01999008755988766, 'mean_word_length': 6.023201856148492, 'pattern_counts': {'":': 0, '<': 71, '<?xml version=': 0, '>': 72, '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': '17', 'dir': 'jupyter-structured-clean-dedup', 'id': '294262', 'license': 'MIT', 'n_tokens_mistral': 2136, 'n_tokens_neox': 1997, 'n_words': 503, 'path': 'Bronze/Executing_quantum_programs_on_IBMQ.ipynb', 'repo_name': 'SevdanurGENC/Quantum-Programming-With-Qiskit', 'size': '6071'}