Qubits and Qiskit
Chapter 1, New Ways to Think about Bits, introduced Jupyter notebooks and showed you how to multiply matrices in Python. In this chapter, we’ll up the ante with Qiskit code for qubits. We’ll write code to create qubits, modify qubits’ values using quantum operators, measure qubits, and then display the results.
Creating and running a quantum circuit
To create your first quantum computing program, follow these steps:
- Create a new Jupyter notebook by following Steps 1 through 3 in the Matrices in Python section in Chapter 1, New Ways to Think about Bits.
- In the cell at the top of the notebook, copy the following code, and then press Shift + Enter:
from qiskit import QuantumRegister, \ ClassicalRegister, QuantumCircuit qReg = QuantumRegister(1, 'q') cReg = ClassicalRegister(1, 'c') circuit = QuantumCircuit(qReg, cReg) circuit.h(qReg[0]) circuit.measure(qReg[0], cReg[0]) display(circuit...