Code: Select all
from qiskit import QuantumCircuit, Aer, execute
# Create a quantum circuit with 2 qubits
circuit = QuantumCircuit(2)
# Apply Hadamard gate to the first qubit
circuit.h(0)
# Apply CNOT gate with the first qubit as the control and the second qubit as the target
circuit.cx(0, 1)
# Simulate the circuit
simulator = Aer.get_backend('statevector_simulator')
job = execute(circuit, simulator)
# Get the result
result = job.result()
# Get the final state vector
final_state_vector = result.get_statevector()
# Print the final state vector
print("State Vector:", final_state_vector)
When you run this code, you should observe that the final state vector matches the expected Bell state (|00⟩ + |11⟩), which signifies that the two qubits are entangled.