Skip to main content

PyState

Struct PyState 

Source
pub struct PyState(/* private fields */);
Expand description

A State object.

Implementations§

Source§

impl PyState

A single ‘assembly’, or ‘state’, containing a canvas with tiles at locations. Generally does not store concentration or temperature information, but does store time simulated.

Source

pub fn empty( shape: (usize, usize), kind: &str, tracking: &str, n_tile_types: Option<usize>, ) -> PyResult<Self>

Source

pub fn from_array( array: PyReadonlyArray2<'_, Tile>, kind: &str, tracking: &str, n_tile_types: Option<usize>, ) -> PyResult<Self>

Source

pub fn rate_array<'py>(&self, py: Python<'py>) -> Bound<'py, PyArray2<f64>>

Return a cloned copy of an array with the total possible next event rate for each point in the canvas. This is the deepest level of the quadtree for tree-based states.

§Returns

NDArray[np.uint]

Source

pub fn total_rate(&self) -> f64

float: the total rate of possible next events for the state.

Source

pub fn canvas_view<'py>( this: Bound<'py, Self>, _py: Python<'py>, ) -> PyResult<Bound<'py, PyArray2<Tile>>>

NDArray[np.uint]: a direct, mutable view of the state’s canvas. This is potentially unsafe.

Source

pub fn canvas_copy<'py>( this: &Bound<'py, Self>, py: Python<'py>, ) -> PyResult<Bound<'py, PyArray2<Tile>>>

Return a copy of the state’s canvas. This is safe, but can’t be modified and is slower than canvas_view.

§Returns

NDArray[np.uint] A cloned copy of the state’s canvas, in raw form.

Source

pub fn rate_at_point(&self, point: (usize, usize)) -> PyResult<f64>

Return the total possible next event rate at a specific canvas point.

§Parameters

point: tuple[int, int] The canvas point.

§Returns

f64

§Raises

ValueError if point is out of bounds for the canvas.

Source

pub fn tracking_copy(this: &Bound<'_, Self>) -> PyResult<RustAny>

Return a copy of the tracker’s tracking data.

§Returns

Any

Source

pub fn n_tiles(&self) -> NumTiles

int: the number of tiles in the state.

Source

pub fn ntiles(&self) -> NumTiles

int: the number of tiles in the state (deprecated, use n_tiles instead).

Source

pub fn total_events(&self) -> NumEvents

int: the total number of events that have occurred in the state.

Source

pub fn time(&self) -> f64

float: the total time the state has simulated, in seconds.

Source

pub fn tile_counts<'py>(&self, py: Python<'py>) -> Bound<'py, PyArray1<u32>>

Source

pub fn __repr__(&self) -> String

Source

pub fn print_debug(&self)

Source

pub fn write_json(&self, filename: &str) -> Result<(), RgrowError>

Write the state to a JSON file. This is inefficient, and is likely useful primarily for debugging.

Source

pub fn read_json(filename: &str) -> Result<Self, RgrowError>

Source

pub fn copy(&self) -> Self

Create a copy of the state.

This creates a complete clone of the state, including all canvas data, tracking information, and simulation state (time, events, etc.).

§Returns

State A new State object that is a copy of this state.

§Examples

original_state = State((10, 10)) copied_state = original_state.copy()

§The copied state is independent of the original

assert copied_state.time == original_state.time assert copied_state.total_events == original_state.total_events

Source

pub fn replay(&self, up_to_event: Option<u64>) -> PyResult<Self>

Replay the events from a MovieTracker up to a given event ID.

This reconstructs the state by replaying all events from the MovieTracker. The state must have been created with Movie tracking enabled.

§Parameters

up_to_event : int, optional The event ID up to which to replay (inclusive). If not provided, all events are replayed.

§Returns

State A new State with the events replayed. The returned state has no tracker and no rates calculated.

§Raises

ValueError If the state does not have a MovieTracker.

§Examples
§Create a state with movie tracking and evolve it

state = ts.create_state(tracking=“Movie”) sys.evolve(state, for_events=100)

§Replay to get state at event 50

replayed = state.replay(up_to_event=50)

Source

pub fn replay_inplace( &mut self, coords: Vec<(usize, usize)>, new_tiles: Vec<Tile>, event_ids: Vec<u64>, up_to_event_id: u64, n_tiles: Option<Vec<u32>>, total_time: Option<Vec<f64>>, energy: Option<Vec<f64>>, ) -> PyResult<()>

Replay events in-place on this state from external event data.

This modifies the state’s canvas by applying the events from the provided coordinate and tile arrays. Unlike replay(), this method takes external event data rather than using a MovieTracker.

§Parameters

coords : list[tuple[int, int]] List of (row, col) coordinates for each event. new_tiles : list[int] List of tile values for each event. event_ids : list[int] List of event IDs for each event. up_to_event_id : int The event ID up to which to replay (inclusive).

§Raises

ValueError If there is an error during replay.

§Examples

state = State((10, 10)) coords = [(1, 1), (2, 2)] new_tiles = [1, 2] event_ids = [0, 1] state.replay_inplace(coords, new_tiles, event_ids, 1)

Trait Implementations§

Source§

impl From<FFSStateRef> for PyState

Source§

fn from(state: FFSStateRef) -> Self

Converts to this type from the input type.
Source§

impl<'py> IntoPyObject<'py> for PyState

Source§

type Target = PyState

The Python output type
Source§

type Output = Bound<'py, <PyState as IntoPyObject<'py>>::Target>

The smart pointer type to use. Read more
Source§

type Error = PyErr

The type returned in the event of a conversion error.
Source§

fn into_pyobject( self, py: Python<'py>, ) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>

Performs the conversion.
Source§

impl PyClass for PyState

Source§

type Frozen = False

Whether the pyclass is frozen. Read more
Source§

impl PyClassImpl for PyState

Source§

const IS_BASETYPE: bool = false

#[pyclass(subclass)]
Source§

const IS_SUBCLASS: bool = false

#[pyclass(extends=…)]
Source§

const IS_MAPPING: bool = false

#[pyclass(mapping)]
Source§

const IS_SEQUENCE: bool = false

#[pyclass(sequence)]
Source§

const IS_IMMUTABLE_TYPE: bool = false

#[pyclass(immutable_type)]
Source§

const RAW_DOC: &'static CStr = /// A State object.

Docstring for the class provided on the struct or enum. Read more
Source§

const DOC: &'static CStr

Fully rendered class doc, including the text_signature if a constructor is defined. Read more
Source§

type BaseType = PyAny

Base class
Source§

type ThreadChecker = SendablePyClass<PyState>

This handles following two situations: Read more
Source§

type Inventory = Pyo3MethodsInventoryForPyState

Source§

type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild

Immutable or mutable
Source§

type Dict = PyClassDummySlot

Specify this class has #[pyclass(dict)] or not.
Source§

type WeakRef = PyClassDummySlot

Specify this class has #[pyclass(weakref)] or not.
Source§

type BaseNativeType = PyAny

The closest native ancestor. This is PyAny by default, and when you declare #[pyclass(extends=PyDict)], it’s PyDict.
Source§

fn items_iter() -> PyClassItemsIter

Source§

fn lazy_type_object() -> &'static LazyTypeObject<Self>

Source§

fn dict_offset() -> Option<isize>

Source§

fn weaklist_offset() -> Option<isize>

Source§

impl PyClassNewTextSignature for PyState

Source§

const TEXT_SIGNATURE: &'static str = "(shape, kind=\"Square\", tracking=\"None\", n_tile_types=None)"

Source§

impl PyTypeInfo for PyState

Source§

const NAME: &'static str = "State"

Class name.
Source§

const MODULE: Option<&'static str>

Module name, if any.
Source§

fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject

Returns the PyTypeObject instance for this type.
Source§

fn type_object(py: Python<'_>) -> Bound<'_, PyType>

Returns the safe abstraction over the type object.
Source§

fn is_type_of(object: &Bound<'_, PyAny>) -> bool

Checks if object is an instance of this type or a subclass of this type.
Source§

fn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool

Checks if object is an instance of this type.
Source§

impl DerefToPyAny for PyState

Source§

impl ExtractPyClassWithClone for PyState

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<'py, T> IntoPyObjectExt<'py> for T
where T: IntoPyObject<'py>,

Source§

fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>

Converts self into an owned Python object, dropping type information.
Source§

fn into_py_any(self, py: Python<'py>) -> Result<Py<PyAny>, PyErr>

Converts self into an owned Python object, dropping type information and unbinding it from the 'py lifetime.
Source§

fn into_pyobject_or_pyerr(self, py: Python<'py>) -> Result<Self::Output, PyErr>

Converts self into a Python object. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> PyErrArguments for T
where T: for<'py> IntoPyObject<'py> + Send + Sync,

Source§

fn arguments(self, py: Python<'_>) -> Py<PyAny>

Arguments for exception
Source§

impl<T> PyTypeCheck for T
where T: PyTypeInfo,

Source§

const NAME: &'static str = T::NAME

👎Deprecated since 0.27.0: Use ::classinfo_object() instead and format the type name at runtime. Note that using built-in cast features is often better than manual PyTypeCheck usage.
Name of self. This is used in error messages, for example.
Source§

fn type_check(object: &Bound<'_, PyAny>) -> bool

Checks if object is an instance of Self, which may include a subtype. Read more
Source§

fn classinfo_object(py: Python<'_>) -> Bound<'_, PyAny>

Returns the expected type as a possible argument for the isinstance and issubclass function. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> PlanCallbackArgs for T

Source§

impl<T> PlanCallbackOut for T

Source§

impl<T> Ungil for T
where T: Send,