Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend support for update and uninterpreted functions #28

Merged
merged 29 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
35c77f9
Unify concept of observability/essentiality for regulations.
ondrej33 Feb 6, 2024
6a17c24
WIP: Start adding parameters to the model.
ondrej33 Feb 6, 2024
0cbc67c
Add basic functionality regarding parameters.
ondrej33 Feb 6, 2024
bf7aa80
wip: Add events regarding parameters.
ondrej33 Feb 6, 2024
f98c066
Merge changes from main.
ondrej33 Feb 21, 2024
172e45c
WIP: Start adding uninterpreted and update functions.
ondrej33 Feb 21, 2024
8346189
WIP: Continue adding uninterpreted and update functions.
ondrej33 Feb 21, 2024
c48b61e
Extend basic skeleton for uninterpreted and update functions.
ondrej33 Feb 24, 2024
d95de05
Refactoring.
ondrej33 Feb 24, 2024
0d3c589
Add checks for name strings, refactor.
ondrej33 Feb 26, 2024
88c5d18
New code structure for the model's event API.
ondrej33 Feb 26, 2024
24f9a3c
Add initial working version of update & uninterpreted fns.
ondrej33 Feb 28, 2024
6664d6d
Reformatting.
ondrej33 Feb 28, 2024
90bad77
Update function parsing and function data.
ondrej33 Feb 29, 2024
88dd9b1
Add events for manipulation with update functions.
ondrej33 Feb 29, 2024
73a7ebf
Extend model's event API, refactor.
ondrej33 Mar 1, 2024
9f608c6
Extend model's API on frontend.
ondrej33 Mar 1, 2024
bd1953f
Finilize event API for uninterpreted fns.
ondrej33 Mar 2, 2024
39d2902
Add additional checks before variable/parameter removal and updates.
ondrej33 Mar 2, 2024
e09f5dd
Extend utilities for converting model to BN and add tests.
ondrej33 Mar 3, 2024
b4d7232
Extend checks before modifiying update/unintepreted functions.
ondrej33 Mar 4, 2024
d0c901a
Modify uninterpreted fn data.
ondrej33 Mar 10, 2024
78905b8
Update api for modifying functions.
ondrej33 Mar 10, 2024
b34f183
Start using the events for uninterpreted functions from the frontend.
ondrej33 Mar 10, 2024
6c3da13
Propagate errors from backend; fix bug in data refreshing.
ondrej33 Mar 12, 2024
8a79e8a
Fix updating of update/uninterpreted functions.
ondrej33 Mar 13, 2024
3822761
Merge UpdateFnData and VariableData structs for more straightforward …
ondrej33 Mar 14, 2024
868fc0d
Extend tests and documentation.
ondrej33 Mar 14, 2024
1d8ca3e
Minor refactor of events.
daemontus Mar 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@ edition = "2021"
[build-dependencies]
tauri-build = { version = "1.4", features = [] }

[[bin]]
name = "cli-test"
path = "src/bin/cli-test.rs"

[dependencies]
biodivine-lib-bdd = ">=0.5.6, <1.0.0"
biodivine-lib-param-bn = ">=0.5.0, <1.0.0"
biodivine-lib-bdd = ">=0.5.11, <1.0.0"
biodivine-lib-param-bn = ">=0.5.9, <1.0.0"
lazy_static = "1.4.0"
regex = "1.10.2"
tauri = { version = "1.4", features = [ "window-set-focus", "window-set-size", "window-close", "window-create", "dialog-all", "shell-open"] }
Expand Down
4 changes: 2 additions & 2 deletions src-tauri/src/app/state/editor/_state_editor_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ impl SessionState for EditorSession {
} else if let Some(at_path) = Self::starts_with("model", at_path) {
self.model.perform_event(event, at_path)
} else {
Self::invalid_path_error(at_path)
Self::invalid_path_error_generic(at_path)
}
}

Expand All @@ -209,7 +209,7 @@ impl SessionState for EditorSession {
} else if let Some(at_path) = Self::starts_with("model", at_path) {
self.model.refresh(full_path, at_path)
} else {
Self::invalid_path_error(at_path)
Self::invalid_path_error_generic(at_path)
}
}
}
4 changes: 2 additions & 2 deletions src-tauri/src/app/state/editor/_state_tab_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl SessionState for TabBarState {
} else if let Some(at_path) = Self::starts_with("pinned", at_path) {
self.pinned.perform_event(event, at_path)
} else {
Self::invalid_path_error(at_path)
Self::invalid_path_error_generic(at_path)
}
}

Expand All @@ -27,7 +27,7 @@ impl SessionState for TabBarState {
} else if let Some(at_path) = Self::starts_with("pinned", at_path) {
self.pinned.refresh(full_path, at_path)
} else {
Self::invalid_path_error(at_path)
Self::invalid_path_error_generic(at_path)
}
}
}
41 changes: 40 additions & 1 deletion src-tauri/src/app/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,52 @@ pub trait SessionHelper {
}

/// A utility function which emits a generic "invalid path" error.
fn invalid_path_error<T>(at_path: &[&str]) -> Result<T, DynError> {
fn invalid_path_error_generic<T>(at_path: &[&str]) -> Result<T, DynError> {
AeonError::throw(format!(
"`{}` cannot process path `{:?}`.",
std::any::type_name::<Self>(),
at_path
))
}

/// A utility function which emits a "invalid path" error mentioning specific state's `component`.
fn invalid_path_error_specific<T>(path: &[&str], component: &str) -> Result<T, DynError> {
AeonError::throw(format!("`{component}` cannot process path `{:?}`.", path))
}

/// A utility function to get and clone a payload of an event. Errors if payload is empty.
///
/// The `component` specifies which component of the state should be mentioned in the error.
/// This might be useful to directly mention relevant fields of more complex types.
fn clone_payload_str(event: &Event, component: &str) -> Result<String, DynError> {
let payload = event.payload.clone().ok_or(format!(
"This event to `{component}` cannot carry empty payload."
))?;
Ok(payload)
}

/// A utility function to assert that path has a given length, or emit a `DynError` otherwise.
///
/// The `component` specifies the state's component that should be mentioned in the error.
/// This might be useful to directly mention relevant fields of more complex types.
fn assert_path_length(path: &[&str], length: usize, component: &str) -> Result<(), DynError> {
if path.len() != length {
return AeonError::throw(format!("`{component}` cannot process path `{:?}`.", path));
}
Ok(())
}

/// A utility function to assert that payload is empty - otherwise, `DynError` is emitted.
///
/// The `component` specifies which component of the state should be mentioned in the error.
/// This might be useful to directly mention relevant fields of more complex types.
fn assert_payload_empty(event: &Event, component: &str) -> Result<(), DynError> {
if event.payload.is_some() {
let message = format!("This event to `{component}` cannot have empty payload.");
return AeonError::throw(message);
}
Ok(())
}
}

pub trait Session: SessionState {
Expand Down
19 changes: 0 additions & 19 deletions src-tauri/src/bin/cli-test.rs

This file was deleted.

12 changes: 10 additions & 2 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use aeon_sketchbook::app::event::{Event, UserAction};
use aeon_sketchbook::app::state::editor::EditorSession;
use aeon_sketchbook::app::state::{AppState, DynSession};
use aeon_sketchbook::app::{AeonApp, AEON_ACTION, AEON_REFRESH};
use aeon_sketchbook::app::{AeonApp, AEON_ACTION, AEON_REFRESH, AEON_VALUE};
use aeon_sketchbook::debug;
use serde::{Deserialize, Serialize};
use tauri::{command, Manager, State, Window};
Expand Down Expand Up @@ -62,7 +62,15 @@ fn main() {
let result = state.consume_event(&aeon, session_id.as_str(), &action);
if let Err(e) = result {
// TODO: This should be a normal error.
panic!("Event error: {:?}", e);
//panic!("Event error: {:?}", e);

// TODO: This is only a temporary solution to propagate the error message to frontend.
debug!("Error processing last event: `{}`.", e.to_string());
let json_message = format!("\"{e}\"");
let state_change = Event::build(&["error"], Some(&json_message));
if aeon.tauri.emit_all(AEON_VALUE, vec![state_change]).is_err() {
panic!("Event error failed to be sent: {:?}", e);
}
}
});
let aeon = aeon_original.clone();
Expand Down
51 changes: 51 additions & 0 deletions src-tauri/src/sketchbook/_binary_op.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use biodivine_lib_param_bn::BinaryOp as OtherBinaryOp;
use core::convert::From;
use serde::{Deserialize, Serialize};
use std::fmt::{Display, Error, Formatter};

/// Possible binary Boolean operators that can appear in `FnUpdate`.
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub enum BinaryOp {
And,
Or,
Xor,
Iff,
Imp,
}

impl From<OtherBinaryOp> for BinaryOp {
fn from(value: OtherBinaryOp) -> Self {
match value {
OtherBinaryOp::And => BinaryOp::And,
OtherBinaryOp::Or => BinaryOp::Or,
OtherBinaryOp::Xor => BinaryOp::Xor,
OtherBinaryOp::Iff => BinaryOp::Iff,
OtherBinaryOp::Imp => BinaryOp::Imp,
}
}
}

impl Display for BinaryOp {
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
let symbol = match self {
BinaryOp::And => "&",
BinaryOp::Or => "|",
BinaryOp::Xor => "^",
BinaryOp::Imp => "=>",
BinaryOp::Iff => "<=>",
};
write!(f, "{}", symbol)
}
}

impl BinaryOp {
pub fn to_lib_param_bn_version(&self) -> OtherBinaryOp {
match self {
BinaryOp::And => OtherBinaryOp::And,
BinaryOp::Or => OtherBinaryOp::Or,
BinaryOp::Xor => OtherBinaryOp::Xor,
BinaryOp::Iff => OtherBinaryOp::Iff,
BinaryOp::Imp => OtherBinaryOp::Imp,
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use serde::{Deserialize, Serialize};

/// Possible variants of observability of a `Regulation`.
/// Possible variants of essentiality of a `Regulation`.
///
/// - `True` means that the regulation is observable and must have an effect
/// - `True` means that the regulation is essential and must have an effect
/// - `False` means that it has no effect
/// - `Unknown` means it might or might not have an effect.
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub enum Observability {
pub enum Essentiality {
True,
False,
Unknown,
Expand Down
Loading
Loading