:py:mod:`flatspin` ================== .. py:module:: flatspin Submodules ---------- .. toctree:: :titlesonly: :maxdepth: 1 cmdline/index.rst data/index.rst encoder/index.rst grid/index.rst model/index.rst plotting/index.rst runner/index.rst sweep/index.rst utils/index.rst vertices/index.rst Package Contents ---------------- Classes ~~~~~~~ .. autoapisummary:: flatspin.Grid flatspin.LabelIndexer flatspin.SpinIce flatspin.SquareSpinIce flatspin.SquareSpinIceClosed flatspin.SquareSpinIceOpen flatspin.PinwheelSpinIceDiamond flatspin.PinwheelSpinIceLuckyKnot flatspin.PinwheelSpinIceRandom flatspin.KagomeSpinIce flatspin.Dataset flatspin.Grid Functions ~~~~~~~~~ .. autoapisummary:: flatspin.find_vertices flatspin.vertex_type flatspin.get_default_params flatspin.plot_vectors flatspin.run Attributes ~~~~~~~~~~ .. autoapisummary:: flatspin.__version__ flatspin.normalize_rad flatspin.normalize_vertex_type flatspin.vertex_clist flatspin.vertex_cmap flatspin.hc .. py:data:: __version__ :annotation: = 1.0 .. py:class:: Grid(points, cell_size=None, padding=None) .. py:method:: centers(self) Return the centers of the grid cells .. py:method:: edges(self) Return the edges of the grid cells .. py:method:: center_grid(self) Make a grid with the cell centers .. py:method:: fixed_grid(cls, pos, grid_size) :classmethod: Make a grid with a fixed size .. py:method:: 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. See https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html#integer-array-indexing .. py:method:: point_index(self, grid_index) Map one grid index to zero or more point indices .. py:method:: map_values(self, values, fill_value=0, mask_empty=False) Map values onto the grid Returns a 2D array with the values mapped onto the grid .. py:method:: add_values(self, values, fill_value=0, mask_empty=False, method='sum') Add values to the grid Returns a 2D array with the values summed to the grid Parameters: ----------- values : array or list Values to map onto the grid cells fill_value : scalar Fill value for empty cells method : {'sum', 'mean'} How to aggregate multiple values which map to the same cell .. py:function:: find_vertices(grid, angle, win_size) Find the vertices of a geometry :param grid: The grid of the spin positions :type grid: Grid object :param angle: The angles of each spin :type angle: 1D array :param win_size: The window size to scan the grid :type win_size: (height, width) :param Returns a tuple (vi: :param vj: :param indices) where vi: :param vj are the vertex indices: :param and indices is a list of spin indices corresponding to each vertex: :param index.: .. py:function:: vertex_type(spin, angle) Determine the type of a vertex given its spins and angles .. py:function:: get_default_params(cls) .. py:function:: plot_vectors(XY, UV, C=None, arrows=True, relim=True, mask_zero=True, replace=False, **kwargs) .. 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 .. py:function:: run(model, encoder='sin', input=1, input_key=None, periods=100, spp=100, temp=0, temp_func='interp', **params) Run a flatspin simulation :param model: Model instance :type model: SpinIce :param encoder: Name of input encoder to use. See flatspin.encoder for a list of available encoders :type encoder: string or Encoder :param input: Input to be encoded float: constant input repeated periods times array: array of input to encode string: filename of table input data :type input: float, array or string :param input_key: Index into input (table column) :type input_key: int or str :param periods: Number of periods of the external field to run Only used if input is a float :type periods: int :param spp: Number of samples to save per input value :type spp: int :param temp: Temperature to be used float: constant temperature for whole run array: array of temperatures stretched to fit run :type temp: float, array :param params: Params to pass to the encoder :type params: dict .. py:class:: Dataset(index=None, params={}, info={}, basepath=None) Bases: :py:obj:`object` .. py:method:: name(self) :property: .. py:method:: __getitem__(self, i) .. py:method:: __repr__(self) Return repr(self). .. py:method:: __str__(self) Return str(self). .. py:method:: keys(self) .. py:method:: items(self) .. py:method:: iterrows(self) .. py:method:: __iter__(self) .. py:method:: __len__(self) .. py:method:: __eq__(self, other) Return self==value. .. py:method:: subset(self, i) .. py:method:: filter(self, **kwargs) .. py:method:: groupby(self, key) .. py:method:: sort_values(self, column) .. py:method:: row(self, row=0) .. py:method:: id(self, row=0) .. py:method:: read(basepath) :staticmethod: .. py:method:: save(self, basepath=None) .. py:method:: file(self, filename) .. py:method:: files(self, patterns=None, squash=True) .. py:method:: tablefile(self, tablename, squash=True) .. py:method:: tablefiles(self, patterns=None, squash=True) .. py:class:: Grid(points, cell_size=None, padding=None) .. py:method:: centers(self) Return the centers of the grid cells .. py:method:: edges(self) Return the edges of the grid cells .. py:method:: center_grid(self) Make a grid with the cell centers .. py:method:: fixed_grid(cls, pos, grid_size) :classmethod: Make a grid with a fixed size .. py:method:: 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. See https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html#integer-array-indexing .. py:method:: point_index(self, grid_index) Map one grid index to zero or more point indices .. py:method:: map_values(self, values, fill_value=0, mask_empty=False) Map values onto the grid Returns a 2D array with the values mapped onto the grid .. py:method:: add_values(self, values, fill_value=0, mask_empty=False, method='sum') Add values to the grid Returns a 2D array with the values summed to the grid Parameters: ----------- values : array or list Values to map onto the grid cells fill_value : scalar Fill value for empty cells method : {'sum', 'mean'} How to aggregate multiple values which map to the same cell