Skip to content

Commit

Permalink
Error modules (#36)
Browse files Browse the repository at this point in the history
* Develop (#35)

* adding glue module to enable error handling (#27)

* added batching runner (#28)

* Kings college london integration (#30)

* adding build using binary downloads (#8)

* adding build using binary downloads

* sorting out the build.rs

* updating build.rs for surrealml package

* prepping version for release

* now has target tracking (#10)

* adding check in build.rs for docs.rs

* removing build.rs for main surrealml to ensure that libraries using the core do not need to do anything in their build.rs

* adding machine learning pipelines for bioengineering projects at Kings College London

* Remove integrated_training_runner/run_env/ from tracking

* adding machine learning pipelines for bioengineering projects at Kings College London

* Update FFmpeg data access module and README (#29)

* adding run_env to the gitignore

---------

Co-authored-by: Yang Li <oliverlee2018@163.com>

* bumping the version

* updating the README and module

* updating the surrealml-core deployment workflow

* updating the surrealml-core deployment workflow

* updating cargo

---------

Co-authored-by: Sam Hillman <116303632+SHillman836@users.noreply.github.com>
Co-authored-by: Yang Li <oliverlee2018@163.com>

* merging error modules into the core

* merging error modules into the core

* merging error modules into the core

---------

Co-authored-by: Sam Hillman <116303632+SHillman836@users.noreply.github.com>
Co-authored-by: Yang Li <oliverlee2018@163.com>
  • Loading branch information
3 people authored Mar 14, 2024
1 parent 8c944f2 commit f09fbca
Show file tree
Hide file tree
Showing 24 changed files with 35 additions and 65 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
workspace = { members = ["modules/glue"] }

[package]
name = "surrealml"
version = "0.1.0"
Expand Down
10 changes: 9 additions & 1 deletion modules/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ license-file = "LICENSE"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
axum-feature = ["axum"]
actix-feature = ["actix-web"]
default = []

[dependencies]
regex = "1.9.3"
ort = { version = "1.16.2", features = ["load-dynamic"], default-features = false }
Expand All @@ -16,7 +21,10 @@ once_cell = "1.18.0"
bytes = "1.5.0"
futures-util = "0.3.28"
futures-core = "0.3.28"
glue = { git = "https://github.com/surrealdb/surrealml.git" }
thiserror = "1.0.57"
serde = { version = "1.0.197", features = ["derive"] }
axum = { version = "0.7.4", optional = true }
actix-web = { version = "4.5.1", optional = true }


[dev-dependencies]
Expand Down
7 changes: 0 additions & 7 deletions modules/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ This crate is just the Rust implementation of the Surml API. It is advised that

If nothing is configured the crate will compile the ONNX runtime into the binary. This is the default behaviour. However, if you want to use an ONNX runtime that is installed on your system, you can set the environment variable `ONNXRUNTIME_LIB_PATH` before you compile the crate. This will make the crate use the ONNX runtime that is installed on your system.

## Modules

This crate uses other modules. However, the other modules would have to be published if we wanted to refernece them via path. To avoid this, we reference the modules via the github url. This means that if a module is to be updated, the updates of that module need to be
pushed to the `main` branch of this repository before the core can reference the updates in that module. A good example of this would be our glue module as seen below:
```toml
glue = { git = "https://github.com/surrealdb/surrealml" }
```
This houses reusable errors that are used across all the crates in the Surml ecosystem, and these errors can construct HTTP responses for the Axum and Actix web frameworks.

## Nix Support
Expand Down
Empty file removed modules/core/src/error.rs
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 3 additions & 4 deletions modules/core/src/execution/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ use crate::storage::surml_file::SurMlFile;
use std::collections::HashMap;
use ndarray::{ArrayD, CowArray};
use ort::{SessionBuilder, Value, session::Input};

use super::onnx_environment::ENVIRONMENT;
use glue::{
safe_eject,
errors::error::{SurrealError, SurrealErrorStatus}
};
use crate::safe_eject;
use crate::errors::error::{SurrealError, SurrealErrorStatus};


/// A wrapper for the loaded machine learning model so we can perform computations on the loaded model.
Expand Down
1 change: 1 addition & 0 deletions modules/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
//! ```
pub mod storage;
pub mod execution;
pub mod errors;


/// Returns the version of the ONNX runtime that is used.
Expand Down
7 changes: 3 additions & 4 deletions modules/core/src/storage/header/keys.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
//! Defines the key bindings for input data.
use std::collections::HashMap;
use glue::{
errors::error::{SurrealError, SurrealErrorStatus},
safe_eject_internal
};

use crate::safe_eject_internal;
use crate::errors::error::{SurrealError, SurrealErrorStatus};


/// Defines the key bindings for input data.
Expand Down
9 changes: 2 additions & 7 deletions modules/core/src/storage/header/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,8 @@ use version::Version;
use engine::Engine;
use origin::Origin;
use input_dims::InputDims;
use glue::{
safe_eject,
errors::error::{
SurrealError,
SurrealErrorStatus
}
};
use crate::safe_eject;
use crate::errors::error::{SurrealError, SurrealErrorStatus};


/// The header of the model file.
Expand Down
6 changes: 2 additions & 4 deletions modules/core/src/storage/header/normalisers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ pub mod wrapper;
use super::keys::KeyBindings;
use utils::{extract_label, extract_two_numbers};
use wrapper::NormaliserType;
use glue::{
safe_eject_option,
errors::error::{SurrealError, SurrealErrorStatus}
};
use crate::safe_eject_option;
use crate::errors::error::{SurrealError, SurrealErrorStatus};


/// A map of normalisers so they can be accessed by column name and input index.
Expand Down
4 changes: 2 additions & 2 deletions modules/core/src/storage/header/normalisers/utils.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//! Utility functions for normalisers to reduce code duplication in areas that cannot be easily defined in a struct.
use regex::{Regex, Captures};
use glue::{
use crate::{
safe_eject_option,
safe_eject_internal,
errors::error::{SurrealError, SurrealErrorStatus}
};
use crate::errors::error::{SurrealError, SurrealErrorStatus};


/// Extracts the label from a normaliser string.
Expand Down
7 changes: 3 additions & 4 deletions modules/core/src/storage/header/normalisers/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ use super::log_scale;
use super::z_score;
use super::utils::{extract_label, extract_two_numbers};
use super::traits::Normaliser;
use glue::{
safe_eject_option,
errors::error::{SurrealError, SurrealErrorStatus}
};

use crate::safe_eject_option;
use crate::errors::error::{SurrealError, SurrealErrorStatus};


/// A wrapper for all different types of normalisers.
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/storage/header/origin.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Defines the origin of the model in the file.
use glue::errors::error::{SurrealError, SurrealErrorStatus};
use crate::errors::error::{SurrealError, SurrealErrorStatus};

use super::string_value::StringValue;

Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/storage/header/output.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Defines the struct housing data around the outputs of the model.
use super::normalisers::wrapper::NormaliserType;
use glue::{
use crate::{
safe_eject_option,
errors::error::{
SurrealError,
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/storage/header/version.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Defines the process of managing the version of the `surml` file in the file.
use glue::{
use crate::{
safe_eject_option,
safe_eject,
errors::error::{
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/storage/stream_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use futures_core::stream::Stream;
use futures_core::task::{Context, Poll};
use std::pin::Pin;
use std::error::Error;
use glue::{
use crate::{
safe_eject,
errors::error::{
SurrealError,
Expand Down
4 changes: 2 additions & 2 deletions modules/core/src/storage/surml_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
use std::fs::File;
use std::io::{Read, Write};

use crate::storage::header::Header;
use glue::{
use crate::{
safe_eject_internal,
safe_eject,
storage::header::Header,
errors::error::{
SurrealError,
SurrealErrorStatus
Expand Down
17 changes: 0 additions & 17 deletions modules/glue/Cargo.toml

This file was deleted.

4 changes: 0 additions & 4 deletions modules/glue/README.md

This file was deleted.

1 change: 0 additions & 1 deletion modules/glue/src/lib.rs

This file was deleted.

6 changes: 3 additions & 3 deletions src/python_apis/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ pub fn add_description(file_id: String, description: String) {
pub fn add_version(file_id: String, version: String) {
let mut python_state = PYTHON_STATE.lock().unwrap();
let wrapped_file = python_state.get_mut(&file_id).unwrap();
wrapped_file.header.add_version(version);
let _ = wrapped_file.header.add_version(version);
}


Expand Down Expand Up @@ -161,7 +161,7 @@ pub fn add_author(file_id: String, author: String) {
pub fn add_origin(file_id: String, origin: String) {
let mut python_state = PYTHON_STATE.lock().unwrap();
let wrapped_file = python_state.get_mut(&file_id).unwrap();
wrapped_file.header.add_origin(origin);
let _ = wrapped_file.header.add_origin(origin);
}


Expand Down Expand Up @@ -213,7 +213,7 @@ pub fn add_normaliser(file_id: String, column_name: String, normaliser_label: St
let normaliser = NormaliserType::new(normaliser_label, one, two);
let mut python_state = PYTHON_STATE.lock().unwrap();
let file = python_state.get_mut(&file_id).unwrap();
file.header.normalisers.add_normaliser(normaliser, column_name, &file.header.keys);
let _ = file.header.normalisers.add_normaliser(normaliser, column_name, &file.header.keys);
}


Expand Down

0 comments on commit f09fbca

Please sign in to comment.