Computer Science
Grade 12
20 min
Quantum Programming Frameworks: Qiskit and Cirq
Get hands-on experience with quantum programming frameworks like Qiskit and Cirq, learning how to write and simulate quantum algorithms using these tools.
Tutorial Preview
1
Introduction & Learning Objectives
Learning Objectives
Differentiate the core philosophies and syntax of IBM's Qiskit and Google's Cirq.
Construct a basic quantum circuit, including qubit initialization, gate application, and measurement, in both Qiskit and Cirq.
Apply fundamental single-qubit (Hadamard, X) and multi-qubit (CNOT) gates to manipulate qubit states.
Implement a simple quantum algorithm, such as creating a Bell state, using a software simulator in both frameworks.
Execute a quantum circuit simulation and interpret the resulting probability distribution of measurement outcomes.
Explain the role of a 'backend' and distinguish between a local simulator and real quantum hardware.
Ever wanted to write code for a computer that leverages the strange principles of quantum mechanics? ⚛...
2
Key Concepts & Vocabulary
TermDefinitionExample
Quantum CircuitA model for quantum computation, analogous to a classical logic circuit. It consists of a sequence of quantum gates applied to a set of qubits, followed by measurements.A circuit that first applies a Hadamard gate to a qubit to put it in superposition, then a CNOT gate to entangle it with another qubit, and finally measures both.
Qubit (Quantum Bit)The fundamental unit of quantum information. Unlike a classical bit (0 or 1), a qubit can exist in a superposition of both |0⟩ and |1⟩ states simultaneously.A qubit after a Hadamard gate is in the state (1/√2)|0⟩ + (1/√2)|1⟩, having a 50% probability of being measured as 0 and a 50% probability of being measured as 1.
Quantum GateAn operation that acts on one or more qubits to change their state. It is the q...
3
Core Syntax & Patterns
Qiskit: Circuit Construction Pattern
1. `qc = QuantumCircuit(n, m)`
2. `qc.gate(qubit_index)`
3. `qc.measure(qubit_index, classical_bit_index)`
In Qiskit, you first initialize a QuantumCircuit object, specifying the number of qubits (n) and classical bits (m). You then apply gates as methods of this object and finally add measurement operations, mapping specific qubits to classical bits.
Cirq: Circuit Construction Pattern
1. `qubits = cirq.LineQubit.range(n)`
2. `circuit = cirq.Circuit()`
3. `circuit.append(cirq.GATE(qubit))`
4. `circuit.append(cirq.measure(qubits, key='result'))`
In Cirq, you typically define your qubits first. Then, you create a Circuit object and append operations (gates and measurements) to it in the desired order. Measurements are grouped and...
4 more steps in this tutorial
Sign up free to access the complete tutorial with worked examples and practice.
Sign Up Free to ContinueSample Practice Questions
Easy
According to the tutorial, what is the fundamental purpose of a 'backend' in the context of Qiskit and Cirq?
A.To design the visual layout of the quantum circuit diagram.
B.software library for optimizing quantum gate sequences.
C.The user interface for writing quantum programs.
D.The computational resource, either a simulator or real hardware, that runs the circuit.
Easy
In Qiskit, which line of code correctly initializes a quantum circuit with 3 quantum bits and 3 classical bits?
A.qc = QuantumCircuit(3, 3)
B.qc = qiskit.Circuit(qubits=3, cbits=3)
C.qc = new Circuit(3, 3)
D.qc = QuantumCircuit.create(3, 3)
Easy
What is the primary function of a quantum gate, such as the Hadamard or CNOT gate?
A.To measure the state of a qubit and return a classical bit.
B.To initialize a qubit to the |0⟩ state.
C.To act on one or more qubits to change their state.
D.To entangle a qubit with the environment, causing decoherence.
Want to practice and check your answers?
Sign up to access all questions with instant feedback, explanations, and progress tracking.
Start Practicing Free