flatspin.model#

Flatspin model

class flatspin.model.LabelIndexer(labels)#
class flatspin.model.SpinIce(*, size=(4, 4), lattice_spacing=1, hc=0.2, alpha=0.001, disorder=0, h_ext=(0, 0), neighbor_distance=1, switching='sw', sw_b=0.41, sw_c=1, sw_beta=1.5, sw_gamma=3.9, temperature=0, therm_timescale=1, m_therm=7.567999999999999e-17, attempt_freq=1000000000.0, flip_mode='max', init='polarized', random_prob=0.5, random_seed=0, use_opencl=False, opencl_platform=0, opencl_device=0, use_cuda=False, astroid_resolution=1801)#

Spin ice abstract base class

The SpinIce class contains the core implementation of the flatspin model. It is an abstract base class, and cannot be instantiated directly. Subclasses of this class define the geometry, by implementing _init_geometry().

Parameters
  • size (tuple of int) – The size of the spin ice (width, height). Note that the size is geometry specific.

  • lattice_spacing (float) – Spacing between each spin.

  • hc (float) – Mean switching threshold.

  • alpha (float) – Coupling strength alpha = u_0 * M / (4 * pi * a^3), where a is the lattice spacing and M is the net magneticmoment of a single magnet.

  • disorder (float) – Switching threshold disorder as percentage of hc. If non-zero, sample switching from a normal distribution with mean hc and standard deviation hc * disorder.

  • h_ext (tuple of float) – External field (h_extx, h_exty).

  • neighbor_distance (float) – Neighborhood to consider when calculating dipole interactions. All spins within lattice_spacing * neighbor_distance are considered neighbors. Set neighbor_distance=np.inf for a global neighborhood.

  • switching ({'sw', 'budrikis'}) –

    Magnetic switching model:
    • ’sw’: Extended Stoner-Wohlfarth model

    • ’budrikis’: switching based on the parallel field component

  • sw_b (float) – Height of the Stoner-Wohlfarth astroid (parallel axis).

  • sw_c (float) – Width of the Stoner-Wohlfarth astroid (perpendicular axis).

  • sw_beta (float) – Pointiness of the top/bottom of the Stoner-Wohlfarth astroid (parallel axis).

  • sw_gamma (float) – Pointiness of the left/right of the Stoner-Wohlfarth astroid (perpendicular axis).

  • temperature (float (positive)) – Absolute temperature in Kelvin.

  • therm_timescale (float) – The thermal time scale (length in seconds of each simulated timestep). When temperature > 0, the thermal activity per timestep increases with therm_timescale. See also set_temperature().

  • m_therm (float) – Thermal nucleation moment (thermal nucleation volume * magnetic moment). See also set_temperature().

  • attempt_freq (float) – Attempt frequency (1/s). Only used for temperature calculations, see set_temperature().

  • flip_mode ({'single', 'max', 'max-rand', 'all'}) –

    Flip mode strategy:
    • ’single’: single uniform random flip (Budrikis Monte Carlo)

    • ’max’: flip the spin with maximum energy, break ties by index

    • ’max-rand’: flip the spin with maximum energy, break ties randomly

    • ’all’: flip all flippable spins

  • init ({1, -1, 'random', 'image.png'} or ndarray) – Initial spin state.

  • use_opencl (bool) – Use OpenCL acceleration.

  • opencl_platform (int) – Select OpenCL platform (if multiple GPUs of different families are installed).

  • opencl_device (int) – Select OpenCL device (if multiple GPUs of the same family are installed).

  • use_cuda (bool) – Use CUDA acceleration. NB! Requires compute platform 10 and above.

  • astroid_resolution (number of polar points in one rotation to resolve) – astroid shape for h_dist calculcations

property N#

Alias for self.spin_count

label(i)#

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

indexof(label)#

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

Alias for self.L[label]

indices()#

Get all spin indices

all_indices()#

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

abstract _init_geometry()#

Initialize the geometry

Subclasses should override this method and return a tuple (pos, angle), where pos is an array with the (x, y) positions of the spins, while angle is an array with the rotations of the spins.

The base class implementation may be invoked to generate an Ising geometry.

property width#
property height#
property vectors#

Spin vectors

set_spin(spin)#
set_spin_image(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(threshold)#

Set switching thresholds manually.

NB: this method does not update self.hc

set_hc(hc)#

Set mean switching threshold hc.

Rescales existing thresholds to have new mean hc and standard devication hc * disorder.

set_h_ext(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(h_ext)#
set_alpha(alpha)#

Set coupling strength alpha = u_0 * M / (4 * pi * a^3), where a is the lattice spacing and M is the net magneticmoment of a single magnet.

set_therm_timescale(therm_timescale)#

Set thermal time scale (length in seconds of each simulated timestep). When temperature > 0, the thermal activity per timestep increases with therm_timescale. See also set_temperature().

set_m_therm(m_therm)#

Thermal nucleation moment (thermal nucleation volume * magnetic moment). See also set_temperature().

set_temperature(temperature)#

Set temperature for the thermal field

The random thermal field depends on temperature, as well as the parameters m_therm, therm_timescale and attempt_freq.

Note: flatspin does not account for the temperature dependence of the parameters. If these parameters are expected to vary significantly in the temperature range of interest, this has to be explicitly accounted for by the user.

randomize(prob=0.5)#
polarize(spin=1)#
update_thermal_noise()#

Resamples thermal noise. Samples a field magnitude matching probability of switching from Poisson(arrhenius_rate(Zeeman/kB*T)*timestep) and returns field vector directed along minimal distance to astroid

neighbors(i)#
spin_dipolar_field(i, j)#

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

dipolar_field(i)#

Calculate total dipolar field parallell to spin i

dipolar_fields()#
external_field(i)#

Calculate external field parallel and perpendicular to spin i

external_fields()#

Calculate external fields parallel and perpendicular to all spins

thermal_field(i)#

Calculate thermal field parallel and perpendicular to spin i

thermal_fields()#

Calculate thermal fields parallel and perpendicular to all spins

total_field(i)#

Calculate the total field parallel to spin i

total_fields()#
total_non_thermal_fields()#
flip(i)#
switching_energy()#
flippable_energy()#
flippable()#
step()#

Perform a flip of one or more flippable spins

relax()#

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

energy()#

Calculate energy per spin

The energy is the component of the total field directed anti-parallel to the spin magnetization

dipolar_energy()#

Calculate the dipolar energy per spin

The dipolar energy is the component of the dipolar field directed anti-parallel to the spin magnetization

external_energy()#

Calculate the external energy per spin

The external energy is the component of the external field directed anti-parallel to the spin magnetization

thermal_energy()#

Calculate the thermal energy per spin

The thermal energy is the component of the thermal field directed anti-parallel to the spin magnetization

total_energy()#

Calculate the total energy

total_dipolar_energy()#

Calculate the total dipolar energy

total_external_energy()#

Calculate the total external energy

total_thermal_energy()#

Calculate the total thermal energy

total_energies()#
total_magnetization()#
_vertex_size = (2, 1)#
find_vertices()#

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()#

Get the spin indices of all vertices

vertex_indices()#

Get all vertex indices

vertex_type(v)#

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

vertex_count()#

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()#

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(v)#

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

vertex_mag(v)#

Get the direction of a vertex v

grid(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(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(attr, values)#

Map grid values onto some spin attribute.

Valid attributes: spin, h_ext, threshold

view_grid(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(cell_size=None)#

Project the spin vectors onto a grid.

See view_grid() for information about cell_size

plot(arrows=True, **kwargs)#
plot_energy(**kwargs)#
plot_vertices(**kwargs)#
plot_vertex_mag(arrows=True, **kwargs)#
class flatspin.model.IsingSpinIce(*, spin_angle=90, **kwargs)#
Parameters
  • size (tuple of int) – The size of the spin ice (width, height). Note that the size is geometry specific.

  • lattice_spacing (float) – Spacing between each spin.

  • hc (float) – Mean switching threshold.

  • alpha (float) – Coupling strength alpha = u_0 * M / (4 * pi * a^3), where a is the lattice spacing and M is the net magneticmoment of a single magnet.

  • disorder (float) – Switching threshold disorder as percentage of hc. If non-zero, sample switching from a normal distribution with mean hc and standard deviation hc * disorder.

  • h_ext (tuple of float) – External field (h_extx, h_exty).

  • neighbor_distance (float) – Neighborhood to consider when calculating dipole interactions. All spins within lattice_spacing * neighbor_distance are considered neighbors. Set neighbor_distance=np.inf for a global neighborhood.

  • switching ({'sw', 'budrikis'}) –

    Magnetic switching model:
    • ’sw’: Extended Stoner-Wohlfarth model

    • ’budrikis’: switching based on the parallel field component

  • sw_b (float) – Height of the Stoner-Wohlfarth astroid (parallel axis).

  • sw_c (float) – Width of the Stoner-Wohlfarth astroid (perpendicular axis).

  • sw_beta (float) – Pointiness of the top/bottom of the Stoner-Wohlfarth astroid (parallel axis).

  • sw_gamma (float) – Pointiness of the left/right of the Stoner-Wohlfarth astroid (perpendicular axis).

  • temperature (float (positive)) – Absolute temperature in Kelvin.

  • therm_timescale (float) – The thermal time scale (length in seconds of each simulated timestep). When temperature > 0, the thermal activity per timestep increases with therm_timescale. See also set_temperature().

  • m_therm (float) – Thermal nucleation moment (thermal nucleation volume * magnetic moment). See also set_temperature().

  • attempt_freq (float) – Attempt frequency (1/s). Only used for temperature calculations, see set_temperature().

  • flip_mode ({'single', 'max', 'max-rand', 'all'}) –

    Flip mode strategy:
    • ’single’: single uniform random flip (Budrikis Monte Carlo)

    • ’max’: flip the spin with maximum energy, break ties by index

    • ’max-rand’: flip the spin with maximum energy, break ties randomly

    • ’all’: flip all flippable spins

  • init ({1, -1, 'random', 'image.png'} or ndarray) – Initial spin state.

  • use_opencl (bool) – Use OpenCL acceleration.

  • opencl_platform (int) – Select OpenCL platform (if multiple GPUs of different families are installed).

  • opencl_device (int) – Select OpenCL device (if multiple GPUs of the same family are installed).

  • use_cuda (bool) – Use CUDA acceleration. NB! Requires compute platform 10 and above.

  • astroid_resolution (number of polar points in one rotation to resolve) – astroid shape for h_dist calculcations

_init_geometry()#

Initialize the geometry

Subclasses should override this method and return a tuple (pos, angle), where pos is an array with the (x, y) positions of the spins, while angle is an array with the rotations of the spins.

The base class implementation may be invoked to generate an Ising geometry.

class flatspin.model.SquareSpinIce(*, size=(4, 4), lattice_spacing=1, hc=0.2, alpha=0.001, disorder=0, h_ext=(0, 0), neighbor_distance=1, switching='sw', sw_b=0.41, sw_c=1, sw_beta=1.5, sw_gamma=3.9, temperature=0, therm_timescale=1, m_therm=7.567999999999999e-17, attempt_freq=1000000000.0, flip_mode='max', init='polarized', random_prob=0.5, random_seed=0, use_opencl=False, opencl_platform=0, opencl_device=0, use_cuda=False, astroid_resolution=1801)#
Parameters
  • size (tuple of int) – The size of the spin ice (width, height). Note that the size is geometry specific.

  • lattice_spacing (float) – Spacing between each spin.

  • hc (float) – Mean switching threshold.

  • alpha (float) – Coupling strength alpha = u_0 * M / (4 * pi * a^3), where a is the lattice spacing and M is the net magneticmoment of a single magnet.

  • disorder (float) – Switching threshold disorder as percentage of hc. If non-zero, sample switching from a normal distribution with mean hc and standard deviation hc * disorder.

  • h_ext (tuple of float) – External field (h_extx, h_exty).

  • neighbor_distance (float) – Neighborhood to consider when calculating dipole interactions. All spins within lattice_spacing * neighbor_distance are considered neighbors. Set neighbor_distance=np.inf for a global neighborhood.

  • switching ({'sw', 'budrikis'}) –

    Magnetic switching model:
    • ’sw’: Extended Stoner-Wohlfarth model

    • ’budrikis’: switching based on the parallel field component

  • sw_b (float) – Height of the Stoner-Wohlfarth astroid (parallel axis).

  • sw_c (float) – Width of the Stoner-Wohlfarth astroid (perpendicular axis).

  • sw_beta (float) – Pointiness of the top/bottom of the Stoner-Wohlfarth astroid (parallel axis).

  • sw_gamma (float) – Pointiness of the left/right of the Stoner-Wohlfarth astroid (perpendicular axis).

  • temperature (float (positive)) – Absolute temperature in Kelvin.

  • therm_timescale (float) – The thermal time scale (length in seconds of each simulated timestep). When temperature > 0, the thermal activity per timestep increases with therm_timescale. See also set_temperature().

  • m_therm (float) – Thermal nucleation moment (thermal nucleation volume * magnetic moment). See also set_temperature().

  • attempt_freq (float) – Attempt frequency (1/s). Only used for temperature calculations, see set_temperature().

  • flip_mode ({'single', 'max', 'max-rand', 'all'}) –

    Flip mode strategy:
    • ’single’: single uniform random flip (Budrikis Monte Carlo)

    • ’max’: flip the spin with maximum energy, break ties by index

    • ’max-rand’: flip the spin with maximum energy, break ties randomly

    • ’all’: flip all flippable spins

  • init ({1, -1, 'random', 'image.png'} or ndarray) – Initial spin state.

  • use_opencl (bool) – Use OpenCL acceleration.

  • opencl_platform (int) – Select OpenCL platform (if multiple GPUs of different families are installed).

  • opencl_device (int) – Select OpenCL device (if multiple GPUs of the same family are installed).

  • use_cuda (bool) – Use CUDA acceleration. NB! Requires compute platform 10 and above.

  • astroid_resolution (number of polar points in one rotation to resolve) – astroid shape for h_dist calculcations

class flatspin.model.SquareSpinIceClosed(*, edge='symmetric', **kwargs)#
Parameters
  • size (tuple of int) – The size of the spin ice (width, height). Note that the size is geometry specific.

  • lattice_spacing (float) – Spacing between each spin.

  • hc (float) – Mean switching threshold.

  • alpha (float) – Coupling strength alpha = u_0 * M / (4 * pi * a^3), where a is the lattice spacing and M is the net magneticmoment of a single magnet.

  • disorder (float) – Switching threshold disorder as percentage of hc. If non-zero, sample switching from a normal distribution with mean hc and standard deviation hc * disorder.

  • h_ext (tuple of float) – External field (h_extx, h_exty).

  • neighbor_distance (float) – Neighborhood to consider when calculating dipole interactions. All spins within lattice_spacing * neighbor_distance are considered neighbors. Set neighbor_distance=np.inf for a global neighborhood.

  • switching ({'sw', 'budrikis'}) –

    Magnetic switching model:
    • ’sw’: Extended Stoner-Wohlfarth model

    • ’budrikis’: switching based on the parallel field component

  • sw_b (float) – Height of the Stoner-Wohlfarth astroid (parallel axis).

  • sw_c (float) – Width of the Stoner-Wohlfarth astroid (perpendicular axis).

  • sw_beta (float) – Pointiness of the top/bottom of the Stoner-Wohlfarth astroid (parallel axis).

  • sw_gamma (float) – Pointiness of the left/right of the Stoner-Wohlfarth astroid (perpendicular axis).

  • temperature (float (positive)) – Absolute temperature in Kelvin.

  • therm_timescale (float) – The thermal time scale (length in seconds of each simulated timestep). When temperature > 0, the thermal activity per timestep increases with therm_timescale. See also set_temperature().

  • m_therm (float) – Thermal nucleation moment (thermal nucleation volume * magnetic moment). See also set_temperature().

  • attempt_freq (float) – Attempt frequency (1/s). Only used for temperature calculations, see set_temperature().

  • flip_mode ({'single', 'max', 'max-rand', 'all'}) –

    Flip mode strategy:
    • ’single’: single uniform random flip (Budrikis Monte Carlo)

    • ’max’: flip the spin with maximum energy, break ties by index

    • ’max-rand’: flip the spin with maximum energy, break ties randomly

    • ’all’: flip all flippable spins

  • init ({1, -1, 'random', 'image.png'} or ndarray) – Initial spin state.

  • use_opencl (bool) – Use OpenCL acceleration.

  • opencl_platform (int) – Select OpenCL platform (if multiple GPUs of different families are installed).

  • opencl_device (int) – Select OpenCL device (if multiple GPUs of the same family are installed).

  • use_cuda (bool) – Use CUDA acceleration. NB! Requires compute platform 10 and above.

  • astroid_resolution (number of polar points in one rotation to resolve) – astroid shape for h_dist calculcations

_init_geometry()#

Initialize the geometry

Subclasses should override this method and return a tuple (pos, angle), where pos is an array with the (x, y) positions of the spins, while angle is an array with the rotations of the spins.

The base class implementation may be invoked to generate an Ising geometry.

_vertex_size = (3, 3)#
class flatspin.model.SquareSpinIceOpen(*, neighbor_distance=1.4142135623730951, **kwargs)#
Parameters
  • size (tuple of int) – The size of the spin ice (width, height). Note that the size is geometry specific.

  • lattice_spacing (float) – Spacing between each spin.

  • hc (float) – Mean switching threshold.

  • alpha (float) – Coupling strength alpha = u_0 * M / (4 * pi * a^3), where a is the lattice spacing and M is the net magneticmoment of a single magnet.

  • disorder (float) – Switching threshold disorder as percentage of hc. If non-zero, sample switching from a normal distribution with mean hc and standard deviation hc * disorder.

  • h_ext (tuple of float) – External field (h_extx, h_exty).

  • neighbor_distance (float) – Neighborhood to consider when calculating dipole interactions. All spins within lattice_spacing * neighbor_distance are considered neighbors. Set neighbor_distance=np.inf for a global neighborhood.

  • switching ({'sw', 'budrikis'}) –

    Magnetic switching model:
    • ’sw’: Extended Stoner-Wohlfarth model

    • ’budrikis’: switching based on the parallel field component

  • sw_b (float) – Height of the Stoner-Wohlfarth astroid (parallel axis).

  • sw_c (float) – Width of the Stoner-Wohlfarth astroid (perpendicular axis).

  • sw_beta (float) – Pointiness of the top/bottom of the Stoner-Wohlfarth astroid (parallel axis).

  • sw_gamma (float) – Pointiness of the left/right of the Stoner-Wohlfarth astroid (perpendicular axis).

  • temperature (float (positive)) – Absolute temperature in Kelvin.

  • therm_timescale (float) – The thermal time scale (length in seconds of each simulated timestep). When temperature > 0, the thermal activity per timestep increases with therm_timescale. See also set_temperature().

  • m_therm (float) – Thermal nucleation moment (thermal nucleation volume * magnetic moment). See also set_temperature().

  • attempt_freq (float) – Attempt frequency (1/s). Only used for temperature calculations, see set_temperature().

  • flip_mode ({'single', 'max', 'max-rand', 'all'}) –

    Flip mode strategy:
    • ’single’: single uniform random flip (Budrikis Monte Carlo)

    • ’max’: flip the spin with maximum energy, break ties by index

    • ’max-rand’: flip the spin with maximum energy, break ties randomly

    • ’all’: flip all flippable spins

  • init ({1, -1, 'random', 'image.png'} or ndarray) – Initial spin state.

  • use_opencl (bool) – Use OpenCL acceleration.

  • opencl_platform (int) – Select OpenCL platform (if multiple GPUs of different families are installed).

  • opencl_device (int) – Select OpenCL device (if multiple GPUs of the same family are installed).

  • use_cuda (bool) – Use CUDA acceleration. NB! Requires compute platform 10 and above.

  • astroid_resolution (number of polar points in one rotation to resolve) – astroid shape for h_dist calculcations

_init_geometry()#

Initialize the geometry

Subclasses should override this method and return a tuple (pos, angle), where pos is an array with the (x, y) positions of the spins, while angle is an array with the rotations of the spins.

The base class implementation may be invoked to generate an Ising geometry.

_vertex_size = (2, 2)#
class flatspin.model.PinwheelSpinIceDiamond(*, spin_angle=45, neighbor_distance=10, **kwargs)#
Parameters
  • size (tuple of int) – The size of the spin ice (width, height). Note that the size is geometry specific.

  • lattice_spacing (float) – Spacing between each spin.

  • hc (float) – Mean switching threshold.

  • alpha (float) – Coupling strength alpha = u_0 * M / (4 * pi * a^3), where a is the lattice spacing and M is the net magneticmoment of a single magnet.

  • disorder (float) – Switching threshold disorder as percentage of hc. If non-zero, sample switching from a normal distribution with mean hc and standard deviation hc * disorder.

  • h_ext (tuple of float) – External field (h_extx, h_exty).

  • neighbor_distance (float) – Neighborhood to consider when calculating dipole interactions. All spins within lattice_spacing * neighbor_distance are considered neighbors. Set neighbor_distance=np.inf for a global neighborhood.

  • switching ({'sw', 'budrikis'}) –

    Magnetic switching model:
    • ’sw’: Extended Stoner-Wohlfarth model

    • ’budrikis’: switching based on the parallel field component

  • sw_b (float) – Height of the Stoner-Wohlfarth astroid (parallel axis).

  • sw_c (float) – Width of the Stoner-Wohlfarth astroid (perpendicular axis).

  • sw_beta (float) – Pointiness of the top/bottom of the Stoner-Wohlfarth astroid (parallel axis).

  • sw_gamma (float) – Pointiness of the left/right of the Stoner-Wohlfarth astroid (perpendicular axis).

  • temperature (float (positive)) – Absolute temperature in Kelvin.

  • therm_timescale (float) – The thermal time scale (length in seconds of each simulated timestep). When temperature > 0, the thermal activity per timestep increases with therm_timescale. See also set_temperature().

  • m_therm (float) – Thermal nucleation moment (thermal nucleation volume * magnetic moment). See also set_temperature().

  • attempt_freq (float) – Attempt frequency (1/s). Only used for temperature calculations, see set_temperature().

  • flip_mode ({'single', 'max', 'max-rand', 'all'}) –

    Flip mode strategy:
    • ’single’: single uniform random flip (Budrikis Monte Carlo)

    • ’max’: flip the spin with maximum energy, break ties by index

    • ’max-rand’: flip the spin with maximum energy, break ties randomly

    • ’all’: flip all flippable spins

  • init ({1, -1, 'random', 'image.png'} or ndarray) – Initial spin state.

  • use_opencl (bool) – Use OpenCL acceleration.

  • opencl_platform (int) – Select OpenCL platform (if multiple GPUs of different families are installed).

  • opencl_device (int) – Select OpenCL device (if multiple GPUs of the same family are installed).

  • use_cuda (bool) – Use CUDA acceleration. NB! Requires compute platform 10 and above.

  • astroid_resolution (number of polar points in one rotation to resolve) – astroid shape for h_dist calculcations

_init_geometry()#

Initialize the geometry

Subclasses should override this method and return a tuple (pos, angle), where pos is an array with the (x, y) positions of the spins, while angle is an array with the rotations of the spins.

The base class implementation may be invoked to generate an Ising geometry.

class flatspin.model.PinwheelSpinIceLuckyKnot(*, spin_angle=45, neighbor_distance=14.142135623730951, **kwargs)#
Parameters
  • size (tuple of int) – The size of the spin ice (width, height). Note that the size is geometry specific.

  • lattice_spacing (float) – Spacing between each spin.

  • hc (float) – Mean switching threshold.

  • alpha (float) – Coupling strength alpha = u_0 * M / (4 * pi * a^3), where a is the lattice spacing and M is the net magneticmoment of a single magnet.

  • disorder (float) – Switching threshold disorder as percentage of hc. If non-zero, sample switching from a normal distribution with mean hc and standard deviation hc * disorder.

  • h_ext (tuple of float) – External field (h_extx, h_exty).

  • neighbor_distance (float) – Neighborhood to consider when calculating dipole interactions. All spins within lattice_spacing * neighbor_distance are considered neighbors. Set neighbor_distance=np.inf for a global neighborhood.

  • switching ({'sw', 'budrikis'}) –

    Magnetic switching model:
    • ’sw’: Extended Stoner-Wohlfarth model

    • ’budrikis’: switching based on the parallel field component

  • sw_b (float) – Height of the Stoner-Wohlfarth astroid (parallel axis).

  • sw_c (float) – Width of the Stoner-Wohlfarth astroid (perpendicular axis).

  • sw_beta (float) – Pointiness of the top/bottom of the Stoner-Wohlfarth astroid (parallel axis).

  • sw_gamma (float) – Pointiness of the left/right of the Stoner-Wohlfarth astroid (perpendicular axis).

  • temperature (float (positive)) – Absolute temperature in Kelvin.

  • therm_timescale (float) – The thermal time scale (length in seconds of each simulated timestep). When temperature > 0, the thermal activity per timestep increases with therm_timescale. See also set_temperature().

  • m_therm (float) – Thermal nucleation moment (thermal nucleation volume * magnetic moment). See also set_temperature().

  • attempt_freq (float) – Attempt frequency (1/s). Only used for temperature calculations, see set_temperature().

  • flip_mode ({'single', 'max', 'max-rand', 'all'}) –

    Flip mode strategy:
    • ’single’: single uniform random flip (Budrikis Monte Carlo)

    • ’max’: flip the spin with maximum energy, break ties by index

    • ’max-rand’: flip the spin with maximum energy, break ties randomly

    • ’all’: flip all flippable spins

  • init ({1, -1, 'random', 'image.png'} or ndarray) – Initial spin state.

  • use_opencl (bool) – Use OpenCL acceleration.

  • opencl_platform (int) – Select OpenCL platform (if multiple GPUs of different families are installed).

  • opencl_device (int) – Select OpenCL device (if multiple GPUs of the same family are installed).

  • use_cuda (bool) – Use CUDA acceleration. NB! Requires compute platform 10 and above.

  • astroid_resolution (number of polar points in one rotation to resolve) – astroid shape for h_dist calculcations

_init_geometry()#

Initialize the geometry

Subclasses should override this method and return a tuple (pos, angle), where pos is an array with the (x, y) positions of the spins, while angle is an array with the rotations of the spins.

The base class implementation may be invoked to generate an Ising geometry.

class flatspin.model.PinwheelSpinIceRandom(*, spin_angle_disorder=0, **kwargs)#
Parameters
  • size (tuple of int) – The size of the spin ice (width, height). Note that the size is geometry specific.

  • lattice_spacing (float) – Spacing between each spin.

  • hc (float) – Mean switching threshold.

  • alpha (float) – Coupling strength alpha = u_0 * M / (4 * pi * a^3), where a is the lattice spacing and M is the net magneticmoment of a single magnet.

  • disorder (float) – Switching threshold disorder as percentage of hc. If non-zero, sample switching from a normal distribution with mean hc and standard deviation hc * disorder.

  • h_ext (tuple of float) – External field (h_extx, h_exty).

  • neighbor_distance (float) – Neighborhood to consider when calculating dipole interactions. All spins within lattice_spacing * neighbor_distance are considered neighbors. Set neighbor_distance=np.inf for a global neighborhood.

  • switching ({'sw', 'budrikis'}) –

    Magnetic switching model:
    • ’sw’: Extended Stoner-Wohlfarth model

    • ’budrikis’: switching based on the parallel field component

  • sw_b (float) – Height of the Stoner-Wohlfarth astroid (parallel axis).

  • sw_c (float) – Width of the Stoner-Wohlfarth astroid (perpendicular axis).

  • sw_beta (float) – Pointiness of the top/bottom of the Stoner-Wohlfarth astroid (parallel axis).

  • sw_gamma (float) – Pointiness of the left/right of the Stoner-Wohlfarth astroid (perpendicular axis).

  • temperature (float (positive)) – Absolute temperature in Kelvin.

  • therm_timescale (float) – The thermal time scale (length in seconds of each simulated timestep). When temperature > 0, the thermal activity per timestep increases with therm_timescale. See also set_temperature().

  • m_therm (float) – Thermal nucleation moment (thermal nucleation volume * magnetic moment). See also set_temperature().

  • attempt_freq (float) – Attempt frequency (1/s). Only used for temperature calculations, see set_temperature().

  • flip_mode ({'single', 'max', 'max-rand', 'all'}) –

    Flip mode strategy:
    • ’single’: single uniform random flip (Budrikis Monte Carlo)

    • ’max’: flip the spin with maximum energy, break ties by index

    • ’max-rand’: flip the spin with maximum energy, break ties randomly

    • ’all’: flip all flippable spins

  • init ({1, -1, 'random', 'image.png'} or ndarray) – Initial spin state.

  • use_opencl (bool) – Use OpenCL acceleration.

  • opencl_platform (int) – Select OpenCL platform (if multiple GPUs of different families are installed).

  • opencl_device (int) – Select OpenCL device (if multiple GPUs of the same family are installed).

  • use_cuda (bool) – Use CUDA acceleration. NB! Requires compute platform 10 and above.

  • astroid_resolution (number of polar points in one rotation to resolve) – astroid shape for h_dist calculcations

_init_geometry()#

Initialize the geometry

Subclasses should override this method and return a tuple (pos, angle), where pos is an array with the (x, y) positions of the spins, while angle is an array with the rotations of the spins.

The base class implementation may be invoked to generate an Ising geometry.

class flatspin.model.KagomeSpinIce(*, size=(4, 4), lattice_spacing=1, hc=0.2, alpha=0.001, disorder=0, h_ext=(0, 0), neighbor_distance=1, switching='sw', sw_b=0.41, sw_c=1, sw_beta=1.5, sw_gamma=3.9, temperature=0, therm_timescale=1, m_therm=7.567999999999999e-17, attempt_freq=1000000000.0, flip_mode='max', init='polarized', random_prob=0.5, random_seed=0, use_opencl=False, opencl_platform=0, opencl_device=0, use_cuda=False, astroid_resolution=1801)#
Parameters
  • size (tuple of int) – The size of the spin ice (width, height). Note that the size is geometry specific.

  • lattice_spacing (float) – Spacing between each spin.

  • hc (float) – Mean switching threshold.

  • alpha (float) – Coupling strength alpha = u_0 * M / (4 * pi * a^3), where a is the lattice spacing and M is the net magneticmoment of a single magnet.

  • disorder (float) – Switching threshold disorder as percentage of hc. If non-zero, sample switching from a normal distribution with mean hc and standard deviation hc * disorder.

  • h_ext (tuple of float) – External field (h_extx, h_exty).

  • neighbor_distance (float) – Neighborhood to consider when calculating dipole interactions. All spins within lattice_spacing * neighbor_distance are considered neighbors. Set neighbor_distance=np.inf for a global neighborhood.

  • switching ({'sw', 'budrikis'}) –

    Magnetic switching model:
    • ’sw’: Extended Stoner-Wohlfarth model

    • ’budrikis’: switching based on the parallel field component

  • sw_b (float) – Height of the Stoner-Wohlfarth astroid (parallel axis).

  • sw_c (float) – Width of the Stoner-Wohlfarth astroid (perpendicular axis).

  • sw_beta (float) – Pointiness of the top/bottom of the Stoner-Wohlfarth astroid (parallel axis).

  • sw_gamma (float) – Pointiness of the left/right of the Stoner-Wohlfarth astroid (perpendicular axis).

  • temperature (float (positive)) – Absolute temperature in Kelvin.

  • therm_timescale (float) – The thermal time scale (length in seconds of each simulated timestep). When temperature > 0, the thermal activity per timestep increases with therm_timescale. See also set_temperature().

  • m_therm (float) – Thermal nucleation moment (thermal nucleation volume * magnetic moment). See also set_temperature().

  • attempt_freq (float) – Attempt frequency (1/s). Only used for temperature calculations, see set_temperature().

  • flip_mode ({'single', 'max', 'max-rand', 'all'}) –

    Flip mode strategy:
    • ’single’: single uniform random flip (Budrikis Monte Carlo)

    • ’max’: flip the spin with maximum energy, break ties by index

    • ’max-rand’: flip the spin with maximum energy, break ties randomly

    • ’all’: flip all flippable spins

  • init ({1, -1, 'random', 'image.png'} or ndarray) – Initial spin state.

  • use_opencl (bool) – Use OpenCL acceleration.

  • opencl_platform (int) – Select OpenCL platform (if multiple GPUs of different families are installed).

  • opencl_device (int) – Select OpenCL device (if multiple GPUs of the same family are installed).

  • use_cuda (bool) – Use CUDA acceleration. NB! Requires compute platform 10 and above.

  • astroid_resolution (number of polar points in one rotation to resolve) – astroid shape for h_dist calculcations

_init_geometry()#

Initialize the geometry

Subclasses should override this method and return a tuple (pos, angle), where pos is an array with the (x, y) positions of the spins, while angle is an array with the rotations of the spins.

The base class implementation may be invoked to generate an Ising geometry.

_vertex_size = (2, 3)#
class flatspin.model.KagomeSpinIceRotated(*, size=(4, 4), lattice_spacing=1, hc=0.2, alpha=0.001, disorder=0, h_ext=(0, 0), neighbor_distance=1, switching='sw', sw_b=0.41, sw_c=1, sw_beta=1.5, sw_gamma=3.9, temperature=0, therm_timescale=1, m_therm=7.567999999999999e-17, attempt_freq=1000000000.0, flip_mode='max', init='polarized', random_prob=0.5, random_seed=0, use_opencl=False, opencl_platform=0, opencl_device=0, use_cuda=False, astroid_resolution=1801)#
Parameters
  • size (tuple of int) – The size of the spin ice (width, height). Note that the size is geometry specific.

  • lattice_spacing (float) – Spacing between each spin.

  • hc (float) – Mean switching threshold.

  • alpha (float) – Coupling strength alpha = u_0 * M / (4 * pi * a^3), where a is the lattice spacing and M is the net magneticmoment of a single magnet.

  • disorder (float) – Switching threshold disorder as percentage of hc. If non-zero, sample switching from a normal distribution with mean hc and standard deviation hc * disorder.

  • h_ext (tuple of float) – External field (h_extx, h_exty).

  • neighbor_distance (float) – Neighborhood to consider when calculating dipole interactions. All spins within lattice_spacing * neighbor_distance are considered neighbors. Set neighbor_distance=np.inf for a global neighborhood.

  • switching ({'sw', 'budrikis'}) –

    Magnetic switching model:
    • ’sw’: Extended Stoner-Wohlfarth model

    • ’budrikis’: switching based on the parallel field component

  • sw_b (float) – Height of the Stoner-Wohlfarth astroid (parallel axis).

  • sw_c (float) – Width of the Stoner-Wohlfarth astroid (perpendicular axis).

  • sw_beta (float) – Pointiness of the top/bottom of the Stoner-Wohlfarth astroid (parallel axis).

  • sw_gamma (float) – Pointiness of the left/right of the Stoner-Wohlfarth astroid (perpendicular axis).

  • temperature (float (positive)) – Absolute temperature in Kelvin.

  • therm_timescale (float) – The thermal time scale (length in seconds of each simulated timestep). When temperature > 0, the thermal activity per timestep increases with therm_timescale. See also set_temperature().

  • m_therm (float) – Thermal nucleation moment (thermal nucleation volume * magnetic moment). See also set_temperature().

  • attempt_freq (float) – Attempt frequency (1/s). Only used for temperature calculations, see set_temperature().

  • flip_mode ({'single', 'max', 'max-rand', 'all'}) –

    Flip mode strategy:
    • ’single’: single uniform random flip (Budrikis Monte Carlo)

    • ’max’: flip the spin with maximum energy, break ties by index

    • ’max-rand’: flip the spin with maximum energy, break ties randomly

    • ’all’: flip all flippable spins

  • init ({1, -1, 'random', 'image.png'} or ndarray) – Initial spin state.

  • use_opencl (bool) – Use OpenCL acceleration.

  • opencl_platform (int) – Select OpenCL platform (if multiple GPUs of different families are installed).

  • opencl_device (int) – Select OpenCL device (if multiple GPUs of the same family are installed).

  • use_cuda (bool) – Use CUDA acceleration. NB! Requires compute platform 10 and above.

  • astroid_resolution (number of polar points in one rotation to resolve) – astroid shape for h_dist calculcations

_init_geometry()#

Initialize the geometry

Subclasses should override this method and return a tuple (pos, angle), where pos is an array with the (x, y) positions of the spins, while angle is an array with the rotations of the spins.

The base class implementation may be invoked to generate an Ising geometry.

_vertex_size = (3, 2)#
class flatspin.model.CustomSpinIce(*, magnet_coords=[[1, 1], [1, 2]], magnet_angles=[0, 90], radians=False, coords_as_labels=False, labels=None, **kwargs)#
Parameters
  • size (tuple of int) – The size of the spin ice (width, height). Note that the size is geometry specific.

  • lattice_spacing (float) – Spacing between each spin.

  • hc (float) – Mean switching threshold.

  • alpha (float) – Coupling strength alpha = u_0 * M / (4 * pi * a^3), where a is the lattice spacing and M is the net magneticmoment of a single magnet.

  • disorder (float) – Switching threshold disorder as percentage of hc. If non-zero, sample switching from a normal distribution with mean hc and standard deviation hc * disorder.

  • h_ext (tuple of float) – External field (h_extx, h_exty).

  • neighbor_distance (float) – Neighborhood to consider when calculating dipole interactions. All spins within lattice_spacing * neighbor_distance are considered neighbors. Set neighbor_distance=np.inf for a global neighborhood.

  • switching ({'sw', 'budrikis'}) –

    Magnetic switching model:
    • ’sw’: Extended Stoner-Wohlfarth model

    • ’budrikis’: switching based on the parallel field component

  • sw_b (float) – Height of the Stoner-Wohlfarth astroid (parallel axis).

  • sw_c (float) – Width of the Stoner-Wohlfarth astroid (perpendicular axis).

  • sw_beta (float) – Pointiness of the top/bottom of the Stoner-Wohlfarth astroid (parallel axis).

  • sw_gamma (float) – Pointiness of the left/right of the Stoner-Wohlfarth astroid (perpendicular axis).

  • temperature (float (positive)) – Absolute temperature in Kelvin.

  • therm_timescale (float) – The thermal time scale (length in seconds of each simulated timestep). When temperature > 0, the thermal activity per timestep increases with therm_timescale. See also set_temperature().

  • m_therm (float) – Thermal nucleation moment (thermal nucleation volume * magnetic moment). See also set_temperature().

  • attempt_freq (float) – Attempt frequency (1/s). Only used for temperature calculations, see set_temperature().

  • flip_mode ({'single', 'max', 'max-rand', 'all'}) –

    Flip mode strategy:
    • ’single’: single uniform random flip (Budrikis Monte Carlo)

    • ’max’: flip the spin with maximum energy, break ties by index

    • ’max-rand’: flip the spin with maximum energy, break ties randomly

    • ’all’: flip all flippable spins

  • init ({1, -1, 'random', 'image.png'} or ndarray) – Initial spin state.

  • use_opencl (bool) – Use OpenCL acceleration.

  • opencl_platform (int) – Select OpenCL platform (if multiple GPUs of different families are installed).

  • opencl_device (int) – Select OpenCL device (if multiple GPUs of the same family are installed).

  • use_cuda (bool) – Use CUDA acceleration. NB! Requires compute platform 10 and above.

  • astroid_resolution (number of polar points in one rotation to resolve) – astroid shape for h_dist calculcations

_init_geometry()#

Initialize the geometry

Subclasses should override this method and return a tuple (pos, angle), where pos is an array with the (x, y) positions of the spins, while angle is an array with the rotations of the spins.

The base class implementation may be invoked to generate an Ising geometry.