:py:mod:`flatspin.model` ======================== .. py:module:: flatspin.model Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: flatspin.model.LabelIndexer flatspin.model.SpinIce flatspin.model.SquareSpinIce flatspin.model.SquareSpinIceClosed flatspin.model.SquareSpinIceOpen flatspin.model.PinwheelSpinIceDiamond flatspin.model.PinwheelSpinIceLuckyKnot flatspin.model.PinwheelSpinIceRandom flatspin.model.KagomeSpinIce Attributes ~~~~~~~~~~ .. autoapisummary:: flatspin.model.normalize_rad flatspin.model.normalize_vertex_type flatspin.model.vertex_clist flatspin.model.vertex_cmap flatspin.model.hc .. py:data:: normalize_rad .. py:data:: normalize_vertex_type .. py:data:: vertex_clist :annotation: = [[0, 1, 0], [0, 0, 1], [1, 0, 0], [0.5, 0.5, 0.5]] .. py:data:: vertex_cmap .. py:class:: LabelIndexer(labels) .. py:method:: __getitem__(self, label) .. py:method:: __repr__(self) Return repr(self). .. py:class:: 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: :py:obj:`object` Ising spin lattice .. py:attribute:: _vertex_size :annotation: = [2, 1] .. py:method:: N(self) :property: Alias for self.spin_count .. py:method:: label(self, i) Get the label of a given spin index or list of indices .. py:method:: indexof(self, label) Get the spin index of a given label or range of labels Alias for self.L[label] .. py:method:: indices(self) Get all spin indices .. py:method:: 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 .. py:method:: _init_spin(self, init) .. py:method:: _init_geometry(self) .. py:method:: _init_threshold(self) .. py:method:: _init_neighbor_list(self) .. py:method:: _init_h_dip(self) .. py:method:: __getstate__(self) .. py:method:: __eq__(self, other) Return self==value. .. py:method:: width(self) :property: .. py:method:: height(self) :property: .. py:method:: vectors(self) :property: Spin vectors .. py:method:: set_spin(self, spin) .. py:method:: 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 .. py:method:: set_threshold(self, threshold) .. py:method:: 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)) .. py:method:: set_h_ext_grid(self, h_ext) .. py:method:: set_temperature(self, std) .. py:method:: randomize(self, prob=0.5) .. py:method:: polarize(self) .. py:method:: update_thermal_noise(self) Resamples thermal noise. Samples x and y components of noise from normal distribution .. py:method:: neighbors(self, i) .. py:method:: spin_dipolar_field(self, i, j) Calculate dipolar field between spin i and j relative to positive spin .. py:method:: dipolar_field(self, i) Calculate total dipolar field parallell to spin i .. py:method:: dipolar_fields(self) .. py:method:: _h_dip(self) :property: .. py:method:: _h_dip_local(self, i) .. py:method:: external_field(self, i) Calculate external field parallel and perpendicular to spin i .. py:method:: external_fields(self) Calculate external fields parallel and perpendicular to all spins .. py:method:: thermal_field(self, i) .. py:method:: thermal_fields(self) .. py:method:: total_field(self, i) Calculate the total field parallel to spin i .. py:method:: total_fields(self) .. py:method:: flip(self, i) .. py:method:: _switching_energy_budrikis(self) .. py:method:: _switching_energy_sw(self) .. py:method:: switching_energy(self) .. py:method:: flippable_energy(self) .. py:method:: flippable(self) .. py:method:: step(self) Perform a flip of one or more flippable spins .. py:method:: relax(self) Flip spins until equilibrium, return number of calls to step() .. py:method:: energy(self) .. py:method:: total_energies(self) .. py:method:: total_energy(self) .. py:method:: total_magnetization(self) .. py:method:: 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. .. py:method:: vertices(self) Get the spin indices of all vertices .. py:method:: vertex_indices(self) Get all vertex indices .. py:method:: vertex_type(self, v) Get the vertex type for a vertex where v are the spin indices of the vertex .. py:method:: 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. .. py:method:: 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. .. py:method:: vertex_pos(self, v) Get the position of a vertex where v are the spin indices of the vertex .. py:method:: vertex_mag(self, v) Get the direction of a vertex v .. py:method:: _default_cell_size(self) :property: .. py:method:: 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 .. py:method:: 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. .. py:method:: set_grid(self, attr, values) Map grid values onto some spin attribute. Valid attributes: spin, h_ext .. py:method:: 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. .. py:method:: spin_grid(self, cell_size=None) Project the spin vectors onto a grid. See view_grid() for information about cell_size .. py:method:: plot(self, arrows=True, **kwargs) .. py:method:: plot_energy(self, arrows=True) .. py:method:: plot_vertices(self) .. py:method:: plot_vertex_mag(self, arrows=True, **kwargs) .. py:method:: _init_h_dip_cl(self) .. py:method:: _init_cl(self) .. py:method:: _total_fields_cl(self) .. py:method:: _h_dip_local_cl(self) .. py:method:: _external_fields_cl(self) .. py:class:: 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: :py:obj:`SpinIce` Ising spin lattice .. py:class:: SquareSpinIceClosed(*, lattice_spacing=2 * np.cos(np.pi / 4), edge='symmetric', **kwargs) Bases: :py:obj:`SquareSpinIce` Ising spin lattice .. py:attribute:: _vertex_size :annotation: = [3, 3] .. py:method:: _init_geometry(self) .. py:method:: _init_spin(self, init) .. py:method:: _default_cell_size(self) :property: .. py:class:: SquareSpinIceOpen(*, neighbor_distance=sqrt(2), **kwargs) Bases: :py:obj:`SquareSpinIce` Ising spin lattice .. py:attribute:: _vertex_size :annotation: = [2, 2] .. py:method:: _init_geometry(self) .. py:class:: PinwheelSpinIceDiamond(*, spin_angle=45, neighbor_distance=10, **kwargs) Bases: :py:obj:`SquareSpinIceClosed` Ising spin lattice .. py:method:: _init_geometry(self) .. py:class:: PinwheelSpinIceLuckyKnot(*, spin_angle=45, neighbor_distance=10 * sqrt(2), **kwargs) Bases: :py:obj:`SquareSpinIceOpen` Ising spin lattice .. py:method:: _init_geometry(self) .. py:class:: PinwheelSpinIceRandom(*, spin_angle_disorder=0, **kwargs) Bases: :py:obj:`PinwheelSpinIceDiamond` Ising spin lattice .. py:method:: _init_geometry(self) .. py:class:: 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: :py:obj:`SpinIce` Ising spin lattice .. py:attribute:: _vertex_size :annotation: = [2, 3] .. py:method:: _init_geometry(self) .. py:method:: _default_cell_size(self) :property: .. py:data:: hc :annotation: = 11.25