pub struct InferenceState {
    sketch: Sketch,
    sketch_received: bool,
    solver: Option<Arc<RwLock<InferenceSolver>>>,
    receiver_channel: Option<Receiver<String>>,
    finished_solver: Option<Result<FinishedInferenceSolver, String>>,
    results: Option<InferenceResults>,
}
Expand description

InferenceState manages the main functionalities and computations of inference session. That inludes boths the components that are exchanged with frontend, and raw low-level structures used during computation like symbolic graph and its colors.

Fields§

§sketch: Sketch

Boolean network sketch to run the inference on. Can be a placeholder at the beginning.

§sketch_received: bool

Flag signalling that the actual sketch data were received from editor session.

§solver: Option<Arc<RwLock<InferenceSolver>>>

Potential inference solver instance.

§receiver_channel: Option<Receiver<String>>

Potential channel to receive (text) updates from the solver instance.

§finished_solver: Option<Result<FinishedInferenceSolver, String>>

Copy of already finished inference solver instance, used to work with full inference results. If the inference ends with error, the error message is stored instead.

§results: Option<InferenceResults>

Potential simplified processed results of the inference.

Implementations§

source§

impl InferenceState

source

pub fn new_empty() -> InferenceState

Create new InferenceState with an empty placeholder sketch.

This is used to create a placeholder instance before the actual sketch data are sent from the editor session.

source

pub fn new(sketch: Sketch) -> InferenceState

Create new InferenceState with a full sketch data.

source

pub fn set_sketch(&mut self, sketch: Sketch)

Update the sketch data of this InferenceState.

source

pub fn get_sketch(&self) -> &Sketch

Get reference to the sketch data of this InferenceState.

source

pub fn get_results(&self) -> Result<InferenceResults, String>

Getter for pre-processed results from the internal solver. If the results were not fetched yet (inference still running), returns error.

This method is only a simple getter. See Self::try_fetch_results for actual result fetching.

source§

impl InferenceState

More complex methods involving dealing with async solver.

source

pub fn initiate_reset(&mut self)

If a computation solver is running, send cancellation flag to it. This is done asynchronously and might not happen immediately.

At the same time, all the inference-related fields of this InferenceState are reset. That is solver and results. The sketch stays the same.

source

pub fn try_fetch_results(&mut self) -> bool

Check if the inference solver finished its computation. If so, clone the important parts of the solver into Self.finished_solver field (so we can easily access it).

Return true if the fetch was successful (or results were already fetched before). Fetching is unsuccessful if the computation is still running (or there is no computation).

Once the true is returned by this method, we know the computation is over, the results are copied into finished_solver attribute and we can safely access them. If some error happened during inference computation, the finished_solver field contains an Err.

source

pub fn check_if_results_fetched(&mut self) -> bool

Check if the results were already fetched from the solver.

source

pub fn try_get_solver_progress( &mut self, ) -> Result<Vec<InferenceStatusReport>, String>

Check if there are any new messages from the solver (reporting on its progress). There can be more than one message. Each message is appended with a newline, and if there is more than one, they are combined.

Return error if there is no new message, computation is finished, or it was not started yet.

source

pub fn start_inference( &mut self, inference_type: InferenceType, ) -> Result<(), DynError>

Start the inference computation on a separate thread. If some previous computation is running, it is cancelled first.

The computation solver has its own thread. Method Self::try_fetch_results can be used to test if the results are ready (and fetch them if so). Method Self::try_get_solver_progress can be used to collect progress messages sent from the solver.

Trait Implementations§

source§

impl SessionHelper for InferenceState

source§

fn starts_with<'a, 'b>( prefix: &str, at_path: &'a [&'b str], ) -> Option<&'a [&'b str]>

A utility function which checks if at_path starts with a specific first segment. If yes, returns the remaining part of the path.
source§

fn matches(expected: &[&str], at_path: &[&str]) -> bool

A utility function which checks if at_path is exactly
source§

fn invalid_path_error_generic<T>(at_path: &[&str]) -> Result<T, DynError>

A utility function which emits a generic “invalid path” error.
source§

fn invalid_path_error_specific<T>( path: &[&str], component: &str, ) -> Result<T, DynError>

A utility function which emits a “invalid path” error mentioning specific state’s component.
source§

fn clone_payload_str(event: &Event, component: &str) -> Result<String, DynError>

A utility function to get and clone a payload of an event. Errors if payload is empty. Read more
source§

fn assert_path_length( path: &[&str], length: usize, component: &str, ) -> Result<(), DynError>

A utility function to assert that path has a given length, or emit a DynError otherwise. Read more
source§

fn assert_payload_empty(event: &Event, component: &str) -> Result<(), DynError>

A utility function to assert that payload is empty - otherwise, DynError is emitted. Read more
source§

impl SessionState for InferenceState

source§

fn perform_event( &mut self, event: &Event, at_path: &[&str], ) -> Result<Consumed, DynError>

Modify the session state using the provided event. The possible outcomes are described by Consumed.
source§

fn refresh( &self, full_path: &[String], at_path: &[&str], ) -> Result<Event, DynError>

“Read” session state into an event without modifying it.

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, 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

impl<T> Same for T

source§

type Output = T

Should always be Self
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.
§

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

§

fn vzip(self) -> V

§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T