Skip to main content

PhiloteError

Enum PhiloteError 

Source
pub enum PhiloteError {
Show 14 variants VariableNotFound(String), ShapeMismatch { expected: Vec<usize>, actual: Vec<usize>, }, InvalidVariableType(String), DisciplineNotInitialized, SetupNotCalled, InvalidOption { name: String, }, IndexOutOfBounds { index: usize, size: usize, }, GrpcError(Box<Status>), ProtobufError(DecodeError), IoError(Error), ArrayError(String), NotImplemented(String), ConfigurationError(String), Cancelled,
}
Expand description

Error types for Philote operations

Variants§

§

VariableNotFound(String)

§

ShapeMismatch

Fields

§expected: Vec<usize>
§actual: Vec<usize>
§

InvalidVariableType(String)

§

DisciplineNotInitialized

§

SetupNotCalled

§

InvalidOption

Fields

§name: String
§

IndexOutOfBounds

Fields

§index: usize
§size: usize
§

GrpcError(Box<Status>)

§

ProtobufError(DecodeError)

§

IoError(Error)

§

ArrayError(String)

§

NotImplemented(String)

§

ConfigurationError(String)

§

Cancelled

Implementations§

Source§

impl PhiloteError

Source

pub fn array_error<S: Into<String>>(msg: S) -> Self

Create an array operation error with a custom message

Examples found in repository?
examples/paraboloid.rs (line 140)
130    async fn compute(&self, inputs: &ArrayMap) -> Result<ArrayMap> {
131        let x = inputs
132            .get("x")
133            .ok_or_else(|| PhiloteError::VariableNotFound("x".to_string()))?;
134
135        let y = inputs
136            .get("y")
137            .ok_or_else(|| PhiloteError::VariableNotFound("y".to_string()))?;
138
139        if x.len() != 1 || y.len() != 1 {
140            return Err(PhiloteError::array_error("Expected scalar inputs"));
141        }
142
143        let x_val = x[[0]];
144        let y_val = y[[0]];
145
146        // f = (x - 3)^2 + x*y + (y + 4)^2 - 3
147        let f_val = (x_val - 3.0).powi(2) + x_val * y_val + (y_val + 4.0).powi(2) - 3.0;
148
149        let mut outputs = HashMap::new();
150        let f_array = ArrayD::from_elem(vec![1], f_val);
151        outputs.insert("f".to_string(), f_array);
152
153        Ok(outputs)
154    }
155
156    async fn compute_partials(&self, inputs: &ArrayMap) -> Result<PartialMap> {
157        let x = inputs
158            .get("x")
159            .ok_or_else(|| PhiloteError::VariableNotFound("x".to_string()))?;
160
161        let y = inputs
162            .get("y")
163            .ok_or_else(|| PhiloteError::VariableNotFound("y".to_string()))?;
164
165        if x.len() != 1 || y.len() != 1 {
166            return Err(PhiloteError::array_error("Expected scalar inputs"));
167        }
168
169        let x_val = x[[0]];
170        let y_val = y[[0]];
171
172        // df/dx = 2*(x - 3) + y
173        let df_dx = 2.0 * (x_val - 3.0) + y_val;
174
175        // df/dy = x + 2*(y + 4)
176        let df_dy = x_val + 2.0 * (y_val + 4.0);
177
178        let mut partials = HashMap::new();
179        partials.insert(
180            ("f".to_string(), "x".to_string()),
181            ArrayD::from_elem(vec![1], df_dx),
182        );
183        partials.insert(
184            ("f".to_string(), "y".to_string()),
185            ArrayD::from_elem(vec![1], df_dy),
186        );
187
188        Ok(partials)
189    }
More examples
Hide additional examples
examples/server_runner.rs (line 139)
129    async fn compute(&self, inputs: &ArrayMap) -> Result<ArrayMap> {
130        let x = inputs
131            .get("x")
132            .ok_or_else(|| PhiloteError::VariableNotFound("x".to_string()))?;
133
134        let y = inputs
135            .get("y")
136            .ok_or_else(|| PhiloteError::VariableNotFound("y".to_string()))?;
137
138        if x.len() != 1 || y.len() != 1 {
139            return Err(PhiloteError::array_error("Expected scalar inputs"));
140        }
141
142        let x_val = x[[0]];
143        let y_val = y[[0]];
144
145        // f = (x - 3)^2 + x*y + (y + 4)^2 - 3
146        let f_val = (x_val - 3.0).powi(2) + x_val * y_val + (y_val + 4.0).powi(2) - 3.0;
147
148        println!("🧮 Computing: x={}, y={} => f={}", x_val, y_val, f_val);
149
150        let mut outputs = HashMap::new();
151        let f_array = ArrayD::from_elem(vec![1], f_val);
152        outputs.insert("f".to_string(), f_array);
153
154        Ok(outputs)
155    }
156
157    async fn compute_partials(&self, inputs: &ArrayMap) -> Result<PartialMap> {
158        let x = inputs
159            .get("x")
160            .ok_or_else(|| PhiloteError::VariableNotFound("x".to_string()))?;
161
162        let y = inputs
163            .get("y")
164            .ok_or_else(|| PhiloteError::VariableNotFound("y".to_string()))?;
165
166        if x.len() != 1 || y.len() != 1 {
167            return Err(PhiloteError::array_error("Expected scalar inputs"));
168        }
169
170        let x_val = x[[0]];
171        let y_val = y[[0]];
172
173        // df/dx = 2*(x - 3) + y
174        let df_dx = 2.0 * (x_val - 3.0) + y_val;
175
176        // df/dy = x + 2*(y + 4)
177        let df_dy = x_val + 2.0 * (y_val + 4.0);
178
179        println!("📊 Computing gradients: df/dx={}, df/dy={}", df_dx, df_dy);
180
181        let mut partials = HashMap::new();
182        partials.insert(
183            ("f".to_string(), "x".to_string()),
184            ArrayD::from_elem(vec![1], df_dx),
185        );
186        partials.insert(
187            ("f".to_string(), "y".to_string()),
188            ArrayD::from_elem(vec![1], df_dy),
189        );
190
191        Ok(partials)
192    }
Source

pub fn not_implemented<S: Into<String>>(feature: S) -> Self

Create a “not implemented” error for features not yet supported

Source

pub fn config_error<S: Into<String>>(msg: S) -> Self

Create a configuration error with a custom message

Examples found in repository?
examples/server_runner.rs (line 211)
196async fn main() -> Result<()> {
197    println!("🚀 Starting Philote Rust Server Example");
198
199    // Create and initialize the discipline
200    let mut discipline = ParaboloidDiscipline::new();
201    discipline.initialize()?;
202    discipline.setup()?;
203    discipline.setup_partials()?;
204
205    // Create the server
206    let server = ExplicitServer::new(discipline).with_verbose(true);
207
208    // Define the address
209    let addr: SocketAddr = "127.0.0.1:50051"
210        .parse()
211        .map_err(|e| PhiloteError::config_error(format!("Invalid address: {}", e)))?;
212
213    println!("🌐 Server listening on: {}", addr);
214    println!("📡 Ready to accept client connections!");
215    println!("💡 You can now run the client_example to test the connection.");
216
217    // Start the gRPC server with both ExplicitService and DisciplineService
218    // We need to use std::sync::Arc to share ownership between the two services
219    let server_arc = std::sync::Arc::new(server);
220
221    Server::builder()
222        .add_service(ExplicitServiceServer::from_arc(server_arc.clone()))
223        .add_service(DisciplineServiceServer::from_arc(server_arc))
224        .serve(addr)
225        .await
226        .map_err(|e| PhiloteError::config_error(format!("Server failed: {}", e)))?;
227
228    Ok(())
229}
More examples
Hide additional examples
examples/client_example.rs (line 307)
144pub async fn start_test_server() -> Result<()> {
145    use philote_mdo::{
146        philote_info::{VariableMetaData, VariableType},
147        server::ExplicitServer,
148        traits::{Discipline, ExplicitDiscipline},
149    };
150    use std::net::SocketAddr;
151    use tonic::transport::Server;
152
153    // This is a simplified version of our paraboloid discipline
154    struct TestParaboloid {
155        variables: Vec<VariableMetaData>,
156        partials: Vec<(String, String)>,
157        options: HashMap<String, String>,
158    }
159
160    impl TestParaboloid {
161        fn new() -> Self {
162            Self {
163                variables: Vec::new(),
164                partials: Vec::new(),
165                options: HashMap::new(),
166            }
167        }
168    }
169
170    impl Discipline for TestParaboloid {
171        fn name(&self) -> &str {
172            "TestParaboloid"
173        }
174        fn version(&self) -> &str {
175            "1.0.0"
176        }
177        fn is_continuous(&self) -> bool {
178            true
179        }
180        fn is_differentiable(&self) -> bool {
181            true
182        }
183        fn provides_gradients(&self) -> bool {
184            true
185        }
186
187        fn add_input(&mut self, name: &str, shape: &[usize], units: &str) -> Result<()> {
188            let var_meta = VariableMetaData {
189                r#type: VariableType::KInput as i32,
190                name: name.to_string(),
191                shape: shape.iter().map(|&s| s as i64).collect(),
192                units: units.to_string(),
193                dynamic_shape: false,
194            };
195            self.variables.push(var_meta);
196            Ok(())
197        }
198
199        fn add_output(&mut self, name: &str, shape: &[usize], units: &str) -> Result<()> {
200            let var_meta = VariableMetaData {
201                r#type: VariableType::KOutput as i32,
202                name: name.to_string(),
203                shape: shape.iter().map(|&s| s as i64).collect(),
204                units: units.to_string(),
205                dynamic_shape: false,
206            };
207            self.variables.push(var_meta);
208            Ok(())
209        }
210
211        fn add_option(&mut self, name: &str, option_type: &str) -> Result<()> {
212            self.options
213                .insert(name.to_string(), option_type.to_string());
214            Ok(())
215        }
216
217        fn set_options(&mut self, _options: &HashMap<String, serde_json::Value>) -> Result<()> {
218            Ok(())
219        }
220
221        fn setup(&mut self) -> Result<()> {
222            self.variables.clear();
223            self.add_input("x", &[1], "")?;
224            self.add_input("y", &[1], "")?;
225            self.add_output("f", &[1], "")?;
226            Ok(())
227        }
228
229        fn declare_partials(&mut self, func: &str, var: &str) -> Result<()> {
230            self.partials.push((func.to_string(), var.to_string()));
231            Ok(())
232        }
233
234        fn setup_partials(&mut self) -> Result<()> {
235            self.declare_partials("f", "x")?;
236            self.declare_partials("f", "y")?;
237            Ok(())
238        }
239
240        fn get_variable_definitions(&self) -> Result<Vec<VariableMetaData>> {
241            Ok(self.variables.clone())
242        }
243
244        fn get_partials_definitions(&self) -> Result<Vec<(String, String)>> {
245            Ok(self.partials.clone())
246        }
247
248        fn get_available_options(&self) -> Result<HashMap<String, String>> {
249            Ok(self.options.clone())
250        }
251    }
252
253    #[async_trait::async_trait]
254    impl ExplicitDiscipline for TestParaboloid {
255        async fn compute(&self, inputs: &ArrayMap) -> Result<ArrayMap> {
256            let x = inputs
257                .get("x")
258                .ok_or_else(|| PhiloteError::VariableNotFound("x".to_string()))?;
259            let y = inputs
260                .get("y")
261                .ok_or_else(|| PhiloteError::VariableNotFound("y".to_string()))?;
262
263            let x_val = x[[0]];
264            let y_val = y[[0]];
265            let f_val = (x_val - 3.0).powi(2) + x_val * y_val + (y_val + 4.0).powi(2) - 3.0;
266
267            let mut outputs = HashMap::new();
268            outputs.insert("f".to_string(), ArrayD::from_elem(vec![1], f_val));
269            Ok(outputs)
270        }
271
272        async fn compute_partials(&self, inputs: &ArrayMap) -> Result<philote_mdo::PartialMap> {
273            let x = inputs
274                .get("x")
275                .ok_or_else(|| PhiloteError::VariableNotFound("x".to_string()))?;
276            let y = inputs
277                .get("y")
278                .ok_or_else(|| PhiloteError::VariableNotFound("y".to_string()))?;
279
280            let x_val = x[[0]];
281            let y_val = y[[0]];
282
283            let df_dx = 2.0 * (x_val - 3.0) + y_val;
284            let df_dy = x_val + 2.0 * (y_val + 4.0);
285
286            let mut partials = HashMap::new();
287            partials.insert(
288                ("f".to_string(), "x".to_string()),
289                ArrayD::from_elem(vec![1], df_dx),
290            );
291            partials.insert(
292                ("f".to_string(), "y".to_string()),
293                ArrayD::from_elem(vec![1], df_dy),
294            );
295            Ok(partials)
296        }
297    }
298
299    let mut discipline = TestParaboloid::new();
300    discipline.setup()?;
301    discipline.setup_partials()?;
302
303    let server_impl = ExplicitServer::new(discipline).with_verbose(true);
304
305    let addr: SocketAddr = "127.0.0.1:50051"
306        .parse()
307        .map_err(|e| PhiloteError::config_error(format!("Invalid address: {}", e)))?;
308
309    println!("🚀 Starting test server on {}", addr);
310
311    Server::builder()
312        .add_service(
313            philote_mdo::philote_info::explicit_service_server::ExplicitServiceServer::new(
314                server_impl,
315            ),
316        )
317        .serve(addr)
318        .await
319        .map_err(|e| PhiloteError::config_error(format!("Server error: {}", e)))?;
320
321    Ok(())
322}

Trait Implementations§

Source§

impl Debug for PhiloteError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for PhiloteError

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for PhiloteError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<DecodeError> for PhiloteError

Source§

fn from(source: DecodeError) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for PhiloteError

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Status> for PhiloteError

Source§

fn from(status: Status) -> Self

Converts to this type from the input type.

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more