Skip to content

Commit

Permalink
Python documentation improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
cgevans committed Jun 29, 2024
1 parent 9f726cb commit f16e6a6
Show file tree
Hide file tree
Showing 6 changed files with 207 additions and 43 deletions.
29 changes: 6 additions & 23 deletions py-rgrow/rgrow/rgrow.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class TileShape(Enum):
Horizontal = ...

class EvolveOutcome(object): ...

class NeededUpdate(object): ...

class State(object):
Expand All @@ -27,9 +26,7 @@ class State(object):
def time(self) -> float: ...
@property
def total_events(self) -> int: ...
def print_debug(self) -> None:
"Print rust Debug string for the state object."
...
def print_debug(self) -> None: ...

class System(object):
@overload
Expand Down Expand Up @@ -83,9 +80,7 @@ class System(object):
) -> "Axes": ...
def get_param(self, name: str) -> Any: ...
def set_param(self, name: str, value: Any): ...
def print_debug(self) -> None:
"Print rust Debug string for the system object."
...
def print_debug(self) -> None: ...

class FissionHandling(object): ...
class CanvasType(object): ...
Expand All @@ -106,30 +101,18 @@ class FFSStateRef(object):
def tracking_copy(self) -> np.ndarray: ...
def clone_state(self) -> State: ...
def rate_at_point(self, point: tuple[int, int]) -> float: ...


class FFSLevelRef(object):
@property
def configs(self) -> list[np.ndarray]:
"""List of configurations at this level, as arrays (not full states)."""
...
def configs(self) -> list[np.ndarray]: ...
@property
def states(self) -> list[FFSStateRef]:
"""List of states at this level."""
...
def states(self) -> list[FFSStateRef]: ...
@property
def previous_indices(self) -> list[int]:
"""For each configuration, the index of the configuration in the previous
level that resulted in it."""
...
def previous_indices(self) -> list[int]: ...

class FFSRunResult(object):
@property
def nucleation_rate(self) -> float:
"""
The calculated nucleation rate, in M/s.
"""
...
def nucleation_rate(self) -> float: ...
@property
def forward_vec(self) -> np.ndarray: ...
@property
Expand Down
30 changes: 24 additions & 6 deletions rgrow/src/ffs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ use system::{DynSystem, Orientation, System, SystemEnum};

/// Configuration options for FFS.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "python", pyclass(get_all, set_all))]
#[cfg_attr(feature = "python", pyclass(get_all, set_all, module = "rgrow"))]
pub struct FFSRunConfig {
/// Use constant-variance, variable-configurations-per-surface method.
/// If false, use max_configs for each surface.
Expand Down Expand Up @@ -644,7 +644,7 @@ impl<St: ClonableState + StateWithCreate<Params = (usize, usize)>> FFSLevel<St>

// RESULTS CODE

#[cfg_attr(feature = "python", pyclass)]
#[cfg_attr(feature = "python", pyclass(module = "rgrow"))]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FFSRunResult {
#[serde(skip)]
Expand All @@ -656,7 +656,7 @@ pub struct FFSRunResult {
pub system: Option<SystemEnum>,
}

#[cfg_attr(feature = "python", pyclass)]
#[cfg_attr(feature = "python", pyclass(module = "rgrow"))]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FFSRunResultDF {
#[serde(skip)]
Expand Down Expand Up @@ -758,7 +758,7 @@ where
}
}

#[cfg_attr(feature = "python", pyclass)]
#[cfg_attr(feature = "python", pyclass(module = "rgrow"))]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FFSLevelResult {
pub state_list: Vec<Arc<StateEnum>>,
Expand Down Expand Up @@ -1218,6 +1218,11 @@ impl FFSRunResultDF {
// .collect()
// }

/// Get the surfaces as a Polars DataFrame.
///
/// Returns
/// -------
/// pl.DataFrame
#[pyo3(name = "surfaces_dataframe")]
fn py_surfaces_dataframe(&self) -> PyResult<pyo3_polars::PyDataFrame> {
Ok(PyDataFrame(self.surfaces_df.clone()))
Expand Down Expand Up @@ -1248,12 +1253,25 @@ impl FFSRunResultDF {
// .collect()
// }

/// Write dataframes and result data to files.
///
/// Parameters
/// ----------
/// prefix : str
/// Prefix for the filenames. The files will be named
/// `{prefix}.surfaces.parquet`, `{prefix}.configurations.parquet`, and
/// `{prefix}.ffs_result.json`.
#[pyo3(name = "write_files")]
fn py_write_files(&mut self, prefix: &str) -> PyResult<()> {
self.write_files(prefix)
.map_err(|e| PyPolarsErr::from(e).into())
}

/// Read dataframes and result data from files.
///
/// Returns
/// -------
/// Self
#[pyo3(name = "read_files")]
#[staticmethod]
fn py_read_files(prefix: &str) -> PyResult<Self> {
Expand All @@ -1268,7 +1286,7 @@ impl FFSRunResultDF {
// }
}

#[cfg_attr(feature = "python", pyclass)]
#[cfg_attr(feature = "python", pyclass(module = "rgrow"))]
#[allow(dead_code)] // This is used in the python interface
pub struct FFSLevelRef(Arc<FFSLevelResult>);

Expand Down Expand Up @@ -1323,7 +1341,7 @@ impl FFSLevelRef {
}
}

#[cfg_attr(feature = "python", pyclass)]
#[cfg_attr(feature = "python", pyclass(module = "rgrow"))]
#[allow(dead_code)] // This is used in the python interface
#[derive(Clone)]
pub struct FFSStateRef(Arc<StateEnum>);
Expand Down
9 changes: 9 additions & 0 deletions rgrow/src/models/ktam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,23 @@ pub struct KTAM {
/// at point P if tile T is in that direction. Eg, friends_e[T]
/// is a set of tiles that might attach at point P if T is east of
/// point P. The ones other than NESW are only for duples.
#[serde(skip)]
friends_n: Vec<HashSetType<Tile>>,
#[serde(skip)]
friends_e: Vec<HashSetType<Tile>>,
#[serde(skip)]
friends_s: Vec<HashSetType<Tile>>,
#[serde(skip)]
friends_w: Vec<HashSetType<Tile>>,
#[serde(skip)]
friends_ne: Vec<HashSetType<Tile>>,
#[serde(skip)]
friends_ee: Vec<HashSetType<Tile>>,
#[serde(skip)]
friends_se: Vec<HashSetType<Tile>>,
#[serde(skip)]
friends_ss: Vec<HashSetType<Tile>>,
#[serde(skip)]
friends_sw: Vec<HashSetType<Tile>>,

has_duples: bool,
Expand Down
Loading

0 comments on commit f16e6a6

Please sign in to comment.