Example #1
0
def qft_steps(N=1, swapping=True):
    """
    Quantum Fourier Transform operator on N qubits returning the individual
    steps as unitary matrices operating from left to right.

    Parameters
    ----------
    N: int
        Number of qubits.
    swap: boolean
        Flag indicating sequence of swap gates to be applied at the end or not.

    Returns
    -------
    U_step_list: list of qobj
        List of Hadamard and controlled rotation gates implementing QFT.

    """
    if N < 1:
        raise ValueError("Minimum value of N can be 1")

    U_step_list = []
    if N == 1:
        U_step_list.append(snot())
    else:
        for i in range(N):
            for j in range(i):
                U_step_list.append(
                    cphase(np.pi / (2**(i - j)), N, control=i, target=j))
            U_step_list.append(snot(N, i))
        if swapping is True:
            for i in range(N // 2):
                U_step_list.append(swap(N, [N - i - 1, i]))

    return U_step_list
Example #2
0
def qft_steps(N=1, swapping=True):
    """
    Quantum Fourier Transform operator on N qubits returning the individual
    steps as unitary matrices operating from left to right.
    
    Parameters
    ----------
    N: int
        Number of qubits.
    swap: boolean
        Flag indicating sequence of swap gates to be applied at the end or not.
    
    Returns
    -------
    U_step_list: list of qobj
        List of Hadamard and controlled rotation gates implementing QFT.
    
    """
    if N < 1:
        raise ValueError("Minimum value of N can be 1")
    
    U_step_list = []
    if N == 1:
        U_step_list.append(snot())
    else:
        for i in range(N):
            for j in range(i):
                U_step_list.append(cphase(np.pi/(2**(i-j)), N,
                                   control=i, target=j))
            U_step_list.append(snot(N, i))
        if swapping == True:
            for i in range(N//2):
                U_step_list.append(swap(N, [N-i-1, i]))

    return U_step_list
Example #3
0
def test_qpt_snot():
    "quantum process tomography for snot gate"

    U_psi = snot()
    U_rho = spre(U_psi) * spost(U_psi.dag())
    N = 1
    op_basis = [[qeye(2), sigmax(), 1j * sigmay(), sigmaz()] for i in range(N)]
    # op_label = [["i", "x", "y", "z"] for i in range(N)]
    chi1 = qpt(U_rho, op_basis)

    chi2 = np.zeros((2 ** (2 * N), 2 ** (2 * N)), dtype=complex)
    chi2[1, 1] = chi2[1, 3] = chi2[3, 1] = chi2[3, 3] = 0.5

    assert_(norm(chi2 - chi1) < 1e-8)
Example #4
0
def test_qpt_snot():
    "quantum process tomography for snot gate"

    U_psi = snot()
    U_rho = spre(U_psi) * spost(U_psi.dag())
    N = 1
    op_basis = [[qeye(2), sigmax(), 1j * sigmay(), sigmaz()] for i in range(N)]
    # op_label = [["i", "x", "y", "z"] for i in range(N)]
    chi1 = qpt(U_rho, op_basis)

    chi2 = np.zeros((2**(2 * N), 2**(2 * N)), dtype=complex)
    chi2[1, 1] = chi2[1, 3] = chi2[3, 1] = chi2[3, 3] = 0.5

    assert_(norm(chi2 - chi1) < 1e-8)
x = sigmax()
print(x)
print("\n")

ket_zero = qubit_states(N=1, states=[0])

print(ket_zero)
print("\n")

print(x * ket_zero)
print("\n")

print(tensor([identity(N=2), hadamard_transform(N=1)]))
print("\n")

print(snot(N=2, target=1))
print("\n")

print(swap(N=2, targets=[0, 1]))
print("\n")

print(cnot(N=2, control=0, target=1))
print("\n")

print(cnot(N=4, control=0, target=3))
print("\n")

print(hadamard_transform(N=2) * qubit_states(N=2, states=[0, 0]))
print("\n")

qc3 = QubitCircuit(N=3)