Esempio n. 1
0
def test_wigner_ghz_su2parity():
    """wigner: testing the SU2 wigner transformation of the GHZ state.
    """
    psi = (ket([0, 0, 0]) + ket([1, 1, 1])) / np.sqrt(2)

    steps = 100
    N = 3
    theta = np.tile(np.linspace(0, np.pi, steps), N).reshape(N, steps)
    phi = np.tile(np.linspace(0, 2 * np.pi, steps), N).reshape(N, steps)
    slicearray = ['l', 'l', 'l']

    wigner_analyt = np.zeros((steps, steps))
    for t in range(steps):
        for p in range(steps):
            wigner_analyt[t, p] = np.real(
                ((1 + np.sqrt(3) * np.cos(theta[0, t])) *
                 (1 + np.sqrt(3) * np.cos(theta[1, t])) *
                 (1 + np.sqrt(3) * np.cos(theta[2, t])) + 3**(3 / 2) *
                 (np.sin(theta[0, t]) * np.exp(-1j * phi[0, p]) *
                  np.sin(theta[1, t]) * np.exp(-1j * phi[1, p]) *
                  np.sin(theta[2, t]) * np.exp(-1j * phi[2, p]) +
                  np.sin(theta[0, t]) * np.exp(1j * phi[0, p]) *
                  np.sin(theta[1, t]) * np.exp(1j * phi[1, p]) *
                  np.sin(theta[2, t]) * np.exp(1j * phi[2, p])) +
                 (1 - np.sqrt(3) * np.cos(theta[0, t])) *
                 (1 - np.sqrt(3) * np.cos(theta[1, t])) *
                 (1 - np.sqrt(3) * np.cos(theta[2, t]))) / 16.)

    wigner_theo = wigner_transform(psi, 0.5, False, steps, slicearray)

    assert_(np.sum(np.abs(wigner_analyt - wigner_theo)) < 1e-11)
Esempio n. 2
0
def test_wigner_ghz_su2parity():
    """wigner: testing the SU2 wigner transformation of the GHZ state.
    """
    psi = (ket([0, 0, 0]) + ket([1, 1, 1])) / np.sqrt(2)

    steps = 100
    N = 3
    theta = np.tile(np.linspace(0, np.pi, steps), N).reshape(N, steps)
    phi = np.tile(np.linspace(0, 2 * np.pi, steps), N).reshape(N, steps)
    slicearray = ['l', 'l', 'l']

    wigner_analyt = np.zeros((steps, steps))
    for t in range(steps):
        for p in range(steps):
            wigner_analyt[t, p] = np.real(((1 + np.sqrt(3)*np.cos(theta[0, t]))
                                           * (1 + np.sqrt(3)
                                           * np.cos(theta[1, t]))
                                           * (1 + np.sqrt(3)
                                           * np.cos(theta[2, t]))
                                           + 3**(3 / 2) * (np.sin(theta[0, t])
                                           * np.exp(-1j * phi[0, p])
                                           * np.sin(theta[1, t])
                                           * np.exp(-1j * phi[1, p])
                                           * np.sin(theta[2, t])
                                           * np.exp(-1j * phi[2, p])
                                           + np.sin(theta[0, t])
                                           * np.exp(1j * phi[0, p])
                                           * np.sin(theta[1, t])
                                           * np.exp(1j * phi[1, p])
                                           * np.sin(theta[2, t])
                                           * np.exp(1j * phi[2, p]))
                                           + (1 - np.sqrt(3)
                                           * np.cos(theta[0, t]))
                                           * (1 - np.sqrt(3)
                                           * np.cos(theta[1, t]))
                                           * (1 - np.sqrt(3)
                                           * np.cos(theta[2, t]))) / 16.)

    wigner_theo = wigner_transform(psi, 0.5, False, steps, slicearray)

    assert_(np.sum(np.abs(wigner_analyt - wigner_theo)) < 1e-11)
Esempio n. 3
0
def test_wigner_pure_su2():
    """wigner: testing the SU2 wigner transformation of a pure state.
    """
    psi = (ket([1]))
    steps = 100
    theta = np.linspace(0, np.pi, steps)
    phi = np.linspace(0, 2 * np.pi, steps)
    theta = theta[None, :]
    phi = phi[None, :]
    slicearray = ['l']

    wigner_analyt = np.zeros((steps, steps))
    for t in range(steps):
        for p in range(steps):
            wigner_analyt[t, p] = (1 + np.sqrt(3) * np.cos(theta[0, t])) / 2.

    wigner_theo = wigner_transform(psi, 0.5, False, steps, slicearray)

    assert_(np.sum(np.abs(wigner_analyt - wigner_theo)) < 1e-11)
Esempio n. 4
0
def test_wigner_pure_su2():
    """wigner: testing the SU2 wigner transformation of a pure state.
    """
    psi = (ket([1]))
    steps = 100
    theta = np.linspace(0, np.pi, steps)
    phi = np.linspace(0, 2 * np.pi, steps)
    theta = theta[None, :]
    phi = phi[None, :]
    slicearray = ['l']

    wigner_analyt = np.zeros((steps, steps))
    for t in range(steps):
        for p in range(steps):
            wigner_analyt[t, p] = (1 + np.sqrt(3) * np.cos(theta[0, t])) / 2.

    wigner_theo = wigner_transform(psi, 0.5, False, steps, slicearray)

    assert_(np.sum(np.abs(wigner_analyt - wigner_theo)) < 1e-11)
Esempio n. 5
0
    def nr_anneal(self, schedule, init_state):
        """
        Performs a numeric reverse anneal on H using QuTip.

        inputs:
        ---------
        schedule - a numeric anneal schedule
        init_state - the starting state for the reverse anneal listed as string or list
        e.g. '111' or [010]

        outputs:
        ---------
        probs - probability of each output state as a list ordered in canconically w.r.t. tensor product
        """
        times, svals = schedule

        # create a numeric representation of H
        ABfuncs = time_interpolation(schedule, self.processordata)
        numericH = get_numeric_H(self)
        A = ABfuncs['A(t)']
        B = ABfuncs['B(t)']
        HX = numericH['HX']
        HZ = numericH['HZ']
        # Define list_H for QuTiP
        listH = [[HX, A], [HZ, B]]

        # create a valid QuTip initial state
        qubit_states = [qts.ket([int(i)]) for i in init_state]
        QuTip_init_state = qt.tensor(*qubit_states)

        # perform a numerical reverse anneal on H
        results = qt.sesolve(listH, QuTip_init_state, times)
        probs = np.array([
            abs(results.states[-1][i].flatten()[0])**2
            for i in range(self.Hsize)
        ])

        return probs
Esempio n. 6
0
    def frem_anneal(self, schedules, partition, HR_init_state):
        """
        Performs a numeric FREM anneal on H using QuTip.

        inputs:
        ---------
        schedules - a numeric annealing schedules [reverse, forward]
        partition - a parition of H in the form [HR, HF]
        init_state - the starting state for the reverse anneal listed as string or list
        e.g. '111' or [010]

        outputs:
        ---------
        probs - probability of each output state as a list ordered in canconically w.r.t. tensor product
        """

        # retrieve useful quantities from input data
        f_sch, r_sch = schedules
        times = f_sch[0]
        HR = DictRep(H=partition['HR'],
                     qpu='numerical',
                     vartype='ising',
                     encoding='logical')
        HF = DictRep(H=partition['HF'],
                     qpu='numerical',
                     vartype='ising',
                     encoding='logical')
        Rqubits = partition['Rqubits']

        # prepare the initial state
        statelist = []
        fidx = 0
        ridx = 0
        for qubit in self.qubits:
            # if part of HR, give assigned value by user
            if qubit in Rqubits:
                statelist.append(qts.ket(HR_init_state[ridx]))
                ridx += 1
            # otherwise, put in equal superposition (i.e. gs of x-basis)
            else:
                xstate = (qts.ket('0') - qts.ket('1')).unit()
                statelist.append(xstate)
                fidx += 1
        init_state = qto.tensor(*statelist)

        # Create the numeric Hamiltonian for HR
        ABfuncs = time_interpolation(r_sch, self.processordata)
        numericH = get_numeric_H(HR)
        A = ABfuncs['A(t)']
        B = ABfuncs['B(t)']
        HX = numericH['HX']
        HZ = numericH['HZ']
        # Define list_H for QuTiP
        listHR = [[HX, A], [HZ, B]]

        # create the numeric Hamiltonian for HF
        ABfuncs = time_interpolation(f_sch, self.processordata)
        numericH = get_numeric_H(HF)
        A = ABfuncs['A(t)']
        B = ABfuncs['B(t)']
        HX = numericH['HX']
        HZ = numericH['HZ']
        # "Analytic" or function H(t)
        analHF = lambda t: A(t) * HX + B(t) * HZ
        # Define list_H for QuTiP
        listHF = [[HX, A], [HZ, B]]

        # create the total Hamitlontian of HF + HR
        list_totH = listHR + listHF

        # run the numerical simulation and find probabilities of each state
        frem_results = qt.sesolve(list_totH, init_state, times)
        probs = np.array([
            abs(frem_results.states[-1][i].flatten()[0])**2
            for i in range(self.Hsize)
        ])

        return probs