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
impl InferenceState
sourcepub fn new_empty() -> InferenceState
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.
sourcepub fn new(sketch: Sketch) -> InferenceState
pub fn new(sketch: Sketch) -> InferenceState
Create new InferenceState
with a full sketch data.
sourcepub fn set_sketch(&mut self, sketch: Sketch)
pub fn set_sketch(&mut self, sketch: Sketch)
Update the sketch data of this InferenceState
.
sourcepub fn get_sketch(&self) -> &Sketch
pub fn get_sketch(&self) -> &Sketch
Get reference to the sketch data of this InferenceState
.
sourcepub fn get_results(&self) -> Result<InferenceResults, String>
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
impl InferenceState
More complex methods involving dealing with async solver.
sourcepub fn initiate_reset(&mut self)
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.
sourcepub fn try_fetch_results(&mut self) -> bool
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.
sourcepub fn check_if_results_fetched(&mut self) -> bool
pub fn check_if_results_fetched(&mut self) -> bool
Check if the results were already fetched from the solver.
sourcepub fn try_get_solver_progress(
&mut self,
) -> Result<Vec<InferenceStatusReport>, String>
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.
sourcepub fn start_inference(
&mut self,
inference_type: InferenceType,
) -> Result<(), DynError>
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
impl SessionHelper for InferenceState
source§fn starts_with<'a, 'b>(
prefix: &str,
at_path: &'a [&'b str],
) -> Option<&'a [&'b str]>
fn starts_with<'a, 'b>( prefix: &str, at_path: &'a [&'b str], ) -> Option<&'a [&'b str]>
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
fn matches(expected: &[&str], at_path: &[&str]) -> bool
at_path
is exactlysource§fn invalid_path_error_generic<T>(at_path: &[&str]) -> Result<T, DynError>
fn invalid_path_error_generic<T>(at_path: &[&str]) -> Result<T, DynError>
source§fn invalid_path_error_specific<T>(
path: &[&str],
component: &str,
) -> Result<T, DynError>
fn invalid_path_error_specific<T>( path: &[&str], component: &str, ) -> Result<T, DynError>
component
.