def test_hamiltonian_builder_index_shift_3D():
    """ Check if PBC are enforced correctly in the Hamiltonian construction (in
        fact, in the construction of the plaquette list).
    """
    param = {'L': [2, 2, 4], 'lambda': 0, 'J': -1.0}
    builder = HamiltonianBuilder(param, states=[])

    # Set up test case.
    expected = np.array([
        [1, 2, 4],
        [0, 3, 5],
        [3, 0, 6],
        [2, 1, 7],
        [5, 6, 8],
        [4, 7, 9],
        [7, 4, 10],
        [6, 5, 11],
        [9, 10, 12],
        [8, 11, 13],
        [11, 8, 14],
        [10, 9, 15],
        [13, 14, 0],
        [12, 15, 1],
        [15, 12, 2],
        [14, 13, 3],
    ])
    for n in range(builder.S[-1]):
        print(n)
        for d in range(len(param['L'])):
            assert expected[n, d] == builder.shift_index(n, d)
def test_u_operator():
    """ Check if the plaquette operator U does what it should do.
    """
    param = {'lambda': 0, 'J': -1.0}

    # Testcase 1: should give an overlap.
    # |0000 0001 0010 0000> ---> |0000000010010000>
    param['L'] = [2, 4]
    builder = HamiltonianBuilder(param, states=[])
    state = int('0000000100100000', 2)
    expected_state = int('0000000010010000', 2)
    constructed_state, _ = apply_u(state, builder.plaquettes[2])
    assert expected_state == constructed_state

    # Testcase 2: should anihilate
    # |0010 0000 0010 0000> ---> 0
    state = int('0010 0000 0000 0000'.replace(' ', ''), 2)
    constructed_state, _ = apply_u(state, builder.plaquettes[2])
    assert constructed_state == 0

    # ---

    # Testcase 3: 3D builder.
    param['L'] = [2, 2, 2]
    builder = HamiltonianBuilder(param, states=[])
    state = set_bits([20, 7])
    expected = set_bits([19, 14])

    p_ind = [19, 14, 7, 20]
    constructed, _ = apply_u(state, p_ind + [set_bits(p_ind)])
    assert expected == constructed

    constructed, _ = apply_u(state, builder.plaquettes[19])
    assert expected == constructed
Beispiel #3
0
    def draw(self,
             a=2,
             axis=None,
             label=None,
             plaquettes=True,
             point_color='#5C60C0',
             latt2=None):
        """ 3D plot for the current lattice.
        """
        with plt.style.context('seaborn-notebook'):
            if axis is None:
                self.fig = plt.figure()
                self.fig.set_size_inches(2.6, 2.2)
                self.ax = self.fig.add_subplot(111, projection='3d')
            else:
                self.ax = axis

            if latt2 is not None:
                latt2.ax = self.ax

            # Draw the actual system.
            self.dlinks = self._draw_2D_lattice()
            points = self._draw_state()
            if latt2 is not None:
                latt2.dlinks = self.dlinks
                points2 = latt2._draw_state(colors=['black', point_color])

            # Get flippable plaquettes & color them.
            if plaquettes:
                builder = HamiltonianBuilder({'L': self.L}, [], silent=True)
                pflip = self._find_flippable_plaquettes(builder)
                print(f'# of flippable plaquettes: {len(pflip)}')
                for p in builder.plaquettes:
                    if p in pflip:
                        pass
                        #self._highlight_plaquette(p[:-1], color='green', alpha=0.1)
                    else:
                        pass
                        self._highlight_plaquette(p[:-1],
                                                  color='red',
                                                  alpha=0.1)

            # Set viewpoint correctly.
            self.ax.view_init(elev=90, azim=-90)
            self.ax.set_axis_off()
            self.ax.set_xlim(0, a * self.L[0])
            self.ax.set_ylim(0, a * self.L[1])
            #self.ax.set_zlim(0, a*self.L[2])
            if not axis:
                self.fig.subplots_adjust(left=0.001,
                                         right=1.1,
                                         top=1.1,
                                         bottom=0.001)

        if label is not None:
            self.ax.text(-0.5,
                         0,
                         self.ax.get_zlim()[1] + 0.5,
                         label,
                         fontsize=24)
def test_plaquette_list_2D():
    """ Check if the correct list of plaquettes is found in 2D.
    """
    param = {'L': [2, 4], 'lambda': 0, 'J': -1.0}
    builder = HamiltonianBuilder(param, states=[])

    # Set up test case.
    expected = [
        [0, 3, 4, 1],
        [2, 1, 6, 3],
        [4, 7, 8, 5],
        [6, 5, 10, 7],
        [8, 11, 12, 9],
        [10, 9, 14, 11],
        [12, 15, 0, 13],
        [14, 13, 2, 15],
    ]

    # Check plaquettes.
    for i, p in enumerate(builder.plaquettes):
        assert expected[i] == p[:-1]

    # Check the mask array.
    for i, p in enumerate(builder.plaquettes):
        mask = 0
        for k in expected[i]:
            mask = mask + (1 << k)
        assert mask == p[-1]
def test_u_dagger_operator():
    """ Check if the inverse plaquette operator U^+ does what it should do.
    """
    param = {'lambda': 0, 'J': -1.0}

    param['L'] = [2, 2, 2]
    builder = HamiltonianBuilder(param, states=[])
    state = set_bits([20, 7])
    expected = set_bits([19, 14])

    p_ind = [19, 14, 7, 20]
    constructed, _ = apply_u_dagger(state, p_ind + [set_bits(p_ind)])
    assert 0 == constructed

    constructed, _ = apply_u_dagger(state, builder.plaquettes[19])
    assert 0 == constructed

    # ---

    state = set_bits([19, 14])
    expected = set_bits([20, 7])

    p_ind = [19, 14, 7, 20]
    constructed, _ = apply_u_dagger(state, p_ind + [set_bits(p_ind)])
    assert expected == constructed
def test_hamiltonian_builder_index_shift_2D():
    """ Check if PBC are enforced correctly in the Hamiltonian construction (in
        fact, in the construction of the plaquette list).
    """
    # 2D check.
    param = {'L': [2, 4], 'lambda': 0, 'J': -1.0}
    builder = HamiltonianBuilder(param, states=[])

    # Set up test case.
    expected = np.array([
        [1, 2],
        [0, 3],
        [3, 4],
        [2, 5],
        [5, 6],
        [4, 7],
        [7, 0],
        [6, 1],
    ])
    for n in range(builder.S[-1]):
        for d in range(len(param['L'])):
            assert expected[n, d] == builder.shift_index(n, d)
def test_plaquette_list_3D():
    """ Check if the correct list of plaquettes is found in 3D.
    """
    param = {'L': [2, 2, 2], 'lambda': 0, 'J': -1.0}
    builder = HamiltonianBuilder(param, states=[])

    # Set up test case.
    expected = [
        [0, 4, 6, 1],
        [1, 8, 13, 2],
        [0, 5, 12, 2],
        [3, 1, 9, 4],
        [4, 11, 16, 5],
        [3, 2, 15, 5],
        [6, 10, 0, 7],
        [7, 2, 19, 8],
        [6, 11, 18, 8],
        [9, 7, 3, 10],
        [10, 5, 22, 11],
        [9, 8, 21, 11],
        [12, 16, 18, 13],
        [13, 20, 1, 14],
        [12, 17, 0, 14],
        [15, 13, 21, 16],
        [16, 23, 4, 17],
        [15, 14, 3, 17],
        [18, 22, 12, 19],
        [19, 14, 7, 20],
        [18, 23, 6, 20],
        [21, 19, 15, 22],
        [22, 17, 10, 23],
        [21, 20, 9, 23],
    ]

    # Chekc the plaquette index.
    for i, p in enumerate(builder.plaquettes):
        assert expected[i] == p[:-1]

    # Check the mask array.
    for i, p in enumerate(builder.plaquettes):
        mask = 0
        for k in expected[i]:
            mask = mask + (1 << k)
        assert mask == p[-1]
Beispiel #8
0
    def draw(self,
             a=2,
             axis=None,
             label=None,
             plaquettes=True,
             type='particle'):
        """ 3D plot for the current lattice.
        """
        if axis is None:
            self.fig = plt.figure()
            self.fig.set_size_inches(2.6, 2.2)
            self.ax = self.fig.add_subplot(111)
        else:
            self.ax = axis

        # Draw the actual system.
        self.dlinks = self._draw_2D_lattice()
        points = self._draw_state(type=type)

        # Get flippable plaquettes & color them.
        if plaquettes:
            builder = HamiltonianBuilder({'L': self.L}, [], silent=True)
            pflip = self._find_flippable_plaquettes(builder)
            print(f'# of flippable plaquettes: {len(pflip)}')
            for p in builder.plaquettes:
                if p in pflip:
                    pass
                    self._highlight_plaquette(p[:-1], color='green', alpha=0.1)
                else:
                    pass
                    self._highlight_plaquette(p[:-1], color='red', alpha=0.1)

        # Set viewpoint correctly.
        self.ax.set_axis_off()
        # self.ax.set_xlim(0, a*self.L[0])
        # self.ax.set_ylim(0, a*self.L[1])

        if label is not None:
            self.ax.text(-0.5,
                         0,
                         self.ax.get_zlim()[1] + 0.5,
                         label,
                         fontsize=24)
Beispiel #9
0
    for p in plaquettes:
        if apply_u_dagger(state, p, sign=False)[0]:
            c_1 += 1
        elif apply_u(state, p, sign=False)[0]:
            c_2 += 1
    return c_1, c_2


# Read the GL states for a given winding sector.
L = [2, 2, 4]
winding_states, _ = read_winding_sector(
    L, [0, 0, 0], basedir='../python_data/local_state_storage/')
winding_states = np.sort(winding_states)

# Count.
builder = HamiltonianBuilder({'L': L}, [], silent=True)
n_states = len(winding_states)
plaquettes = builder.get_plaquette_list(separate_lists=True)

# Compute observables.
obs = np.zeros(shape=(n_states, 6))
for k in range(n_states):
    for j, p in enumerate(plaquettes):
        obs[k, 2 * j:2 + 2 * j] = count_flippable_plaquettes(
            winding_states[k], p)

    # Show progress.
    if not (k + 1) % (1e4):
        print(f'{timestamp()} {k+1} / {n_states} states done')

np.save('counted_plaquettes', obs)
Beispiel #10
0
 def flippables(self, extensive=False):
     builder = HamiltonianBuilder({'L': self.L}, [], silent=True)
     self.pflips = self._find_flippable_plaquettes(builder)
     if extensive:
         return builder, self.pflips
     return len(self.pflips)
Beispiel #11
0
from gauss_lattice.bit_magic import count_particles


def print_path(path):
    print(' >>> '.join(map(str, path)))


param = {
    'L': [2, 2, 2],
}
input_file = 'output/hamiltonian_' + size_tag(param['L']) + '.npz'
ham = load_npz(input_file)

# Read the GSL states and produce a builder object, this is convenient for later.
gsl_states = read_all_states(param['L'])
builder = HamiltonianBuilder(param, states=gsl_states)
blen = builder.S[-1] * 3

# Here we need to convert the sparse matrix into a list of transitions, since
# this is easier to use for the recursion.
n_fock = ham.shape[0]
transitions = {k: [] for k in range(n_fock)}
for i, r in enumerate(ham.row):
    transitions[r].append((ham.col[i], int(ham.data[i])))


def loop_state(path, ml):
    if len(path) >= ml:
        return []
    for i, n in enumerate(path[:-1]):
        if abs(path[-1]) == abs(n):