def test_full_small(): m = 4 n = 3 t = 2 expected = [[r, c, u, k] for r in xrange(m) for c in xrange(n) for u in xrange(2) for k in xrange(t)] assert linear_index_to_chimera(range(2 * m * n * t), m, n, t) == expected
def coupler_number(M, N, L, q1, q2): "Map a pair of qubits to a coupler number a la the dw command." qmin = min(q1, q2) qmax = max(q1, q2) [[imin, jmin, umin, kmin], [imax, jmax, umax, kmax]] = linear_index_to_chimera([qmin, qmax], M, N, L) cell_links = L*L if imin == imax and jmin == jmax and umin != umax: # Same unit cell return cell_links*(imin*M + jmin) + kmin*L + kmax total_intra = cell_links*M*N if imin == imax and jmin + 1 == jmax and umin == umax and kmin == kmax: # Horizontal (same cell row) return total_intra + L*(imin*(M - 1) + jmin) + kmin total_horiz = (M - 1)*N*L if imin + 1 == imax and jmin == jmax and umin == umax and kmin == kmax: # Vertical (same cell column) return total_intra + total_horiz + L*(imin*M + jmin) + kmin raise IndexError("No coupler exists between Q%04d and Q%04d" % (q1, q2))
def coupler_number(M, N, L, q1, q2): "Map a pair of qubits to a coupler number a la the dw command." qmin = min(q1, q2) qmax = max(q1, q2) [[imin, jmin, umin, kmin], [imax, jmax, umax, kmax]] = linear_index_to_chimera([qmin, qmax], M, N, L) cell_links = L*L if imin == imax and jmin == jmax and umin != umax: # Same unit cell return cell_links*(imin*M + jmin) + kmin*L + kmax total_intra = cell_links*M*N if imin == imax and jmin + 1 == jmax and umin == umax and kmin == kmax: # Horizontal (same cell row) return total_intra + L*(imin*(M - 1) + jmin) + kmin total_horiz = (M - 1)*N*L if imin + 1 == imax and jmin == jmax and umin == umax and kmin == kmax: # Vertical (same cell column) return total_intra + total_horiz + L*(imin*M + jmin) + kmin raise IndexError("No coupler exists between Q%04d and Q%04d" % (q1, q2))
def test_trivial(): assert linear_index_to_chimera([], 1) == []
def test_larger(): li = [214, 370, 1210, 366, 1172, 350, 1338, 503, 283, 361, 887, 681] expected = [[2, 1, 1, 4], [3, 6, 1, 4], [12, 4, 1, 4], [3, 6, 1, 0], [12, 1, 1, 2], [3, 5, 0, 2], [13, 7, 1, 0], [5, 1, 1, 5], [2, 7, 1, 1], [3, 6, 0, 1], [9, 1, 1, 5], [7, 0, 1, 3]] assert linear_index_to_chimera(li, 15, 8, 6) == expected