Beispiel #1
0
    def test_filter_functions(self):

        # Basis for qubit subspace
        qubit_subspace_basis = ff.Basis(
            [np.pad(b, 1, 'constant') for b in ff.Basis.pauli(2)],
            skip_check=True,
            btype='Pauli')

        c_opers = ff_testutil.subspace_opers
        n_opers = c_opers
        c_coeffs, n_coeffs = ff_testutil.c_coeffs, ff_testutil.n_coeffs
        dt = ff_testutil.dt
        infid_MC = ff_testutil.cnot_infid_fast
        A = ff_testutil.A

        identifiers = ['eps_12', 'eps_23', 'eps_34', 'b_12', 'b_23', 'b_34']
        H_c = list(
            zip(c_opers[:3] + [c_opers[3] + 7 * c_opers[4] - c_opers[5]],
                c_coeffs[:3] + [c_coeffs[3]], identifiers[:4]))
        H_n = list(zip(n_opers[:3], n_coeffs[:3], identifiers[:3]))
        cnot = ff.PulseSequence(H_c, H_n, dt, basis=qubit_subspace_basis)

        T = dt.sum()
        omega = np.logspace(np.log10(1 / T), 2, 125)
        S_t, omega_t = ff.util.symmetrize_spectrum(A[0] / omega**0.0, omega)
        infid, xi = ff.infidelity(cnot,
                                  S_t,
                                  omega_t,
                                  identifiers[:3],
                                  return_smallness=True)
        # infid scaled with d = 6, but we actually have d = 4
        infid *= 1.5
        self.assertLessEqual(np.abs(1 - (infid.sum() / infid_MC[0])), .4)
        self.assertLessEqual(infid.sum(), xi**2 / 4)

        time_slot_comp_closed = SchroedingerSolver(
            h_drift=[OPERATORS['h_drift']] * len(dt),
            h_ctrl=OPERATORS['h_ctrl'],
            initial_state=OPERATORS['initial_state'],
            tau=list(dt),
            calculate_propagator_derivatives=True,
            exponential_method='spectral',
            is_skew_hermitian=True,
            transfer_function=id_tf,
            amplitude_function=exp_amp_func,
            filter_function_h_n=H_n,
            filter_function_basis=qubit_subspace_basis)
        time_slot_comp_closed.set_optimization_parameters(eps.T)

        ff_infid = OperatorFilterFunctionInfidelity(
            solver=time_slot_comp_closed,
            noise_power_spec_density=S_t,
            omega=omega_t)
        print(ff_infid.grad())
        np.testing.assert_array_almost_equal(infid, ff_infid.costs() * 1.5)
Beispiel #2
0
    def quasi_static_noise(self):

        sigma_z = DenseOperator(np.asarray([[1, 0], [0, -1]]))
        sigma_x = DenseOperator(np.asarray([[0, 1], [1, 0]]))
        h_drift = DenseOperator(np.zeros((2, 2)))

        # reference_frequency = 20e9 * 2 * np.pi
        reference_frequency = 100e6 * 2 * np.pi
        driving_frequency = 1e6 * 2 * np.pi

        # 100 per reference period
        # int(reference_frequency / driving_frequency) to make one driving period
        # 20 driving periods
        n_time_steps = int(35 * reference_frequency / driving_frequency * 20)
        n_noise_traces = 100  # int(10 * 60 * 1e6 / 35)
        evolution_time = 35e-6

        delta_t = evolution_time / n_time_steps

        down = np.asarray([[0], [1]])
        up = np.asarray([[1], [0]])
        x_half = rabi.x_half.data

        projector_left = up.T
        projector_right = up

        def up_amplitude(unitary):
            probability = projector_left @ unitary.data @ projector_right
            return np.abs(probability) ** 2

        ctrl_amps = delta_t * np.arange(1, 1 + n_time_steps)
        ctrl_amps = driving_frequency * np.sin(reference_frequency * ctrl_amps)


        def rabi_driving(transferred_parameters, **_):
            ctrl_amps = delta_t * np.arange(1, 1 + n_time_steps)
            ctrl_amps = 2 * np.sin(reference_frequency * ctrl_amps)
            # times 2 because the rabi frequency is .5 * Amplitude
            ctrl_amps = np.einsum("tc, t->tc", transferred_parameters, ctrl_amps)
            return ctrl_amps


        def rabi_driving_noise(noise_samples, **_):
            ctrl_amps = delta_t * np.arange(1, 1 + n_time_steps)
            ctrl_amps = 2 * np.sin(reference_frequency * ctrl_amps)
            ctrl_amps = np.einsum("sno, t->tno", noise_samples, ctrl_amps)
            return ctrl_amps


        rabi_driving_amp_func = CustomAmpFunc(value_function=rabi_driving,
                                              derivative_function=None)
        id_transfer_func = OversamplingTF(oversampling=n_time_steps)
        id_transfer_func.set_times(np.asarray([evolution_time]))


        ts_comp_unperturbed = SchroedingerSolver(
            h_drift=[reference_frequency * .5 * sigma_z, ] * n_time_steps,
            h_ctrl=[.5 * sigma_x, ],
            initial_state=DenseOperator(np.eye(2)),
            tau=[delta_t, ] * n_time_steps,
            exponential_method='Frechet',

        )

        ts_comp_lindblad = LindbladSolver(
            h_drift=[reference_frequency * .5 * sigma_z, ] * n_time_steps,
            h_ctrl=[.5 * sigma_x, ],
            initial_state=DenseOperator(np.eye(2)),
            tau=[delta_t, ] * n_time_steps,
            exponential_method='Frechet'
        )

        ts_comp_unperturbed.set_optimization_parameters(np.expand_dims(ctrl_amps, 1))


        """
        # unperturbed:
        forward_propagators = ts_comp_unperturbed.forward_propagators
        
        propabilities = np.zeros((n_time_steps, ))
        for j in range(n_time_steps):
            propabilities[j] = up_amplitude(forward_propagators[j])
        
        plt.figure()
        plt.plot(delta_t * np.arange(n_time_steps), propabilities)
        """

        # Tom
        # todo: he seems to assume angular frequencies in his spectrum
        S_01 = 3e8
        S_02 = 3e4
        # S(f) = S_01 / f + S_02 / f^2

        f_min = 1 / 10 / 60  # 1 over 10 minutes
        f_max = 1 / 35e-6

        variance_f = S_01 * (np.log(f_max) - np.log(f_min)) \
            - S_02 * (1 / f_max - 1 / f_min)
        sigma_f = np.sqrt(variance_f)


        """
        # Yoneda
        S_0 = 3.2 * 1e6 * 4 * np.pi * np.pi
        
        f_min = 1e-2
        f_max = 1 / 35e-6
        
        variance_f = S_0 * (np.log(f_max) - np.log(f_min))
        sigma_f = np.sqrt(variance_f)  # 29 kHz
        """
        expected_t2star = np.sqrt(2 / variance_f)

        ntg = NTGQuasiStatic(
            standard_deviation=[sigma_f, ],
            n_samples_per_trace=1,
            n_traces=n_noise_traces,
            always_redraw_samples=False,
            sampling_mode='monte_carlo'
        )


        tslot_comp = SchroedingerSMonteCarlo(
            h_drift=[reference_frequency * .5 * sigma_z, ] * n_time_steps,
            h_ctrl=[.5 * sigma_x, ],
            h_noise=[.5 * sigma_x],
            initial_state=DenseOperator(np.eye(2)),
            tau=[delta_t, ] * n_time_steps,
            noise_trace_generator=ntg,
            exponential_method='Frechet',
            transfer_function=id_transfer_func,
            amplitude_function=rabi_driving_amp_func,
            noise_amplitude_function=rabi_driving_noise
        )

        """
        # for the rotating frame
        delta_rabi = 1.5 / 10 * 1e6
        tslot_comp.set_optimization_parameters(
            (2 * np.pi * delta_rabi) * np.ones((n_time_steps, 1)))
        """
        tslot_comp.set_optimization_parameters(np.asarray([[driving_frequency]]))

        forward_propagators = tslot_comp.forward_propagators_noise

        propabilities = np.zeros((n_noise_traces, n_time_steps))
        for i in range(n_noise_traces):
            for j in range(n_time_steps):
                propabilities[i, j] = up_amplitude(forward_propagators[i][j])

        propabilities = np.mean(propabilities, axis=0)

        """
        def t2star_decay(t, delta_f, t2_star):
            return .5 * np.exp(-(t / t2_star) ** 2) * np.cos(
                2 * np.pi * delta_f * t) + .5
        """


        def t2star_decay(t, sigma_driving):
            return .5 * np.exp(-.5 * (sigma_driving * t) ** 2) * np.cos(driving_frequency * t) + .5


        def t2star_decay_2(t, sigma_driving):
            return .5 * (1 + (sigma_driving ** 2 / driving_frequency * t)) ** -.25 * np.cos(driving_frequency * t) + .5


        def t2star_decay_3(t, sigma_driving, sigma_ref):
            up_prop = np.exp(-.5 * (sigma_driving * t) ** 2)
            up_prop *= (1 + (sigma_ref ** 2 / driving_frequency * t) ** 2) ** -.25
            up_prop *= .5 * np.cos(driving_frequency * t)
            up_prop += .5
            return up_prop


        def t2star_decay_4(t, sigma_driving, sigma_ref, periodicity):
            up_prop = np.exp(-.5 * (sigma_driving * t) ** 2)
            up_prop *= (1 + ((sigma_ref ** 2) / periodicity * t) ** 2) ** -.25
            up_prop *= .5 * np.cos(periodicity * t)
            up_prop += .5
            return up_prop


        def t2star_decay_5(t, sigma_driving, sigma_ref, periodicity, lin_decay):
            up_prop = np.exp(-.5 * (sigma_driving * t) ** 2)
            up_prop *= np.exp(-1 * lin_decay * t)
            up_prop *= (1 + ((sigma_ref ** 2) / periodicity * t) ** 2) ** -.25
            up_prop *= .5 * np.cos(periodicity * t)
            up_prop += .5
            return up_prop


        popt, pcov = scipy.optimize.curve_fit(
            t2star_decay_3,
            xdata=delta_t * np.arange(n_time_steps),
            ydata=propabilities,
            p0=np.asarray([sigma_f, sigma_f])
        )


        popt, pcov = scipy.optimize.curve_fit(
            t2star_decay_5,
            xdata=delta_t * np.arange(n_time_steps),
            ydata=propabilities,
            p0=np.asarray([sigma_f, sigma_f, driving_frequency, sigma_f])
        )

        self.assertLess(np.linalg.norm(
            propabilities - t2star_decay(delta_t * np.arange(n_time_steps),
                           sigma_driving=sigma_f)) / len(propabilities), 1e-3)

        """
from qopt.solver_algorithms import SchroedingerSolver
from qopt.cost_functions import StateInfidelity
from qopt.simulator import Simulator

sigma_x = DenseOperator(np.asarray([[0, 1], [1, 0]]))
sigma_y = DenseOperator(np.asarray([[0, -1j], [1j, 0]]))
sigma_z = DenseOperator(np.asarray([[1, 0], [0, -1]]))

n_time_steps = 5
delta_t = .5 * np.pi

up = DenseOperator(np.asarray([[1], [0]]))
down = DenseOperator(np.asarray([[0], [1]]))

schroedinger_solver = SchroedingerSolver(h_drift=[0 * sigma_x] * n_time_steps,
                                         h_ctrl=[sigma_x, sigma_y],
                                         tau=delta_t * np.ones(n_time_steps),
                                         initial_state=up)


class TestFidelitySchroedingerEq(unittest.TestCase):
    def test_state_fid(self):
        cost_fkt = StateInfidelity(schroedinger_solver, target=down)

        simulator = Simulator(solvers=[
            schroedinger_solver,
        ],
                              cost_fktns=[
                                  cost_fkt,
                              ])

        np.random.seed(0)
Beispiel #4
0
                                  always_redraw_samples=False,
                                  sampling_mode='uncorrelated_deterministic')

# ##################### 7. Time Slot Computer #################################
# The time slot computer calculates the evolution of the qubit taking into
# account the amplitude and transfer function and also the noise traces if
# required.

# 7.1 xy-control
solver_unperturbed_xy = SchroedingerSolver(
    h_drift=[
        0 * h_drift,
    ],
    h_ctrl=h_ctrl,
    initial_state=DenseOperator(np.eye(2)),
    tau=[
        time_step,
    ] * n_time_samples,
    is_skew_hermitian=True,
    exponential_method=exponential_method,
    transfer_function=exponential_transfer_function,
    amplitude_function=lin_amp_func)

solver_qs_noise_xy = SchroedingerSMonteCarlo(
    h_drift=[
        0 * h_drift,
    ],
    h_ctrl=h_ctrl,
    h_noise=[
        h_drift,
    ],
Beispiel #5
0
def create_discrete_classes(n_bit_ph: int, n_bit_amp: int):
    n_max_phase = 2**n_bit_ph - 1
    delta_phase = phase_max / n_max_phase * np.pi / 180

    # 2.2: from our group
    amp_bound = rabi_frequency_max * 2 * np.pi / lin_freq_rel

    n_max_amp = 2**n_bit_amp - 1
    delta_amp = amp_bound / n_max_amp

    discrete_tf_phase = LinearTF(oversampling=1,
                                 bound_type=None,
                                 num_ctrls=1,
                                 linear_factor=delta_phase)

    discrete_tf_amp = LinearTF(oversampling=1,
                               bound_type=None,
                               num_ctrls=1,
                               linear_factor=delta_amp)

    discrete_tf = ParallelTF(tf1=discrete_tf_amp, tf2=discrete_tf_phase)

    total_tf = ConcatenateTF(tf1=discrete_tf,
                             tf2=exponential_transfer_function)
    total_tf.set_times(time_step * np.ones(n_time_samples))

    ts_comp_unperturbed_pc_discrete = SchroedingerSolver(
        h_drift=[
            0 * h_drift,
        ] * n_time_samples * oversampling,
        h_ctrl=h_ctrl,
        initial_state=DenseOperator(np.eye(2)),
        tau=[
            time_step / oversampling,
        ] * n_time_samples * oversampling,
        is_skew_hermitian=True,
        exponential_method=exponential_method,
        transfer_function=total_tf,
        amplitude_function=phase_ctrl_amp_func)

    time_slot_comp_qs_noise_pc_discrete = SchroedingerSMonteCarlo(
        h_drift=[
            0 * h_drift,
        ] * n_time_samples * oversampling,
        h_ctrl=h_ctrl,
        h_noise=[
            h_drift,
        ],
        noise_trace_generator=ntg_quasi_static,
        initial_state=DenseOperator(np.eye(2)),
        tau=[
            time_step / oversampling,
        ] * n_time_samples * oversampling,
        is_skew_hermitian=True,
        exponential_method=exponential_method,
        transfer_function=total_tf,
        amplitude_function=phase_ctrl_amp_func)

    qs_noise_pc_discrete = OperationNoiseInfidelity(
        solver=time_slot_comp_qs_noise_pc_discrete,
        target=x_half,
        fidelity_measure='entanglement',
        index=['Entanglement Fidelity QS-Noise Phase Control'],
        neglect_systematic_errors=True)

    entanglement_infid_pc_discrete = OperationInfidelity(
        solver=ts_comp_unperturbed_pc_discrete,
        target=x_half,
        fidelity_measure='entanglement',
        index=['Entanglement Fidelity Phase Control'])

    return [ts_comp_unperturbed_pc_discrete,
            time_slot_comp_qs_noise_pc_discrete], \
           [entanglement_infid_pc_discrete, qs_noise_pc_discrete]