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.
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.
pub fn empty( shape: (usize, usize), kind: &str, tracking: &str, n_tile_types: Option<usize>, ) -> PyResult<Self>
pub fn from_array( array: PyReadonlyArray2<'_, Tile>, kind: &str, tracking: &str, n_tile_types: Option<usize>, ) -> PyResult<Self>
Sourcepub fn rate_array<'py>(&self, py: Python<'py>) -> Bound<'py, PyArray2<f64>> ⓘ
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]
Sourcepub fn total_rate(&self) -> f64
pub fn total_rate(&self) -> f64
float: the total rate of possible next events for the state.
Sourcepub fn canvas_view<'py>(
this: Bound<'py, Self>,
_py: Python<'py>,
) -> PyResult<Bound<'py, PyArray2<Tile>>>
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.
Sourcepub fn canvas_copy<'py>(
this: &Bound<'py, Self>,
py: Python<'py>,
) -> PyResult<Bound<'py, PyArray2<Tile>>>
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.
Sourcepub fn tracking_copy(this: &Bound<'_, Self>) -> PyResult<RustAny>
pub fn tracking_copy(this: &Bound<'_, Self>) -> PyResult<RustAny>
Sourcepub fn ntiles(&self) -> NumTiles
pub fn ntiles(&self) -> NumTiles
int: the number of tiles in the state (deprecated, use n_tiles instead).
Sourcepub fn total_events(&self) -> NumEvents
pub fn total_events(&self) -> NumEvents
int: the total number of events that have occurred in the state.
pub fn tile_counts<'py>(&self, py: Python<'py>) -> Bound<'py, PyArray1<u32>> ⓘ
pub fn __repr__(&self) -> String
pub fn print_debug(&self)
Sourcepub fn write_json(&self, filename: &str) -> Result<(), RgrowError>
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.
pub fn read_json(filename: &str) -> Result<Self, RgrowError>
Sourcepub fn copy(&self) -> Self
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
Sourcepub fn replay(&self, up_to_event: Option<u64>) -> PyResult<Self>
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)
Sourcepub 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<()>
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
impl From<FFSStateRef> for PyState
Source§fn from(state: FFSStateRef) -> Self
fn from(state: FFSStateRef) -> Self
Source§impl<'py> IntoPyObject<'py> for PyState
impl<'py> IntoPyObject<'py> for PyState
Source§type Output = Bound<'py, <PyState as IntoPyObject<'py>>::Target>
type Output = Bound<'py, <PyState as IntoPyObject<'py>>::Target>
Source§fn into_pyobject(
self,
py: Python<'py>,
) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>
fn into_pyobject( self, py: Python<'py>, ) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>
Source§impl PyClassImpl for PyState
impl PyClassImpl for PyState
Source§const IS_BASETYPE: bool = false
const IS_BASETYPE: bool = false
Source§const IS_SUBCLASS: bool = false
const IS_SUBCLASS: bool = false
Source§const IS_MAPPING: bool = false
const IS_MAPPING: bool = false
Source§const IS_SEQUENCE: bool = false
const IS_SEQUENCE: bool = false
Source§const IS_IMMUTABLE_TYPE: bool = false
const IS_IMMUTABLE_TYPE: bool = false
Source§const RAW_DOC: &'static CStr = /// A State object.
const RAW_DOC: &'static CStr = /// A State object.
Source§const DOC: &'static CStr
const DOC: &'static CStr
text_signature if a constructor is defined. Read moreSource§type ThreadChecker = SendablePyClass<PyState>
type ThreadChecker = SendablePyClass<PyState>
type Inventory = Pyo3MethodsInventoryForPyState
Source§type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
Source§type BaseNativeType = PyAny
type BaseNativeType = PyAny
PyAny by default, and when you declare
#[pyclass(extends=PyDict)], it’s PyDict.fn items_iter() -> PyClassItemsIter
fn lazy_type_object() -> &'static LazyTypeObject<Self>
fn dict_offset() -> Option<isize>
fn weaklist_offset() -> Option<isize>
Source§impl PyClassNewTextSignature for PyState
impl PyClassNewTextSignature for PyState
const TEXT_SIGNATURE: &'static str = "(shape, kind=\"Square\", tracking=\"None\", n_tile_types=None)"
Source§impl PyTypeInfo for PyState
impl PyTypeInfo for PyState
Source§fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
Source§fn type_object(py: Python<'_>) -> Bound<'_, PyType>
fn type_object(py: Python<'_>) -> Bound<'_, PyType>
impl DerefToPyAny for PyState
impl ExtractPyClassWithClone for PyState
Auto Trait Implementations§
impl Freeze for PyState
impl RefUnwindSafe for PyState
impl Send for PyState
impl Sync for PyState
impl Unpin for PyState
impl UnsafeUnpin for PyState
impl UnwindSafe for PyState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreSource§impl<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
impl<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
Source§fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
self into an owned Python object, dropping type information.