emulsim.state module

Provides a class representing the full system state of multiple elements.

digraph inheritanceaeffdaa5f7 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "DictElementBase" [URL="emulsim.elements.base.html#emulsim.elements.base.DictElementBase",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Element storing data in a dictionary of states."]; "State" [URL="#emulsim.state.State",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Defines the state of the simulation as a collection of elements."]; "DictElementBase" -> "State" [arrowsize=0.5,style="setlinewidth(0.5)"]; }
class State(elements: dict[str, _ElementBase] | None = None, parameters: dict[str, Any] | None = None)[source]

Bases: DictElementBase

Defines the state of the simulation as a collection of elements.

Parameters Dictionary:
  • bounds: Bounds of the simulation box, which affects plotting (default=None)

  • invisible_elements: Collection of elements that will not be plotted (default=set())

  • plot_args: Extra arguments for plotting this element (default={})

Parameters:
  • elements (dict) – Lists the elements in the simulation. The key in this dictionary gives the name of the element, while the associated value should be an instance of _ElementBase.

  • parameters (dict) – Parameters that affect the entire state

Parameters of State:

plot_args

Extra arguments for plotting this element (Default value: {})

bounds

Bounds of the simulation box, which affects plotting (Default value: None)

invisible_elements

Collection of elements that will not be plotted (Default value: set())

add_element(name: str, element: _ElementBase)[source]

Adds an element to the simulation.

Parameters:
  • name (str) – The identifier for the element.

  • element (_ElementBase) – The instance defining the element.

copy(method: Literal['clean', 'shallow', 'data'] = 'clean', data=None)[source]

Create a copy of the state.

Parameters:
  • method (str) – Determines whether a clean, shallow, or data copy is performed. See copy() for details.

  • data – Data to be used instead of the one in the current state. This data is used as is and not copied!

Returns:

A copy of the current state object

data: dict[str, _ElementBase]
property degrees_of_freedom: int

the number of degrees of freedom of the simulation

Type:

int

property elements: dict[str, _ElementBase]
classmethod from_data(attributes: dict[str, Any], data=None) State[source]

Create the state from attributes and data.

Parameters:
  • attributes (dict) – Attributes of the element. This carries information about parameters and possibly additional parts that do not depend on time.

  • data (ndarray) – The numerical data associated with the state of the element

get_index(name: str) int[source]

Returns the numerical index of a specific element.

Parameters:

name (str) – The name of the element

get_quantities(property_name: str) dict[str, Any][source]

Returns quantities obtained from the elements.

Quantities are typically implemented as properties or attributes of the elements. If an element does not have a property, it is silently ignored and not included in the result.

Parameters:

property_name (str) – The name of the property or attribute that is analyzed

Returns:

The value of the quantity is returned for each element. Elements that do not define the quantity are not included.

Return type:

dict

get_quantity(property_name: str, total: bool = True)[source]

Returns quantities obtained from the elements.

Quantities are typically implemented as properties or attributes. If an element does not have a property, it is silently ignored and not included in the result.

Parameters:
  • property_name (str) – The name of the property or attribute that is analyzed

  • total (bool) – Flag determining whether the sum of all values is returned. If False, the properties are returned for each element individually.

Returns:

A total value is returned if total is True. Otherwise, the value for each element is returned in a dictionary. Note that elements that do not define the quantity are not included.

Return type:

float or dict

This function has been deprecated on 2022-06-16

get_total_quantity(property_name: str) float[source]

Returns quantities summed over all elements.

Quantities are typically implemented as properties or attributes. If an element does not have a property, it is silently ignored and not included in the result.

Parameters:

property_name (str) – The name of the property or attribute that is analyzed

Returns:

A total value is returned if total is True. Otherwise, the value for each element is returned in a dictionary. Note that elements that do not define the quantity are not included.

Return type:

float or dict

property grid: GridBase

a grid representing the entire state.

Type:

GridBase

items()[source]
keys()[source]
parameters_default = [Parameter(name='bounds', default_value=None, cls=<class 'object'>, description='Bounds of the simulation box, which affects plotting', choices=None, required=False, hidden=False, extra={}), Parameter(name='invisible_elements', default_value=set(), cls=<class 'set'>, description='Collection of elements that will not be plotted', choices=None, required=False, hidden=False, extra={})]

parameters (with default values) of this subclass

Type:

list

plot(element_args: dict[str, Any] | None = None, invisible_elements: Iterable[str] | None = None, *args, title: str | None = None, filename: str | None = None, action: Literal['auto', 'close', 'none', 'sca', 'show'] = 'auto', ax_style: dict[str, Any] | None = None, fig_style: dict[str, Any] | None = None, ax=None, **kwargs)[source]

Visualize the state.

Parameters:
  • element_args (dict) – A dictionary with arguments passed to the plotting functions of individual elements

  • invisible_elements (list) – A list of elements that will not be plotted.

  • title (str) – Title of the plot. If omitted, the title might be chosen automatically.

  • filename (str, optional) – If given, the plot is written to the specified file.

  • action (str) – Decides what to do with the final figure. If the argument is set to show, matplotlib.pyplot.show() will be called to show the plot. If the value is none, the figure will be created, but not necessarily shown. The value close closes the figure, after saving it to a file when filename is given. The default value auto implies that the plot is shown if it is not a nested plot call.

  • ax_style (dict) – Dictionary with properties that will be changed on the axis after the plot has been drawn by calling matplotlib.pyplot.setp(). A special item i this dictionary is use_offset, which is flag that can be used to control whether offset are shown along the axes of the plot.

  • fig_style (dict) – Dictionary with properties that will be changed on the figure after the plot has been drawn by calling matplotlib.pyplot.setp(). For instance, using fig_style={‘dpi’: 200} increases the resolution of the figure.

  • ax (matplotlib.axes.Axes) – Figure axes to be used for plotting. The special value “create” creates a new figure, while “reuse” attempts to reuse an existing figure, which is the default.

  • **kwargs – All additional arguments are passed to all plotting functions

plot_interactive(*, grid: GridBase | None = None, viewer_args: dict[str, Any] | None = None, **kwargs)[source]

Create an interactive plot of the field using napari

Parameters:
  • ( (grid) – ~pde.grids.base.GridBase`): The grid that defines the space in which the simulation takes place. If omitted, we try to determine it automatically from the elements in the state.

  • viewer_args (dict) – Arguments passed to napari.viewer.Viewer to affect the viewer

  • **kwargs – Extra arguments passed to all plotting function

values()[source]