Created
December 12, 2020 14:51
-
-
Save GDLMadushanka/925861491bb2a23d8ec8aacef26535a6 to your computer and use it in GitHub Desktop.
Creating arbitrary qubit by custom rotations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, execute, Aer | |
from qiskit.visualization import plot_bloch_multivector | |
from math import pi | |
%matplotlib inline | |
q = QuantumRegister(1,"q") | |
c = ClassicalRegister(1,"c") | |
qc = QuantumCircuit(q,c) | |
# Crating the angle pi/4 = 45 degrees | |
theta = pi*(1/4) | |
qc.ry(theta,q[0]) | |
# Get the state-vector to draw on the bloch sphere. | |
backend = Aer.get_backend('statevector_simulator') | |
result = execute(qc, backend).result() | |
psi = result.get_statevector() | |
display(plot_bloch_multivector(psi)) | |
# Measure the quibit | |
qc.measure(q,c) | |
# Run the circuit again in qasm_simulator to get probability results. | |
job = execute(qc,Aer.get_backend('qasm_simulator'),shots=1000) | |
counts = job.result().get_counts(qc) | |
print(counts) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment