# `flatspin`

## Package Contents

### Classes

 `Grid` `LabelIndexer` `SpinIce` Ising spin lattice `SquareSpinIce` Ising spin lattice `SquareSpinIceClosed` Ising spin lattice `SquareSpinIceOpen` Ising spin lattice `PinwheelSpinIceDiamond` Ising spin lattice `PinwheelSpinIceLuckyKnot` Ising spin lattice `PinwheelSpinIceRandom` Ising spin lattice `KagomeSpinIce` Ising spin lattice `Dataset` `Grid`

### Functions

 `find_vertices`(grid, angle, win_size) Find the vertices of a geometry `vertex_type`(spin, angle) Determine the type of a vertex given its spins and angles `plot_vectors`(XY, UV, C=None, arrows=True, relim=True, mask_zero=True, replace=False, **kwargs) `run`(model, encoder='sin', input=1, input_key=None, periods=100, spp=100, temp=0, temp_func='interp', **params) Run a flatspin simulation

### Attributes

flatspin.__version__ = 1.0
centers(self)

Return the centers of the grid cells

edges(self)

Return the edges of the grid cells

center_grid(self)

Make a grid with the cell centers

classmethod fixed_grid(cls, pos, grid_size)

Make a grid with a fixed size

grid_index(self, point_inds)

Map point index to grid index

If point_inds is a single index i, a single grid index (gi, gj) is returned.

If point_inds is a list of indices, it should take the form of an integer array index: ([i0, i1, i2, …], [j0, j1, j2, …]) The corresponding grid indices are returned in the same format.

point_index(self, grid_index)

Map one grid index to zero or more point indices

Map values onto the grid

Returns a 2D array with the values mapped onto the grid

Returns a 2D array with the values summed to the grid

valuesarray or list

Values to map onto the grid cells

fill_valuescalar

Fill value for empty cells

method{‘sum’, ‘mean’}

How to aggregate multiple values which map to the same cell

flatspin.find_vertices(grid, angle, win_size)

Find the vertices of a geometry

Parameters
• grid (Grid object) – The grid of the spin positions

• angle (1D array) – The angles of each spin

• win_size ((height, width)) – The window size to scan the grid

• (vi (Returns a tuple) –

• vj

• vi (indices) where) –

• indices (vj are the vertex) –

• vertex (and indices is a list of spin indices corresponding to each) –

• index.

flatspin.vertex_type(spin, angle)

Determine the type of a vertex given its spins and angles

flatspin.get_default_params(cls)
flatspin.plot_vectors(XY, UV, C=None, arrows=True, relim=True, mask_zero=True, replace=False, **kwargs)
flatspin.normalize_vertex_type
flatspin.vertex_clist = [[0, 1, 0], [0, 0, 1], [1, 0, 0], [0.5, 0.5, 0.5]]
flatspin.vertex_cmap
class flatspin.LabelIndexer(labels)
__getitem__(self, label)
__repr__(self)

Return repr(self).

class flatspin.SpinIce(*, size=(4, 4), lattice_spacing=1, hc=10, alpha=1.0, disorder=0, h_ext=(0, 0), neighbor_distance=1, switching='sw', sw_b=1, sw_c=1, sw_beta=3, sw_gamma=3, thermal_std=0, flip_mode='max', init='polarized', random_prob=0.5, random_seed=None, use_opencl=False, opencl_platform=0, opencl_device=0)

Bases: `object`

Ising spin lattice

_vertex_size = [2, 1]
property N(self)

Alias for self.spin_count

label(self, i)

Get the label of a given spin index or list of indices

indexof(self, label)

Get the spin index of a given label or range of labels

Alias for self.L[label]

indices(self)

Get all spin indices

all_indices(self)

Get all spin indices as numpy integer array index See https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html#integer-array-indexing

_init_spin(self, init)
_init_geometry(self)
_init_threshold(self)
_init_neighbor_list(self)
_init_h_dip(self)
__getstate__(self)
__eq__(self, other)

Return self==value.

property width(self)
property height(self)
property vectors(self)

Spin vectors

set_spin(self, spin)
set_spin_image(self, filename)

Set spin state from image

The image is resized to fit the default spin grid. Then the grayscale image is used to set spin state: * black maps to spin -1 * non-black maps to spin 1

set_threshold(self, threshold)
set_h_ext(self, h_ext)

Set external field to h_ext

h_ext can either be a single vector for a uniform field (h_ext.shape==(2,)) or a 2D array of vectors for a non-uniform field (h_ext.shape==(self.spin_count, 2))

set_h_ext_grid(self, h_ext)
set_temperature(self, std)
randomize(self, prob=0.5)
polarize(self)
update_thermal_noise(self)

Resamples thermal noise. Samples x and y components of noise from normal distribution

neighbors(self, i)
spin_dipolar_field(self, i, j)

Calculate dipolar field between spin i and j relative to positive spin

dipolar_field(self, i)

Calculate total dipolar field parallell to spin i

dipolar_fields(self)
property _h_dip(self)
_h_dip_local(self, i)
external_field(self, i)

Calculate external field parallel and perpendicular to spin i

external_fields(self)

Calculate external fields parallel and perpendicular to all spins

thermal_field(self, i)
thermal_fields(self)
total_field(self, i)

Calculate the total field parallel to spin i

total_fields(self)
flip(self, i)
_switching_energy_budrikis(self)
_switching_energy_sw(self)
switching_energy(self)
flippable_energy(self)
flippable(self)
step(self)

Perform a flip of one or more flippable spins

relax(self)

Flip spins until equilibrium, return number of calls to step()

energy(self)
total_energies(self)
total_energy(self)
total_magnetization(self)
find_vertices(self)

Find the vertices in this geometry

Returns a tuple (vi, vj, indices) where vi, vj are the vertex indices and indices is a list of spin indices corresponding to each vertex index.

vertices(self)

Get the spin indices of all vertices

vertex_indices(self)

Get all vertex indices

vertex_type(self, v)

Get the vertex type for a vertex where v are the spin indices of the vertex

vertex_count(self)

Count the number of vertices of each type

Returns a tuple (types, counts) where types are the different vertex types and counts are the corresponding counts.

vertex_population(self)

Calculate the vertex type population as a fraction of all vertices

Returns a tuple (types, pops) where types are the different vertex types and pops are the corresponding fractions.

vertex_pos(self, v)

Get the position of a vertex where v are the spin indices of the vertex

vertex_mag(self, v)

Get the direction of a vertex v

property _default_cell_size(self)
grid(self, cell_size=None)

Map spin indices onto a regular grid

The spacing between each grid point is given by cell_size. If cell_size <= lattice_spacing, each grid cell will contain at most one spin. If cell_size > lattice_spacing, each grid cell may contain more than one spin. If cell_size is None, an optimal (geometry dependent) cell size is used

Returns a Grid object which allows quick lookup of spin index to grid index

fixed_grid(self, grid_size)

Map spin indices onto a regular grid of fixed size

Like grid() but takes grid size (number of cells) as parameter instead of cell size.

set_grid(self, attr, values)

Map grid values onto some spin attribute.

Valid attributes: spin, h_ext

view_grid(self, attr, cell_size=None, method='sum')

Project some spin attribute onto a grid.

Valid attributes: spin, vectors, h_ext, threshold, pos

The spacing between each grid cell is given by cell_size. If cell_size <= lattice_spacing, each grid cell will contain at most one spin attribute. If cell_size > lattice_spacing, each grid cell will contain the sum of several spin attributes.

spin_grid(self, cell_size=None)

Project the spin vectors onto a grid.

See view_grid() for information about cell_size

plot(self, arrows=True, **kwargs)
plot_energy(self, arrows=True)
plot_vertices(self)
plot_vertex_mag(self, arrows=True, **kwargs)
_init_h_dip_cl(self)
_init_cl(self)
_total_fields_cl(self)
_h_dip_local_cl(self)
_external_fields_cl(self)
class flatspin.SquareSpinIce(*, size=(4, 4), lattice_spacing=1, hc=10, alpha=1.0, disorder=0, h_ext=(0, 0), neighbor_distance=1, switching='sw', sw_b=1, sw_c=1, sw_beta=3, sw_gamma=3, thermal_std=0, flip_mode='max', init='polarized', random_prob=0.5, random_seed=None, use_opencl=False, opencl_platform=0, opencl_device=0)

Bases: `SpinIce`

Ising spin lattice

class flatspin.SquareSpinIceClosed(*, lattice_spacing=2 * np.cos(np.pi / 4), edge='symmetric', **kwargs)

Bases: `SquareSpinIce`

Ising spin lattice

_vertex_size = [3, 3]
_init_geometry(self)
_init_spin(self, init)
property _default_cell_size(self)
class flatspin.SquareSpinIceOpen(*, neighbor_distance=sqrt(2), **kwargs)

Bases: `SquareSpinIce`

Ising spin lattice

_vertex_size = [2, 2]
_init_geometry(self)
class flatspin.PinwheelSpinIceDiamond(*, spin_angle=45, neighbor_distance=10, **kwargs)

Ising spin lattice

_init_geometry(self)
class flatspin.PinwheelSpinIceLuckyKnot(*, spin_angle=45, neighbor_distance=10 * sqrt(2), **kwargs)

Ising spin lattice

_init_geometry(self)
class flatspin.PinwheelSpinIceRandom(*, spin_angle_disorder=0, **kwargs)

Ising spin lattice

_init_geometry(self)
class flatspin.KagomeSpinIce(*, size=(4, 4), lattice_spacing=1, hc=10, alpha=1.0, disorder=0, h_ext=(0, 0), neighbor_distance=1, switching='sw', sw_b=1, sw_c=1, sw_beta=3, sw_gamma=3, thermal_std=0, flip_mode='max', init='polarized', random_prob=0.5, random_seed=None, use_opencl=False, opencl_platform=0, opencl_device=0)

Bases: `SpinIce`

Ising spin lattice

_vertex_size = [2, 3]
_init_geometry(self)
property _default_cell_size(self)
flatspin.hc = 11.25
flatspin.run(model, encoder='sin', input=1, input_key=None, periods=100, spp=100, temp=0, temp_func='interp', **params)

Run a flatspin simulation

Parameters
• model (SpinIce) – Model instance

• encoder (string or Encoder) – Name of input encoder to use. See flatspin.encoder for a list of available encoders

• input (float, array or string) – Input to be encoded float: constant input repeated periods times array: array of input to encode string: filename of table input data

• input_key (int or str) – Index into input (table column)

• periods (int) – Number of periods of the external field to run Only used if input is a float

• spp (int) – Number of samples to save per input value

• temp (float, array) – Temperature to be used float: constant temperature for whole run array: array of temperatures stretched to fit run

• params (dict) – Params to pass to the encoder

class flatspin.Dataset(index=None, params={}, info={}, basepath=None)

Bases: `object`

property name(self)
__getitem__(self, i)
__repr__(self)

Return repr(self).

__str__(self)

Return str(self).

keys(self)
items(self)
iterrows(self)
__iter__(self)
__len__(self)
__eq__(self, other)

Return self==value.

subset(self, i)
filter(self, **kwargs)
groupby(self, key)
sort_values(self, column)
row(self, row=0)
id(self, row=0)
save(self, basepath=None)
file(self, filename)
files(self, patterns=None, squash=True)
tablefile(self, tablename, squash=True)
tablefiles(self, patterns=None, squash=True)
centers(self)

Return the centers of the grid cells

edges(self)

Return the edges of the grid cells

center_grid(self)

Make a grid with the cell centers

classmethod fixed_grid(cls, pos, grid_size)

Make a grid with a fixed size

grid_index(self, point_inds)

Map point index to grid index

If point_inds is a single index i, a single grid index (gi, gj) is returned.

If point_inds is a list of indices, it should take the form of an integer array index: ([i0, i1, i2, …], [j0, j1, j2, …]) The corresponding grid indices are returned in the same format.

point_index(self, grid_index)

Map one grid index to zero or more point indices

Map values onto the grid

Returns a 2D array with the values mapped onto the grid

Returns a 2D array with the values summed to the grid

valuesarray or list

Values to map onto the grid cells

fill_valuescalar

Fill value for empty cells

method{‘sum’, ‘mean’}

How to aggregate multiple values which map to the same cell