Quantum Computing with IBM QX Chapter 8 9

Quantum Computing with IBM QX Chapter 8, 9, and 10 Dr. Charles Tappert The information presented here, although greatly condensed, comes almost entirely from the textbook

Chapter 8 Qiskit & Quantum Simulation n n This chapter introduces Qiskit (Quantum Information Software Kit), focusing on how it can be used to run programs in IBM QX as well as its capabilities for quantum simulation This chapter covers the following topics: n n Qiskit Using Qiskit installation and usage Terra and Qiskit Aqua Qiskit with Open. QASM Capstone project – quantum chords (MIDI)

Chapter 8 Qiskit & Quantum Simulation Technical requirements n This chapter’s code is in a Jupyter Notebook https: //github. com/Packt. Publishing/Mastering. Quantum-Computing-with-IBMQX, in the Chapter 08 directory, together with data files

Chapter 8 Qiskit & Quantum Simulation Testing Qiskit installation n Check installation by running following code, and refer to Chapter 1, What is Quantum Computing? , in the Setup and run Qiskit examples section, as required for troubleshooting: from qiskit import Aer from qiskit import IBMQ # Authenticate an account and add for use during this session. Replace string argument with your private token IBMQ. enable_account("INSERT_YOUR_API_TOKEN_HERE")

Chapter 8 Qiskit & Quantum Simulation Testing Qiskit installation Run the following code: n import qiskit from qiskit. tools. visualization import plot_histogram # Pick an available backend = IBMQ. get_backend('ibmq_qasm_simulator') # Setup 5 quantum and 5 classical registers, performing a measurement q = qiskit. Quantum. Register(5) c = qiskit. Classical. Register(5) qc = qiskit. Quantum. Circuit(q, c) qc. measure(q, c) # Executing the job on IBM QX job_exp = qiskit. execute(qc, backend=backend) plot_histogram(job_exp. result(). get_counts(qc))

Chapter 8 Qiskit & Quantum Simulation Testing Qiskit installation n You should get 00000 with 100% probability:

Chapter 8 Qiskit & Quantum Simulation Using Open. QASM with Qiskit n n Although directly programming in Qiskit via Python is useful, often quantum algorithms are specified in Open. QASM. In this subsection, we provide a few examples of integrating Open. QASM programs into Qiskit code. Skip brief sections on loading from a file and from a string

Chapter 8 Qiskit & Quantum Simulation Qiskit Aqua introduction and installation n Qiskit, as we have set it up so far, focuses on lower level direct manipulation of qubits This portion of the qiskit library is also known as Qiskit Terra (https: //qiskit. org/terra ) to contrast it with QISKit Aqua (https: //qiskit. org/aqua ) Many algorithms are available in Qiskit Aqua (Algorithms for QUantum computing Applications)

Chapter 8 Qiskit & Quantum Simulation Qiskit Aqua introduction and installation n If you installed the requirements for the book using pip from the requirements. txt file, Qiskit Aqua is already installed. If not, Qiskit Aqua can be installed with the following: pip install qiskit-acqua-chemistry n Test your Qiskit Aqua installation by running the following code: # Testing QISKit Aqua installation import qiskit_acqua_chemistry

Chapter 8 Qiskit & Quantum Simulation Qiskit Aqua introduction and installation n At the time of this book's writing, Qiskit Aqua contained modules for the following: n n n n Quantum Grover Search (QGS) Support Vector Machine Quantum Kernel (SVM Q Kernel) Quantum Dynamics (QD) Quantum Phase Estimation (QPE) Variational Quantum Eigensolver (VQE) Iterative Quantum Phase Estimation (IQPE) Support Vector Machine Variational (SVM Variational) For more information about Qiskit Aqua, check out the website at https: //github. com/Qiskit/aqua

Chapter 8 Qiskit & Quantum Simulation Qiskit Terra – Capstone project n IBM has tutorials on short quantum programs that illustrate the nature of superposition through ASCII characters and sound clips n n https: //github. com/Qiskit/qiskittutorials/tree/master/community/hello_world We skip the remaining sections that illustrate the nature of superposition through encoding musical notes via the MIDI code

Chapter 8 Qiskit & Quantum Simulation Grover's algorithm n n Jupyter notebooks for Qiskit Aqua may be found in the following Qiskit Git. Hub repositories at qiskit-iqxtutorials/qiskit/advanced/aqua and qiskit-communitytutorials/aqua The code below shows how Grover’s search algorithm can be used with the Logical. Expression. Oracle to find one satisfying assignment for the Satisfiability (SAT) problem instance encoded in the DIMACS CNF format. The input string sat_cnf corresponds to the following Conjunctive Normal Form (CNF): n n (¬x 1 ∨ ¬x 2 ∨ ¬x 3) ∧ (x 1 ∨ ¬x 2 ∨ x 3) ∧ (x 1 ∨ x 2 ∨ ¬x 3) ∧ (x 1 ∨ ¬x 2 ∨ ¬x 3) ∧ (¬x 1 ∨ x 2 ∨ x 3) This Python code prints out one possible solution for this CNF n For example, output 1, -2, 3 indicates that logical expression ( x 1 ∨ ¬x 2 ∨ x 3) satisfies the given CNF.

Chapter 8 Qiskit & Quantum Simulation Grover's algorithm n n n n n $ python from qiskit import Aer from qiskit. aqua. components. oracles import Logical. Expression. Oracle from qiskit. aqua. algorithms import Grover sat_cnf = """ c Example DIMACS 3 -sat p cnf 3 5 -1 -2 -3 0 1 -2 3 0 1 2 -3 0 1 -2 -3 0 -1 2 3 0 """ backend = Aer. get_backend('qasm_simulator') oracle = Logical. Expression. Oracle(sat_cnf) algorithm = Grover(oracle) result = algorithm. run(backend) print(result["result"])

Chapter 9 Quantum AND and OR Gates n This chapter explores some of the quantum equivalents of classic Boolean logical gates, with the aim of being able to specify logic problems to be solved by a quantum computer for use with Grover's and other algorithms n n n The 3 SAT function and the process of inverting it A classic algorithm for inverting the 3 SAT function Toffoli gate: quantum equivalent of the AND gate The quantum equivalent of the OR gate Specifying 3 SAT problems using quantum circuits

Chapter 9 Quantum AND and OR Gates n This chapter’s code is in a Jupyter Notebook https: //github. com/Packt. Publishing/Mastering. Quantum-Computing-with-IBMQX, in the Chapter 09 directory, together with data files

Chapter 9 Quantum AND and OR Gates Boolean satisfiability problem (SAT) n n n In computer programming, we often deal with logical conditions, if/else statements and loops being two prominent examples that evaluate expressions to determine whether they are true or not, and thereby determine future actions of the code A Boolean expression is an expression with variables joined by the operators AND, OR, and NOT as well as parentheses The process of figuring out whether any possible combination of Boolean variables could satisfy a Boolean expression is known as the Boolean satisfiability problem or SAT

Chapter 9 Quantum AND and OR Gates 3 SAT classical implementation n Any Boolean satisfiability problem can be rewritten in the form of distinct sections of variables containing or and functions between them 3 SAT is an especially interesting problem to solve as many other problems can be mapped to its formulation 3 SAT is also a well known NP-complete problem

Chapter 9 Quantum AND and OR Gates 3 SAT quantum circuit implementation n n Sections on implementation of quantum AND and OR Final section on 3 SAT quantum circuit implementation n Let's put everything together to implement a 3 SAT problem in a quantum circuit. In the next chapter on Grover's algorithm, we will use the formulation we develop in this section as input to Grover's algorithm to solve for the unique input that satisfies it. The 3 SAT problem we will implement in a quantum circuit is as follows:

Chapter 9 Quantum AND and OR Gates 3 SAT quantum circuit implementation n Complex circuits, only a portion shown below

Chapter 10 Grover's Algorithm n n Grover's algorithm is a quantum algorithm that can be used to invert a function more quickly than any classic algorithm. Essentially, that means if there are N possible solutions to a function, only one of which is correct, Grover's algorithm works to efficiently find the one solution out of the pack. Grover's algorithm is sometimes referred to as quantum search or even as quantum database search. This chapter first introduces Grover's algorithm. It then goes over a specific use case of Grover's algorithm to illustrate its potential: that of solving the Boolean satisfiability problem.

Chapter 10 Grover's Algorithm n This chapter’s code is in a Jupyter Notebook https: //github. com/Packt. Publishing/Mastering. Quantum-Computing-with-IBMQX, in the Chapter 10 directory, together with data files

Chapter 10 Grover's Algorithm Overview and example use case n n n We will use Grover's algorithm to find the solution to an exactly-1 3 SAT problem, 3 sat_mystery defined as follows: Grover's algorithm will find the unique combination of a, b, and c for which this function returns true. For those interested, read this chapter.
- Slides: 22