Skip to content

Commit a97dae0

Browse files
Added Qiskit code to create and measure a Bell State
1 parent d82cf52 commit a97dae0

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

quantum/bell_state.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
### Qiskit code to create and measure a Bell state. ####
2+
import numpy as np
3+
from qiskit import QuantumCircuit, execute, Aer
4+
# Create a Quantum Circuit with two qbits and 2 classical bits
5+
circuit = QuantumCircuit(2,2)
6+
# Add a H gate on qubit 0
7+
circuit.h(0)
8+
# Add a CX (CNOT) gate on control qubit 0 and target qubit 1
9+
circuit.cx(0,1)
10+
# Map the quantum measurement to the classical bits
11+
circuit.measure([0,1],[0,1])
12+
# Use Aer's qasm_simulator
13+
simulator = Aer.get_backend('qasm_simulator')
14+
# Execute the circuit on the qasm simulator
15+
job = execute(circuit, simulator, shots=1000)
16+
# Grab results from the job
17+
result = job.result()
18+
# Returns counts
19+
counts = result.get_counts(circuit)
20+
print("\nTotal count for 00 and 11 are:",counts)

0 commit comments

Comments
 (0)