-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqiskit_example.py
More file actions
25 lines (22 loc) · 808 Bytes
/
Copy pathqiskit_example.py
File metadata and controls
25 lines (22 loc) · 808 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
"""
Qiskit Example: Create and Simulate a Bell State
-------------------------------------------------
This script demonstrates how to use Qiskit to create a Bell state,
simulate it, and print the measurement results.
"""
from qiskit import QuantumCircuit, Aer, execute
# Create a 2-qubit quantum circuit
circuit = QuantumCircuit(2, 2)
# Apply Hadamard gate to qubit 0 (creates superposition)
circuit.h(0)
# Apply CNOT gate (entangles qubits 0 and 1)
circuit.cx(0, 1)
# Measure both qubits
circuit.measure([0, 1], [0, 1])
# Use the QasmSimulator backend
simulator = Aer.get_backend('qasm_simulator')
# Execute the circuit 1024 times (shots)
result = execute(circuit, simulator, shots=1024).result()
# Get the counts of measurement outcomes
counts = result.get_counts()
print("Bell state counts:", counts)