from qiskit import QuantumCircuit
QuantumCircuit(2)

QuantumCircuit(2, 2)

import math

qc = QuantumCircuit(4)
qc.h(0)
qc.id(2)
qc.i(2)
qc.p(math.pi/2,0)
qc.rx(math.pi/4,2)
qc.ry(math.pi/8,0)
qc.rz(math.pi/2,1)
qc.s(3)
qc.sdg(3)
qc.sx(2)
qc.t(1)
qc.tdg(1)
qc.u(math.pi/2,0,math.pi,1)
qc.x(3)
qc.y([0,2,3])
qc.z(2)

qc = QuantumCircuit(4)
qc.h(0)
qc.id(2)
qc.p(math.pi/2,0)
qc.rx(math.pi/4,2)
qc.ry(math.pi/8,0)
qc.rz(math.pi/2,1)
qc.s(3)
qc.sdg(3)
qc.sx(2)
qc.t(1)
qc.tdg(1)
qc.u(math.pi/2,0,math.pi,1)
qc.x(3)
qc.y([0,2,3])
qc.z(2)
qc.draw('mpl')

qc.ccx(0,1,2)
qc.ch(0,1)
qc.cp(math.pi/4,0,1)
qc.crx(math.pi/2,2,3)
qc.crz(math.pi/4,0,1)
qc.cswap(0,2,3)
qc.fredkin(0,2,3)
qc.csx(0,1)
qc.cu(math.pi/2,0,math.pi,0,0,1)
qc.cx(2,3)
qc.cnot(2,3)
qc.cy(2,3)
qc.cz(1,2)
qc.dcx(2,3)
qc.iswap(0,1)
qc.mcp(math.pi/4,[0,1,2],3)
qc.mcx([0,1,2],3)
qc.swap(2,3)

qc = QuantumCircuit(4)
qc.ccx(0,1,2)
qc.ch(0,1)
qc.cp(math.pi/4,0,1)
qc.crx(math.pi/2,2,3)
qc.crz(math.pi/4,0,1)
qc.cswap(0,2,3)
qc.csx(0,1)
qc.cu(math.pi/2,0,math.pi,0,0,1)
qc.cx(2,3)
qc.cy(2,3)
qc.cz(1,2)
qc.dcx(2,3)
qc.iswap(0,1)
qc.mcp(math.pi/4,[0,1,2],3)
qc.mcx([0,1,2],3)
qc.swap(2,3)
qc.draw('mpl')

qc = QuantumCircuit(3)
qc.h(0)
qc.cx(0, 1)
qc.cx(0, 2)
qc.draw('mpl')

qc = QuantumCircuit(2)
qc.h([0,1])
qc.barrier()
qc.x(0)
qc.x(0)
qc.s(1)
qc.barrier([1])
qc.s(1)
qc.draw('mpl')

qc = QuantumCircuit(3, 3)
qc.h([0,1,2])
qc.measure([0,1,2], [0,1,2])
qc.draw('mpl')

qc = QuantumCircuit(3)
qc.h([0,1,2])
qc.measure_all()
qc.draw('mpl')

qc.depth()

qc.size()

qc.width()

qc.clbits

qc.data

qc.global_phase

qc.num_clbits

qc.num_qubits

qc.qubits

from qiskit.circuit.library import CXGate

qc = QuantumCircuit(2)
qc.h(1)
cx_gate = CXGate()
qc.append(cx_gate, [1,0])
qc.draw()

from qiskit.circuit import QuantumCircuit,\
                           Parameter

theta1 = Parameter('θ1')
theta2 = Parameter('θ2')
theta3 = Parameter('θ3')

qc = QuantumCircuit(3)
qc.h([0,1,2])
qc.p(theta1,0)
qc.p(theta2,1)
qc.p(theta3,2)

qc.draw()

b_qc = qc.bind_parameters({theta1: math.pi/8,
                              theta2: math.pi/4,
                              theta3: math.pi/2})
b_qc.draw()

qc = QuantumCircuit(2,2)
qc.h(0)
another_qc = QuantumCircuit(2,2)
another_qc.cx(0,1)
bell_qc = qc.compose(another_qc)
bell_qc.draw()

qc = QuantumCircuit(2)
qc.h(0)
qc.s(0)
qc.x(1)
decomposed_qc = qc.decompose()
decomposed_qc.draw()

qasm_str = """
OPENQASM 2.0;
include "qelib1.inc";
qreg q[2];
creg c[2];
h q[0];
cx q[0],q[1];
measure q[0] -> c[0];
measure q[1] -> c[1];
"""
new_qc = QuantumCircuit.from_qasm_str(qasm_str)
new_qc.draw()

qc = QuantumCircuit(2)
qc.initialize([0, 0, 0, 1])
qc.draw()

qc = QuantumCircuit(1)
qc.x(0)
qc.reset(0)
qc.draw()

anti_cnot_qc = QuantumCircuit(2)
    
anti_cnot_qc.x(0)
anti_cnot_qc.cx(0,1)
anti_cnot_qc.x(0)
anti_cnot_qc.draw()

anti_cnot_gate = anti_cnot_qc.to_gate()

qc = QuantumCircuit(3)
qc.x([0,1,2])
qc.append(anti_cnot_gate, [0,2])

qc.decompose().draw()

reset_one_qc = QuantumCircuit(1)
    
reset_one_qc.reset(0)
reset_one_qc.x(0)
reset_one_qc.draw()

reset_one_inst = reset_one_qc.to_instruction()
    
qc = QuantumCircuit(2)
qc.h([0,1])
qc.reset(0)
qc.append(reset_one_inst, [1])

qc.decompose().draw()

from qiskit import QuantumRegister, \
                   ClassicalRegister

qr = QuantumRegister(3, 'q')
scratch = QuantumRegister(1, 'scratch')
cr = ClassicalRegister(3, 'c')
qc = QuantumCircuit(qr, scratch, cr)
    
qc.h(qr)
qc.x(scratch)
qc.h(scratch)
qc.cx(qr[0], scratch)
qc.cx(qr[2], scratch)
qc.barrier(qr)
qc.h(qr)
qc.measure(qr, cr)

qc.draw()

