Skip to content

Instantly share code, notes, and snippets.

@tedtanne
Created March 31, 2020 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tedtanne/6e4bf22d9ee9f06ce918175a225da66c to your computer and use it in GitHub Desktop.
Save tedtanne/6e4bf22d9ee9f06ce918175a225da66c to your computer and use it in GitHub Desktop.
# Create a Quantum Circuit acting on the q register
circuit = QuantumCircuit(2, 2)
Add a H gate on qubit 0
circuit.h(0)
# Add a CX (CNOT) gate on control qubit 0 and target qubit 1
circuit.cx(0, 1)
# Map the quantum measurement to the classical bits
circuit.measure([0,1], [0,1])
#Execute Phase:
#Use Aer's qasm_simulator
simulator = Aer.get_backend('qasm_simulator')
Execute the circuit on the qasm simulator
job = execute(circuit, simulator, shots=1000)
Grab results from the job
result = job.result()
Return counts
counts = result.get_counts(circuit)
print("\nTotal count for 00 and 11 are:",counts)
#Analyze
Draw the circuit
circuit.draw()
@tedtanne
Copy link
Author

This code is from IBM Quantum Computing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment