from qiskit import IBMQ
# IBMQ.save_account(MY_API_TOKEN)
import qiskit 
qiskit.__version__

import numpy as np
from qiskit import QuantumCircuit, QuantumRegister
from qiskit.quantum_info.operators import Operator
from qiskit import(QuantumCircuit, execute, Aer)
from qiskit.visualization import plot_histogram
from qiskit.extensions import Initialize # Import the Inititialize function

theta = np.pi / 6
x = 0.25

qc = QuantumCircuit(2,2)
initial_state = [np.sqrt(x), np.sqrt(1-x)]
initialize_qubit = Initialize(initial_state)
qc.append(initialize_qubit, [0])
qc.h(0)
# qc.unitary(Rz(0), [0], label='Rz')
qc.rz(theta, 0)
qc.cx(0,1)
qc.h(1)
# Map the quantum measurement to the classical bits
qc.measure([0], [0])

# Use Aer's qasm_simulator
simulator = Aer.get_backend('qasm_simulator')

# Execute the circuit on the qasm simulator
job = execute(qc, simulator, shots=1000)

# Grab results from the job
result = job.result()

# Returns counts
counts = result.get_counts(qc)
print("\nTotal count for 0 and 1 are:",counts)
qc.draw()

