import qiskit
qiskit.__version__

qiskit.__qiskit_version__

#Import the required packages
from qiskit import QuantumCircuit, QuantumRegister,ClassicalRegister,Aer,execute
from qiskit.visualization import *


qc1=QuantumCircuit(3)

## also comment the 2 NOT gates on qubit 0 and 1 and check the third qubit
qc1.x(0)
qc1.x(1)
qc1.ccx(0,1,2)
qc1.draw('mpl')

backend=Aer.get_backend('statevector_simulator')
job=execute(qc1,backend)
result=job.result()
sv=result.get_statevector()
sv.draw(output="latex")

# We create 3-qubit mct gate
# We have a list of control qubits :0,1 and a target qubit 2.
qc2=QuantumCircuit(3)


## also comment the 2 NOT gates on qubit 0 and 1 and check the third qubit

qc2.x(0)
qc2.x(1)
qc2.mct([0,1],2)
qc2.draw('mpl')

backend=Aer.get_backend('statevector_simulator')
job=execute(qc2,backend)
result=job.result()
sv=result.get_statevector()
sv.draw(output="latex")

# We simply create a user-defined object cx from  CXGate class
# Another way of accessing a CX or NOT gate

from qiskit.circuit.library import CXGate
qc3=QuantumCircuit(3)
cx=CXGate()
qc3.append(cx,[0,1])
qc3.draw('mpl')

from qiskit.circuit.library import CXGate
qc4=QuantumCircuit(3)
ccx=CXGate().control()
qc4.append(ccx,[0,1,2])
qc4.draw('mpl')

from math import pi

qc5=QuantumCircuit(2)
qc5.cry(pi/2,0,1)
qc5.draw('mpl')

backend=Aer.get_backend('statevector_simulator')
job=execute(qc5,backend)
result=job.result()
sv=result.get_statevector()
sv.draw(output="latex")

#Let's apply a X on the control qubit
qc6=QuantumCircuit(2)
qc6.x(0)
qc6.cry(pi/2,0,1)
qc6.draw('mpl')

backend=Aer.get_backend('statevector_simulator')
job=execute(qc6,backend)
result=job.result()
sv=result.get_statevector()
print("statevector:", sv)
sv.draw(output="latex")

