def test_bell_perm(): assert [len(generate_bell(i)) for i in xrange(1, 7)] == [1, 2, 5, 15, 52, 203] assert list(generate_bell(4)) == [(0, 1, 2, 3), (0, 1, 3, 2), (0, 2, 1, 3), (0, 3, 1, 2), (0, 3, 2, 1), (1, 0, 2, 3), (1, 0, 3, 2), (2, 0, 1, 3), (2, 1, 0, 3), (2, 3, 0, 1), (3, 0, 1, 2), (3, 0, 2, 1), (3, 1, 0, 2), (3, 1, 2, 0), (3, 2, 1, 0)]
def test_bell_perm(): assert [len(set(generate_bell(i))) for i in range(1, 7)] == [factorial(i) for i in range(1, 7)] assert list(generate_bell(3)) == [(0, 1, 2), (0, 2, 1), (2, 0, 1), (2, 1, 0), (1, 2, 0), (1, 0, 2)] # generate_bell and trotterjohnson are advertised to return the same # permutations; this is not technically necessary so this test could # be removed for n in range(1, 5): p = Permutation(range(n)) b = generate_bell(n) for bi in b: assert bi == tuple(p.array_form) p = p.next_trotterjohnson() raises(ValueError, lambda: list(generate_bell(0))) # XXX is this consistent with other permutation algorithms?
def test_bell_perm(): assert [len(set(generate_bell(i))) for i in range(1, 7)] == [ factorial(i) for i in range(1, 7)] assert list(generate_bell(3)) == [ (0, 1, 2), (0, 2, 1), (2, 0, 1), (2, 1, 0), (1, 2, 0), (1, 0, 2)] # generate_bell and trotterjohnson are advertised to return the same # permutations; this is not technically necessary so this test could # be removed for n in range(1, 5): p = Permutation(range(n)) b = generate_bell(n) for bi in b: assert bi == tuple(p.array_form) p = p.next_trotterjohnson() raises(ValueError, lambda: list(generate_bell(0))) # XXX is this consistent with other permutation algorithms?
def test_bell_perm(): assert [len(list(generate_bell(i))) for i in xrange(1, 7)] == [factorial(i) for i in xrange(1, 7)] assert list(generate_bell(3)) == [(0, 1, 2), (1, 0, 2), (1, 2, 0), (2, 1, 0), (2, 0, 1), (0, 2, 1)]
def test_bell_perm(): assert [len(list(generate_bell(i))) for i in xrange(1, 7)] == [ factorial(i) for i in xrange(1, 7)] assert list(generate_bell(3)) == [ (0, 1, 2), (1, 0, 2), (1, 2, 0), (2, 1, 0), (2, 0, 1), (0, 2, 1)]
def q_instability_psi(n_qubits, n_ones): # from Phys. Rev. A 79, 022302 , eq. 4 S = lambda k, l: np.sqrt(2 / (n_qubits + 1)) * np.sin(np.pi * (k + 1) * (l + 1) / (n_qubits + 1)) ## generate unnormalized dicke state with (n_qubits, k). n_zeros = n_qubits - n_ones # initialize vector with n_zeros of zeros and n_ones of ones zeros_int = [0 for _ in range(n_zeros)] ones_int = [1 for _ in range(n_ones)] statevector_init_int = zeros_int + ones_int # generate all permutations statevect_permutations_int = multiset_permutations(statevector_init_int) # generate a list of combinations of flipped spin locations for a given number of spins ls = [list(np.nonzero(row)[0]) for row in list(statevect_permutations_int)] ls = np.array(ls) # generate a permutation group for number of spins #ks = list(multiset_permutations(list(range(n_ones)))) ks = list(generate_bell(n_ones)) ks = np.array(ks) # construct pairs of ks and ls clist = [] for llist in ls: # llist goes in the subscript of C (so C_(llist)) c = 0 for j, klist in enumerate(ks): # j = permutation number # klist = ks[j] = member of the permuation group of k # = P_j(ks) cterm = (-1)**(j + 1) for i in range(len(klist)): k, l = klist[i], llist[i] cterm *= S(k, l) c += cterm clist += [c] zeros = ["0" for _ in range(n_zeros)] ones = ["1" for _ in range(n_ones)] statevector_init = zeros + ones # generate all permutations statevect_permutations = multiset_permutations(statevector_init) # join the string of 0s and 1s, convert it to an integer from base 2, # these will be the locations of nonzero probabilities positiveproblocations = [ int("".join(vect_permutation), 2) for vect_permutation in statevect_permutations ] # generate XX state q_instability_state = [0.] * 2**n_qubits for i, loc in enumerate(positiveproblocations): q_instability_state[loc] = clist[i] # normalize q_instability_state = np.array(q_instability_state) q_instability_state /= norm(q_instability_state) return q_instability_state