pythonjupytersimulationphysics# Displaying the spins on the links of the Ising Lattice Gauge model

I am trying to display the spins on the site of the Ising Lattice Gauge theory which has spins placed on the bonds instead of the usual sites (in the case of the Ising Theory) in 2D. Basically the idea is that instead of the spins being on the sites as in the case of the Ising Model, they reside on the link between the two sites.

Using PIL in Python one can easily display these sites for the 2D Ising model by considering the spins to be in an N x N matrix. Here is the example of a 100 x 100 grid. But I am not sure how to do this in the case of the Lattice Gauge Theory where the spins are actually on the bonds. Can someone help me? Thanks it is my first time posting here.

Edit: Did not realise LaTex is not a thing here.

Solution

Assuming only nearest neighbour bonds (I'm not sure whether that is accurate), you have an N x (N-1) matrix for all horizontal bonds and an (N - 1) x N matrix for the vertical ones.

Assume these matrices are each populated with entries of +1 for spin-up and -1 for spin-down.

To visualize this structure (using PIL), you could use the following script:

```
array = np.zeros((2 * N - 1, 2 * N - 1))
for i in range(N):
for j in range(N):
if j < (N - 1):
array[2 * i, 2 * j + 1] = vert_bonds[i, j]
if i < (N - 1):
array[2 * i + 1, 2 * j] = hori_bonds[i, j]
```

We can then plot `array`

using PIL, but I would actually suggest using `matplotlib`

instead, as it is much more designed to handle this kind of data. With minimal modifications, we can get the following image:

small ising lattice gauge model plot

Or with a larger system:

large ising lattice gauge model plot

The full code for these figures is:

```
import numpy as np
import matplotlib.pyplot as plt
N = 10
if __name__ == "__main__":
# Your input data
vert_bonds = np.random.randint(2, size=(N, N - 1))
hori_bonds = np.random.randint(2, size=(N - 1, N))
# Make sure we differentiate spin-down from nodes
vert_bonds[vert_bonds == 0] = -1
hori_bonds[hori_bonds == 0] = -1
array = np.zeros((2 * N - 1, 2 * N - 1))
for i in range(N):
for j in range(N):
if j < (N - 1):
array[2 * i, 2 * j + 1] = vert_bonds[i, j]
if i < (N - 1):
array[2 * i + 1, 2 * j] = hori_bonds[i, j]
# more customiyable plotting tool
plt.imshow(array, cmap="seismic")
plt.savefig("ising-lattice-gauge-small.png")
plt.show()
```

Please let me know whether that answers your question, or whether you have any other queries!

edit: changed alt-text for large plot

- How do I scrap the text of anchor tag using Beautifulsoup?
- Is Python memory-safe?
- Python OpenAI Whisper FileNotFoundError when running a standalone created with PyInstaller
- Create array of outer products in numpy
- YOLOv8 custom save directory path
- How to use ManyToManyField for self class
- Error in running exe file having xgboost package by using pyinstaller
- Different eigenvectors from Python and Matlab
- Polars dataframe: rolling_sum look ahead
- Exception in thread django-main-thread
- Is there a way to persist decorators during inheritance?
- How do I pass in a parameter name into a function as an argument in python?
- Producer/Consumer - Queue.get by list
- Python 3.x rounding behavior
- cannot import name 'PROT_READ' from 'mmap'
- List lookup faster than tuple?
- VSCode and Jupyter notebook - changes in python script code dont update
- Compute row average in pandas
- What is the best way to filter groups by two lambda conditions and create a new column based on the conditions?
- 401 Unauthorized Error when Making POST Request to Google Apps Script Web App with Valid OAuth Token"
- Module 'cv2.cv2' has no attribute 'ximgproc'
- How do you input and output text with Pyscript?
- What's the polars equivalent to the pandas `.iloc` method?
- Error running pyttsx3 code on OS X: "NameError: name 'objc' is not defined"
- Windows cannot access the specified device, file... error when running exe made using PyInstaller
- Why Can't VS Code Directly Run Python unittest .py's Or Discover In Testing Tab
- NetworkX Not Saving Node Attributes
- Check if a certain character of a string is a number
- How does Pytorch Dataloader handle variable size data?
- Merge multiple sublists where the value is not zero