def run():
    N = 101
    M = 101

    A_pow = np.zeros((M, N))
    A_mag = np.zeros((M, N))
    A_phase = np.zeros((M, N))

    phi = np.linspace(-0.20, -0.10, N)
    wd = (2 * np.pi) * np.linspace(5.5, 6.5, M)

    for j in range(N):
        print(j)
        H = TwoQubitNonLin_wInt(17.0, 16.0, 65e-15, 48.8e-15, 20.0, 40.0e-15,
                                phi[j])

        results = qt.parallel_map(task,
                                  wd,
                                  task_args=(H, c),
                                  progress_bar=True)
        results = np.array(results)
        A_pow[j, :] = results[:, 0]
        A_mag[j, :] = results[:, 1]
        A_phase[j, :] = results[:, 2]

    np.savetxt('Mag2D.txt', A_mag, fmt='%f', delimiter=',')
    np.savetxt('Phase2D.txt', A_phase, fmt='%f', delimiter=',')
    np.savetxt('Power2D.txt', A_pow, fmt='%f', delimiter=',')
    def run(self,parfunc,debug = False):
        # self.ask_for_setup_info()
        t0 = time.time()
        self.generate_parameter_space()

        # debugging
        if debug:
            parfunc(self.parameter_space[0])

        if not debug:
            raw_data = parallel_map(parfunc,self.parameter_space, progress_bar = True)
            self.set_simulation_data_path()
            self.save_dat(raw_data)
            self.generate_spyview_meta()
            p = self.open_spyview()
            t1 = time.time()
            self.generate_timing_info(t0,t1)

            response = self.ask_for_comments()
            if response == -1:
                os.kill(p.pid, signal.SIGINT)
                time.sleep(0.3)
                rmtree(self.simulation_data_path)
            else:
                self.end_comments = response
                self.ask_for_png() 
                self.save_meta()
                self.log_on_ppt()
                copyfile(os.path.join(self.manager_path,"settings.json"),
                        os.path.join(self.simulation_data_path,"settings.json"))
 def fexpt2(self):
     self.power_plot=True
     fexpt=parallel_map(self.funcer, self.value_grid2,  progress_bar=True)
     #print shape(self.value_grid2)
     #print self.pwr_arr.shape
     #print self.phi_arr.shape
     #print shape(fexpt)
     return reshape(fexpt, (len(self.pwr_arr), len(self.phi_arr)))
Exemple #4
0
 def fexpt2(self):
     self.power_plot = True
     fexpt = parallel_map(self.funcer, self.value_grid2, progress_bar=True)
     #print shape(self.value_grid2)
     #print self.pwr_arr.shape
     #print self.phi_arr.shape
     #print shape(fexpt)
     return reshape(fexpt, (len(self.pwr_arr), len(self.phi_arr)))
Exemple #5
0
def entanglement_fidelity(channel, subspace_basis, tlist, progress_bar=False):
    d = len(subspace_basis)
    u_basis = build_unitary_basis(subspace_basis)
    pure_state_basis, T = build_pure_state_basis(subspace_basis, u_basis)
    if progress_bar:
        F_e = sum(parallel_map(
            entanglement_fidelity_term,
            range(d**2), (channel, pure_state_basis, tlist, u_basis, d, T),
            progress_bar=True),
                  axis=0)
    else:
        F_e = sum(parallel_map(entanglement_fidelity_term, range(
            d**2), (channel, pure_state_basis, tlist, u_basis, d, T)),
                  axis=0)
    if any(imag(F_e) > 10**-12):
        warnings.warn(
            'I got a pretty large imaginary number when calculating entanglement fidelity. Are you sure your simulation function is correct?'
        )
    return real(F_e)
Exemple #6
0
def scan_laser_power(experiment,
                     start_power,
                     stop_power,
                     observables=None,
                     scan_laser='probe',
                     steps=100,
                     parallelize=False,
                     progress_bar=True):
    """Scans the frequency of a laser and returns transmission by default or user given observables

    :param parallelize: Use multiple cores to calculate
    :type parallelize: bool
    :param experiment: The experiment on which the scan is performed
    :type experiment: ntypecqed.simulation.NTypeExperiment
    :param start_power: Start power of power scan
    :type start_power: float
    :param stop_power: Stop power of power scan
    :type stop_power: float
    :param observables: Observables for which the steadystate is calculated
    :type observables: list of qutip.operator
    :param scan_laser: Which laser to scan, either *probe*, *signal* or *control*
    :type scan_laser: str
    :param steps: Number of steps
    :type steps: int
    :return: tuple(powers, list of lists of the steadystates of the observables)
    """

    laser_powers = {'probe': 'eta_p', 'signal': 'eta_s', 'control': 'omega_c'}
    powers = np.linspace(start_power, stop_power, steps)
    tmp_experiment = experiment.copy()

    try:
        power_scanned_laser = laser_powers[scan_laser]
    except KeyError:
        raise (KeyError,
               "No valid scan laser, must be one of signal, control, probe")

    if observables is None:
        observables = tmp_experiment.environment.n_a, tmp_experiment.environment.n_b
    if parallelize:
        steady_states = parallel_map(ss_power,
                                     powers,
                                     task_args=(experiment,
                                                power_scanned_laser),
                                     progress_bar=progress_bar)
    else:
        steady_states = serial_map(ss_power,
                                   powers,
                                   task_args=(experiment, power_scanned_laser),
                                   progress_bar=progress_bar)
    ob_results = []
    for result in steady_states:
        ob_results.append(tuple(expect(result, ob) for ob in observables))
    return powers, list(map(list, zip(*ob_results)))
Exemple #7
0
def scan_laser_freq(experiment,
                    start_freq,
                    stop_freq,
                    observables=None,
                    scan_laser='probe',
                    steps=100,
                    parallelize=False,
                    progress_bar=True):
    """Scans the frequency of a laser and returns transmission by default or user given observables

    :param parallelize: Use multiple cores to calculate
    :type parallelize: bool
    :param experiment: The experiment on which the scan is performed
    :type experiment: ntypecqed.simulation.NTypeExperiment
    :param start_freq: Start frequency of the scan
    :type start_freq: float
    :param stop_freq: Stop frequency of the scan
    :type stop_freq: float
    :param observables: Observables for which the steadystate is calculated
    :type observables: list(qutip.operator)
    :param scan_laser: Which laser to scan, either *probe*, *signal* or *control*
    :type scan_laser: str
    :param steps: Number of steps
    :type steps: int
    :return: tuple(frequencies, list of lists of the steadystates of the observables)
    """

    freqs = np.linspace(start_freq, stop_freq, steps)
    tmp_experiment = experiment.copy()
    if scan_laser in ['signal', 'control', 'probe']:
        scan_laser += '_detuning'
    else:
        raise (KeyError,
               "No valid scan laser, must be one of signal, control, probe")

    if observables is None:
        observables = tmp_experiment.environment.n_a, tmp_experiment.environment.n_b
    if parallelize:
        steady_states = parallel_map(ss_freq,
                                     freqs,
                                     task_args=(experiment, scan_laser),
                                     progress_bar=progress_bar)
    else:
        steady_states = serial_map(ss_freq,
                                   freqs,
                                   task_args=(experiment, scan_laser),
                                   progress_bar=progress_bar)
    ob_results = []
    for result in steady_states:
        ob_results.append(tuple(expect(result, ob) for ob in observables))
    return freqs, list(map(list, zip(*ob_results)))
Exemple #8
0
def generate_cut_states(fd_array, times, params, psi0=None, parallel=False, num_cpus=10, opt=None):
    task_args = (times,)
    task_kwargs = {'psi0': psi0, 'opt': opt}
    params_list = []
    for fd in fd_array:
        params_copy = deepcopy(params)
        params_copy.fd = fd
        params_list.append(params_copy)

    if parallel:
        results = parallel_map(generate_result_states, params_list, task_args=task_args, task_kwargs=task_kwargs,
                               num_cpus=num_cpus, progress_bar=True)
    else:
        results = [generate_result(p, *task_args, **task_kwargs) for p in params_list]

    results = pd.concat(results)

    return results
 def fexpt(self):
     self.power_plot=False
     fexpt=parallel_map(self.funcer, self.value_grid,  progress_bar=True)
     return reshape(fexpt, (len(self.frq_arr), len(self.phi_arr)))
Exemple #10
0
 def fexpt(self):
     fexpt = parallel_map(self.funcer, self.value_grid, progress_bar=True)
     return reshape(fexpt, (len(self.pwr_arr), len(self.phi_arr)))
    #Ej = Ejmax*absolute(cos(pi*phi)) #Josephson energy as function of Phi.

    #wTvec = -Ej + sqrt(8.0*Ej*Ec)*(nvec+0.5)+Ecvec

    #wT = wTvec-wdvec
    #transmon_levels = Qobj(diag(wT[range(N)]))
    #H=transmon_levels +Omega_op
    final_state = steadystate(H, c_op_list)

    return expect(a, final_state)


if 0:
    value_grid = array(meshgrid(phi_arr, Omega_sim_vec))
    vg = zip(value_grid[0, :, :].flatten(), value_grid[1, :, :].flatten())
    fexpt = parallel_map(find_expect, vg, progress_bar=True)
    fexpt = reshape(fexpt, (31, 101))
    pcolormesh(phi_arr, sample_power_sim_dBm, absolute(fexpt), cmap="RdBu_r")
    show()

#w01_vec(i) = wT_vec(2)- wT_vec(1); % Transition energies.
#w12_vec(i) = wT_vec(3)- wT_vec(2);
#w23_vec(i) = wT_vec(4)- wT_vec(3);
#w34_vec(i) = wT_vec(5)- wT_vec(4);
H = make_H(0.2, 190, 4000.0)
print H
L = liouvillian(H, c_op_list)
print L
tr_mat = tensor([qeye(n) for n in L.dims[0][0]])
print tr_mat
tr_vec = transpose(mat2vec(tr_mat.full()))
Exemple #12
0
# %%
if __name__ == '__main__':
    # Simple CR, in qubit 2 frame
    print('Calculate simple CR gate')
    result_down = CR(tlist_simple, psidown)
    result_up = CR(tlist_simple, psiup)
    # Save result to file
    print('Save data')
    data = np.vstack((tlist_simple, result_down, result_up))
    qt.file_data_store('CR0.dat', data, numtype='real')
    print('Finished')
    # Echoed CR, in qubit 2 frame
    print('Calculate echoed CR gate')
    print('|psi0> = |00>')
    result_down = \
        np.array(qt.parallel_map(CR_echo, tlist_echo, task_args=(psidown,),
                                 progress_bar=True)).T
    print('|psi0> = |10>')
    result_up = \
        np.array(qt.parallel_map(CR_echo, tlist_echo, task_args=(psiup,),
                                 progress_bar=True)).T
    print('Finished')
    # Save result to file
    print('Save data')
    data = np.vstack((tlist_echo, result_down, result_up))
    qt.file_data_store('CR2.dat', data, numtype='real')
    # %% Plot results
    data = qt.file_data_read('CR0.dat')
    tlist = data[0]
    result_down = data[1:7]
    result_up = data[7:13]
 def fexpt(self):
     fexpt=parallel_map(self.funcer, self.value_grid,  progress_bar=True)
     return reshape(fexpt, (len(self.pwr_arr), len(self.phi_arr)))
        #print "tm_l", tm_l.full().shape
        #print "Lint", Lint.shape
        #print "pl", p_l.full().shape
        #print "pr", p_r.full().shape
        #print rho.shape, to_super(rho_ss).full().shape
        #print "rho", to_super(rho_ss) #rho_ss.full().shape #rho.shape
        #print (tm_l.full()*Lint*(p_l.full() - p_r.full())*rho).shape
        #raise Exception
        return 1j*trace(tm_l*Lint*(p_l_m_p_r)*rho_ss)

value_grid=array(meshgrid(phi_arr, wd_vec))
vg=zip(value_grid[0, :, :].flatten(), value_grid[1, :, :].flatten())
print "1"
two_tone((0.23, 4000.0))
print "2"

fexpt=parallel_map(two_tone, vg,  progress_bar=True)
fexpt=reshape(fexpt, (len(wd_vec), len(phi_arr)))
pcolormesh(absolute(fexpt), cmap="RdBu_r")
colorbar()
show()
#arange(1,7).reshape(-1,2).transpose()
#        return (1.0/theta_steps)*1j*trace(reshape(tm_l*Lint*(p_l - p_r)*rho_ss_c,N,N))

#            Chi_temp(i,j) = Chi_temp(i,j) + (1/theta_steps)*1i*trace(reshape(tm_l*Lint*(p_l - p_r)*rho_ss_c,dim,dim));



#    r = (gamma/2)*Chi; % The reflection coefficient.
Exemple #15
0
 def fexpt(self):
     self.power_plot = False
     fexpt = parallel_map(self.funcer, self.value_grid, progress_bar=True)
     return reshape(fexpt, (len(self.frq_arr), len(self.phi_arr)))
# Construct all combinations of omegaD and omegaP for parallelization
omegazip = []
for omegaP in omegaPlist:
    omegazip.extend(zip(omegaDlist, np.repeat(omegaP, len(omegaDlist))))
# Divide into batches
bsize = 4 * len(omegaDlist)
nbatch = int(np.ceil(len(omegazip) / bsize))
filename = 'transSweep.dat'
result = []
# Run simulation and save data batch by batch
for ii in range(0, nbatch):
    print('Calculating batch %d of %d ...' % (ii + 1, nbatch))
    result.extend(
        qt.parallel_map(transmission,
                        omegazip[ii * bsize:(ii + 1) * bsize],
                        task_args=(ampD, ampP),
                        num_cpus=40,
                        progress_bar=True))
    qt.file_data_store(filename,
                       np.array(result).reshape((-1, 1)),
                       numtype='real')
    print('Saved to %s\n' % filename)

# Save data
# data is an numpy array with M rows and N columns
# M = len(omegaPlist)+1, N = len(omegaDlist)+1
# data[0, 1:] = omegaDlist, data[1:, 0] = omegaPlist
# data[1:, 1:] = transmission data
result = np.array(result).reshape((len(omegaPlist), len(omegaDlist)))
data = np.vstack((omegaDlist, result))
data = np.hstack((np.append([0], omegaPlist).reshape(-1, 1), data))
def expect_update(Omega):
    tstart=time()
    Omega_vec=- 0.5j*(Omega*adag - conj(Omega)*a)
    fexp=parallel_map(find_expect, phi_arr, task_kwargs=dict(Omega_vec=Omega_vec))# for phi in phi_arr]
    print time()-tstart
    return fexp
    H=transmon_levels +Omega_vec #- 0.5j*(Omega_true*adag - conj(Omega_true)*a)
    final_state = steadystate(H, c_op_list) #solve master equation

    return expect( a, final_state) #expectation value of relaxation operator
    #Omega=\alpha\sqrt{2\Gamma_10} where |\alpha|^2=phonon flux=number of phonons per second
    #Omega=2\alpha\sqrt{\gamma} where |\alpha|^2=phonon flux=number of phonons per second

def expect_update(Omega):
    tstart=time()
    Omega_vec=- 0.5j*(Omega*adag - conj(Omega)*a)
    fexp=parallel_map(find_expect, phi_arr, task_kwargs=dict(Omega_vec=Omega_vec))# for phi in phi_arr]
    print time()-tstart
    return fexp

vg=zip(value_grid[0, :, :].flatten(), value_grid[1, :, :].flatten())
fexpt=parallel_map(find_expect, vg,  progress_bar=True)
fexpt=reshape(fexpt, (31, 101))
#fexpt=[expect_update(Omega) for Omega in Omega_sim_vec]

#fexpt=[[find_expect(phi, Omega) for phi in phi_arr] for Omega in Omega_sim_vec]
#print fexpt
pcolormesh(phi_arr, sample_power_sim_dBm, absolute(fexpt), cmap="RdBu_r")
figure()
pcolormesh(absolute(fexpt), cmap="RdBu_r")
figure()
plot(sample_power_sim_dBm, absolute(fexpt)[:, 77])

figure()
plot(sample_power_sim_dBm, 20*log10(absolute(fexpt)[:, 77])-sample_power_sim_dBm)
figure()
plot(sample_power_sim_dBm, 10**((20*log10(absolute(fexpt)[:, 77])-sample_power_sim_dBm)/10.0))