Skip to main content

philote_mdo/
lib.rs

1//! Philote-Rust: A high-performance library for building MDO analysis servers
2//!
3//! This library provides a type-safe, async implementation for creating distributed
4//! analysis services in Multidisciplinary Design Optimization (MDO) frameworks using
5//! gRPC and Protocol Buffers.
6//!
7//! # Overview
8//!
9//! Philote enables computational disciplines to be exposed as remote services that can
10//! be integrated into MDO frameworks. It supports both explicit and implicit analysis
11//! types with automatic gradient computation capabilities.
12//!
13//! # Key Features
14//!
15//! - **Type-safe gRPC communication** using Protocol Buffers
16//! - **Async/await support** with Tokio runtime for high-performance concurrent operations
17//! - **Flexible discipline types** for different analysis patterns
18//! - **Efficient data streaming** for large arrays
19//! - **Comprehensive error handling** with domain-specific error types
20//!
21//! # Quick Start
22//!
23//! ## Creating a Discipline Server
24//!
25//! ```rust,no_run
26//! use async_trait::async_trait;
27//! use philote_mdo::{
28//!     traits::{Discipline, ExplicitDiscipline},
29//!     server::ExplicitServer,
30//!     ArrayMap, Result,
31//! };
32//! use ndarray::ArrayD;
33//! use std::collections::HashMap;
34//!
35//! struct MyDiscipline;
36//!
37//! #[async_trait]
38//! impl ExplicitDiscipline for MyDiscipline {
39//!     async fn compute(&self, inputs: &ArrayMap) -> Result<ArrayMap> {
40//!         let mut outputs = HashMap::new();
41//!         // Your computation logic here
42//!         Ok(outputs)
43//!     }
44//! }
45//!
46//! impl Discipline for MyDiscipline {
47//!     fn name(&self) -> &str { "MyDiscipline" }
48//!     fn version(&self) -> &str { "1.0.0" }
49//!     // Implement other required methods...
50//! #   fn add_input(&mut self, _: &str, _: &[usize], _: &str) -> Result<()> { Ok(()) }
51//! #   fn add_output(&mut self, _: &str, _: &[usize], _: &str) -> Result<()> { Ok(()) }
52//! #   fn add_option(&mut self, _: &str, _: &str) -> Result<()> { Ok(()) }
53//! #   fn set_options(&mut self, _: &HashMap<String, serde_json::Value>) -> Result<()> { Ok(()) }
54//! #   fn setup(&mut self) -> Result<()> { Ok(()) }
55//! #   fn declare_partials(&mut self, _: &str, _: &str) -> Result<()> { Ok(()) }
56//! #   fn get_variable_definitions(&self) -> Result<Vec<philote_mdo::philote_info::VariableMetaData>> { Ok(vec![]) }
57//! #   fn get_partials_definitions(&self) -> Result<Vec<(String, String)>> { Ok(vec![]) }
58//! #   fn get_available_options(&self) -> Result<HashMap<String, String>> { Ok(HashMap::new()) }
59//! }
60//! ```
61//!
62//! ## Connecting with a Client
63//!
64//! ```rust,no_run
65//! use philote_mdo::client::ExplicitClient;
66//!
67//! # async fn example() -> philote_mdo::Result<()> {
68//! let mut client = ExplicitClient::connect("http://localhost:50051").await?;
69//! let info = client.get_info().await?;
70//! println!("Connected to: {} v{}", info.name, info.version);
71//! # Ok(())
72//! # }
73//! ```
74//!
75//! # Module Organization
76//!
77//! - [`client`] - Client implementations for connecting to Philote servers
78//! - [`server`] - Server implementations for hosting disciplines
79//! - [`traits`] - Core trait definitions for disciplines
80//! - [`types`] - Data structures and type conversions
81//! - [`error`] - Error types and handling
82//! - [`utils`] - Utility functions for array operations
83//!
84//! # Type Aliases
85//!
86//! - [`Result<T>`](Result) - Standard result type using [`PhiloteError`]
87//! - [`ArrayMap`] - Map of variable names to N-dimensional arrays
88//! - [`PartialMap`] - Map of (output, input) tuples to partial derivative arrays
89
90use ndarray::ArrayD;
91use std::collections::HashMap;
92
93/// Protocol buffer definitions generated from the Philote MDO specification
94pub mod philote_info {
95    tonic::include_proto!("philote");
96}
97
98pub mod client;
99pub mod error;
100pub mod server;
101pub mod traits;
102pub mod types;
103pub mod utils;
104
105pub use error::PhiloteError;
106pub use traits::{Discipline, ExplicitDiscipline, ImplicitDiscipline};
107pub use types::{ArrayData, VariableData};
108
109/// Standard result type for Philote operations
110pub type Result<T> = std::result::Result<T, PhiloteError>;
111
112/// Map of variable names to their N-dimensional array values
113pub type ArrayMap = HashMap<String, ArrayD<f64>>;
114
115/// Map of (output variable, input variable) pairs to their partial derivative arrays
116pub type PartialMap = HashMap<(String, String), ArrayD<f64>>;
117
118pub type DiscreteMap = HashMap<String, prost_types::Value>;