def test_operator_at_cells(self): p_2222 = qutip.Lattice1d(num_cell=2, boundary="periodic", cell_num_site=2, cell_site_dof=[2, 2]) op_0 = qutip.projection(2, 0, 1) op_c = qutip.tensor(op_0, qutip.qeye([2, 2])) OP = p_2222.operator_between_cells(op_c, 1, 0) T = qutip.projection(2, 1, 0) QP = qutip.tensor(T, op_c) assert OP == QP
def _hamiltonian_expected(cells, periodic, sites_per_cell, freedom): """Expected Hamiltonian for the simple 1D lattice model""" # Within the cell, adjacent sites hop to each other, and it's always # non-periodic. cell = qutip.qdiags([-np.ones(sites_per_cell - 1)]*2, [1, -1]) # To hop to the cell one to the left, then you have to drop from the lowest # in-cell location to the highest in the other. hop_left = qutip.qdiags(np.ones(cells - 1), 1) if periodic and cells > 2: # If cells <= 2 then all cells border each other anyway. hop_left += qutip.qdiags([1], -(cells - 1)) drop_site = -qutip.projection(sites_per_cell, sites_per_cell-1, 0) if np.prod(freedom) != 1: # Degenerate degrees of freedom per lattice site are unchanged. identity = qutip.qeye(freedom) cell = qutip.tensor(cell, identity) drop_site = qutip.tensor(drop_site, identity) out = (qutip.tensor(qutip.qeye(cells), cell) + qutip.tensor(hop_left, drop_site) + qutip.tensor(hop_left, drop_site).dag()) # Contract scalar spaces. dims = [x for x in [cells, sites_per_cell] + freedom if x != 1] dims = dims or [1] out.dims = [dims, dims] return out
def projection_operators(self): """ Defines projection operators. """ s = [[ qt.projection(self.N_levels, i, j) for i in range(self.N_levels) ] for j in range(self.N_levels)] return s
def test_coefficient_c_ops_3ls(self, dependence_3ls): # Calculate zero-delay HOM cross-correlation for incoherently pumped # three-level system, g2_ab[0] with gamma = 1. dimension = 3 H = qutip.qzero(dimension) start = qutip.basis(dimension, 2) times = _3ls_times project_0_1 = qutip.projection(dimension, 0, 1) project_1_2 = qutip.projection(dimension, 1, 2) population_1 = qutip.projection(dimension, 1, 1) # Define the pi pulse to be when 99% of the population is transferred. rabi = np.sqrt(-np.log(0.01) / (_3ls_args['tp'] * np.sqrt(np.pi))) c_ops = [project_0_1, [rabi * project_1_2, dependence_3ls]] forwards = qutip.correlation_2op_2t(H, start, times, times, c_ops, project_0_1.dag(), project_0_1, args=_3ls_args) backwards = qutip.correlation_2op_2t(H, start, times, times, c_ops, project_0_1.dag(), project_0_1, args=_3ls_args, reverse=True) n_expect = qutip.mesolve(H, start, times, c_ops, args=_3ls_args, e_ops=[population_1]).expect[0] correlation_ab = -forwards * backwards + _n_correlation( times, n_expect) g2_ab_0 = _trapz_2d(np.real(correlation_ab), times) assert abs(g2_ab_0 - 0.185) < 1e-2
def test_dqd_current(): "Counting statistics: current and current noise in a DQD model" G = 0 L = 1 R = 2 sz = qutip.projection(3, L, L) - qutip.projection(3, R, R) sx = qutip.projection(3, L, R) + qutip.projection(3, R, L) sR = qutip.projection(3, G, R) sL = qutip.projection(3, G, L) w0 = 1 tc = 0.6 * w0 GammaR = 0.0075 * w0 GammaL = 0.0075 * w0 nth = 0.00 eps_vec = np.linspace(-1.5 * w0, 1.5 * w0, 20) J_ops = [GammaR * qutip.sprepost(sR, sR.dag())] c_ops = [ np.sqrt(GammaR * (1 + nth)) * sR, np.sqrt(GammaR * (nth)) * sR.dag(), np.sqrt(GammaL * (nth)) * sL, np.sqrt(GammaL * (1 + nth)) * sL.dag() ] current = np.zeros(len(eps_vec)) noise = np.zeros(len(eps_vec)) for n, eps in enumerate(eps_vec): H = (eps / 2 * sz + tc * sx) L = qutip.liouvillian(H, c_ops) rhoss = qutip.steadystate(L) current[n], noise[n] = qutip.countstat_current_noise(L, [], rhoss=rhoss, J_ops=J_ops) current2 = qutip.countstat_current(L, rhoss=rhoss, J_ops=J_ops) assert abs(current[n] - current2) < 1e-8 current2 = qutip.countstat_current(L, c_ops, J_ops=J_ops) assert abs(current[n] - current2) < 1e-8 current_target = (tc**2 * GammaR / (tc**2 * (2 + GammaR / GammaL) + GammaR**2 / 4 + eps_vec**2)) noise_target = current_target * ( 1 - (8 * GammaL * tc**2 * (4 * eps_vec**2 * (GammaR - GammaL) + GammaR * (3 * GammaL * GammaR + GammaR**2 + 8 * tc**2)) / (4 * tc**2 * (2 * GammaL + GammaR) + GammaL * GammaR**2 + 4 * eps_vec**2 * GammaL)**2)) np.testing.assert_allclose(current, current_target, atol=1e-4) np.testing.assert_allclose(noise, noise_target, atol=1e-4)
def test_dqd_current(): "Counting statistics: current and current noise in a DQD model" G = 0 L = 1 R = 2 sz = projection(3, L, L) - projection(3, R, R) sx = projection(3, L, R) + projection(3, R, L) sR = projection(3, G, R) sL = projection(3, G, L) w0 = 1 tc = 0.6 * w0 GammaR = 0.0075 * w0 GammaL = 0.0075 * w0 nth = 0.00 eps_vec = np.linspace(-1.5*w0, 1.5*w0, 20) J_ops = [GammaR * sprepost(sR, sR.dag())] c_ops = [np.sqrt(GammaR * (1 + nth)) * sR, np.sqrt(GammaR * (nth)) * sR.dag(), np.sqrt(GammaL * (nth)) * sL, np.sqrt(GammaL * (1 + nth)) * sL.dag(), ] I = np.zeros(len(eps_vec)) S = np.zeros(len(eps_vec)) for n, eps in enumerate(eps_vec): H = (eps/2 * sz + tc * sx) L = liouvillian(H, c_ops) rhoss = steadystate(L) I[n], S[n] = countstat_current_noise(L, [], rhoss=rhoss, J_ops=J_ops) I2 = countstat_current(L, rhoss=rhoss, J_ops=J_ops) assert_(abs(I[n] - I2) < 1e-8) I2 = countstat_current(L, c_ops, J_ops=J_ops) assert_(abs(I[n] - I2) < 1e-8) Iref = tc**2 * GammaR / (tc**2 * (2 + GammaR/GammaL) + GammaR**2/4 + eps_vec**2) Sref = 1 * Iref * ( 1 - 8 * GammaL * tc**2 * (4 * eps_vec**2 * (GammaR - GammaL) + GammaR * (3 * GammaL * GammaR + GammaR**2 + 8*tc**2)) / (4 * tc**2 * (2 * GammaL + GammaR) + GammaL * GammaR**2 + 4 * eps_vec**2 * GammaL)**2 ) assert_allclose(I, Iref, 1e-4) assert_allclose(S, Sref, 1e-4)
def test_implicit_tensor_projection(size, n, m): implicit = qutip.projection(size, n, m) explicit = qutip.tensor( *[qutip.projection(ss, nn, mm) for ss, nn, mm in zip(size, n, m)]) assert implicit == explicit
def vicinity_ideal_test(data_file=None, method="ezhov", approx_scheme="approx"): """Vicinity test Match with a distributed query of one target, iterating over number of qubits, filling of database, as well as averaging over random choices of marked state. Include states in memory, which are at least a hamming distance 3 away from mark and also a certain percentage of states within a specified distance from target. Use real heuristics instead of ideal matching prob search. """ max_bits = 9 # maximum number of qubits n_bits = np.arange(4, max_bits + 1) n_nums = len(n_bits) number_of_marks = 10 # number of random marks to test for max_dist = 3 distances = np.arange( 1, max_dist + 1) # the distance at which to put the target memory state ratio_vals = 4 # number of ratio parameters to test for mark_ratio_vals = 10 ratio_range = np.linspace(0.1, 0.9, ratio_vals) mark_ratios = np.linspace(0.1, 0.9, mark_ratio_vals) peak_factor = 0.4 # 0 is a delta peak at mark amp_ratio = 0.1 data_struct = (n_nums, number_of_marks, len(mark_ratios), ratio_vals, len(distances)) ventura_probs = np.zeros(data_struct) ventura_prob_inds = np.zeros(data_struct) target_failure_probs = np.zeros(data_struct) memory_failure_probs = np.zeros(data_struct) # trugenberg_probs = np.zeros((n_nums, number_of_marks, ratio_vals)) for i1 in range(len(n_bits)): # iterate number of bits n = n_bits[i1] N = 2**n mark_num = min(N, number_of_marks) # number of marks to test for i2 in range(number_of_marks): # iterate number of marks mark = np.random.randint(0, N) for dist_ind in range(len(distances)): target_dist = distances[dist_ind] max_dist = target_dist if target_dist >= N: continue possible_states = [i for i in range(N)] dist_states = set() mark_projector = qu.Qobj() i = 0 while i < len(possible_states): if hamm_dist(possible_states[i], mark) <= target_dist: dist_states.add(possible_states.pop(i)) elif hamm_dist(possible_states[i], mark) <= max_dist: possible_states.pop(i) else: i += 1 mem_states = set() for mark_ratio_ind in range(len(mark_ratios)): # prepare target states and projector mark_ratio = mark_ratios[mark_ratio_ind] target_states = set() possible_targets = dist_states.copy() target_num = int(len(possible_targets) * mark_ratio) if target_num < 1: target_num = 1 mark_projector = qu.Qobj() for i in range(target_num): state = possible_targets.pop() target_states.add(state) mark_projector += qu.projection(N, state, state) for i3 in range(len(ratio_range)): # iterate ratios ratio = ratio_range[i3] # create memory list mem_states = target_states.copy() # number of memory states available_states = possible_states.copy() N_mem = int(np.ceil(ratio * len(available_states))) for j in range(N_mem): # add random memories num_ind = np.random.randint( 0, len(available_states)) add_state = available_states.pop(num_ind) mem_states.add(add_state) # create memory projector mem_projector = qu.Qobj() for mem in mem_states: mem_projector += qu.projection(N, mem, mem) # Create complement (spurious) projector to memory non_mem_projector = qu.identity(N) - mem_projector non_target_mem_projector = mem_projector - mark_projector # make query and memory list query = [int_to_bitstr(i, n) for i in range(N)] weights = np.zeros(N) for i in range(N): dist = hamm_dist(i, mark) if dist <= max_dist: weights[i] = np.sqrt( (peak_factor)**dist * (1 - peak_factor)**(n - dist)) weights[mark] = 0 n_zero = len(weights[weights == 0]) weights[weights == 0] = np.sqrt( np.sum(weights**2) * amp_ratio / (1 - amp_ratio)) / n_zero # print(weights) # query_weights = [peak_factor/q_N if i in marks else (1-peak_factor)/(N-q_N) for i in range(N)] memory = [int_to_bitstr(mem, n) for mem in mem_states] # mark_list = [int_to_bitstr(mark, n) for mark in marks] # initialize QuAM ventura = Ventura_QuAM.QuAM() ventura.set_mem(memory) ventura.set_query( query, weights=weights) #bin_param=peaking_factor) ventura.set_oracle() ventura.set_diffusion() # print("memory:", memory) print("query:", format(mark, "0" + str(n) + "b")) # perform matching repeat_case = True iteration_cap = int(np.ceil(np.sqrt(N))) iteration_limit = iteration_cap if method == "ezhov": _, ventura_states = ventura.match_ezhov( iteration=approx_scheme) if method == "improved": _, ventura_states = ventura.match_C1( iteration=approx_scheme) # gather probabilites success_prob = (mark_projector * ventura_states[-1]).norm()**2 max_prob_ind = len(ventura_states) good_failure_prob = (non_target_mem_projector * ventura_states[-1]).norm()**2 bad_failure_prob = (non_mem_projector * ventura_states[-1]).norm()**2 print( "n ratio mark_ratio dist prob fail_prob bad_fail ind" ) print(n, format(ratio, "0.3f"), format(mark_ratio, "0.3f"), target_dist, format(success_prob, "0.4f"), format(good_failure_prob, "0.4f"), format(bad_failure_prob, "0.4f"), max_prob_ind) # if max_prob < 0.9: # plt.plot(success_probs) # plt.show() ventura_probs[i1, i2, mark_ratio_ind, i3, dist_ind] = success_prob target_failure_probs[i1, i2, mark_ratio_ind, i3, dist_ind] = good_failure_prob memory_failure_probs[i1, i2, mark_ratio_ind, i3, dist_ind] = bad_failure_prob ventura_prob_inds[i1, i2, mark_ratio_ind, i3, dist_ind] = max_prob_ind # save results if data_file is None: data_file = "data" np.savez(data_file, bits=n_bits, ratios=ratio_range, mark_ratios=mark_ratios, peak_factor=np.array([peak_factor]), amp_ratio=np.array([amp_ratio]), distances=distances, values=ventura_probs, good_failure=target_failure_probs, bad_failure=memory_failure_probs, inds=ventura_prob_inds)