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

refactor(graph): refactor the Knowledge Graph to include configs check, while eligibility analysis #4687

Merged
merged 16 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/euclid/src/dssa/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::{
pub mod euclid_graph_prelude {
pub use hyperswitch_constraint_graph as cgraph;
pub use rustc_hash::{FxHashMap, FxHashSet};
pub use strum::EnumIter;

pub use crate::{
dssa::graph::*,
Expand Down Expand Up @@ -71,6 +72,7 @@ impl<V: cgraph::ValueNode> AnalysisError<V> {
}
}

#[derive(Debug)]
pub struct AnalysisContext {
keywise_values: FxHashMap<dir::DirKey, FxHashSet<dir::DirValue>>,
}
Expand Down
2 changes: 1 addition & 1 deletion crates/euclid/src/enums.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub use common_enums::{
AuthenticationType, CaptureMethod, CardNetwork, Country, Currency,
AuthenticationType, CaptureMethod, CardNetwork, Country, CountryAlpha2, Currency,
FutureUsage as SetupFutureUsage, PaymentMethod, PaymentMethodType, RoutableConnectors,
};
use strum::VariantNames;
Expand Down
4 changes: 2 additions & 2 deletions crates/euclid/src/frontend/dir/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use strum::VariantNames;
use crate::enums::collect_variants;
pub use crate::enums::{
AuthenticationType, CaptureMethod, CardNetwork, Country, Country as BusinessCountry,
Country as BillingCountry, Currency as PaymentCurrency, MandateAcceptanceType, MandateType,
PaymentMethod, PaymentType, RoutableConnectors, SetupFutureUsage,
Country as BillingCountry, CountryAlpha2, Currency as PaymentCurrency, MandateAcceptanceType,
MandateType, PaymentMethod, PaymentType, RoutableConnectors, SetupFutureUsage,
};
#[cfg(feature = "payouts")]
pub use crate::enums::{PayoutBankTransferType, PayoutType, PayoutWalletType};
Expand Down
8 changes: 6 additions & 2 deletions crates/euclid_wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,12 @@ pub fn seed_knowledge_graph(mcas: JsValue) -> JsResult {
.collect::<Result<_, _>>()
.map_err(|_| "invalid connector name received")
.err_to_js()?;

let mca_graph = kgraph_utils::mca::make_mca_graph(mcas).err_to_js()?;
let pm_filter = kgraph_utils::types::PaymentMethodFilters(HashMap::new());
let config = kgraph_utils::types::CountryCurrencyFilter {
connector_configs: HashMap::new(),
default_configs: Some(pm_filter),
};
let mca_graph = kgraph_utils::mca::make_mca_graph(mcas, &config).err_to_js()?;
let analysis_graph =
hyperswitch_constraint_graph::ConstraintGraph::combine(&mca_graph, &truth::ANALYSIS_GRAPH)
.err_to_js()?;
Expand Down
2 changes: 1 addition & 1 deletion crates/hyperswitch_constraint_graph/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl From<DomainId> for DomainIdOrIdentifier<'_> {
Self::DomainId(value)
}
}

#[derive(Debug)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If possible we can revert the added Derive implemetations.

pub struct ConstraintGraphBuilder<'a, V: ValueNode> {
domain: DenseMap<DomainId, DomainInfo<'a>>,
nodes: DenseMap<NodeId, Node<V>>,
Expand Down
4 changes: 4 additions & 0 deletions crates/hyperswitch_constraint_graph/src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::{
},
};

#[derive(Debug)]
struct CheckNodeContext<'a, V: ValueNode, C: CheckingContext<Value = V>> {
ctx: &'a C,
node: &'a Node<V>,
Expand All @@ -24,6 +25,7 @@ struct CheckNodeContext<'a, V: ValueNode, C: CheckingContext<Value = V>> {
domains: Option<&'a [DomainId]>,
}

#[derive(Debug)]
pub struct ConstraintGraph<'a, V: ValueNode> {
pub domain: DenseMap<DomainId, DomainInfo<'a>>,
pub domain_identifier_map: FxHashMap<DomainIdentifier<'a>, DomainId>,
Expand Down Expand Up @@ -139,6 +141,7 @@ where
ctx,
domains,
};

match &node.node_type {
NodeType::AllAggregator => self.validate_all_aggregator(check_node_context),

Expand Down Expand Up @@ -206,6 +209,7 @@ where
} else {
vald.memo
.insert((vald.node_id, vald.relation, vald.strength), Ok(()));

Ok(())
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/kgraph_utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ masking = { version = "0.1.0", path = "../masking/" }
serde = "1.0.197"
serde_json = "1.0.115"
thiserror = "1.0.58"
strum = { version = "0.26", features = ["derive"] }

[dev-dependencies]
criterion = "0.5"
Expand Down
12 changes: 8 additions & 4 deletions crates/kgraph_utils/benches/evaluation.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(unused, clippy::expect_used)]

use std::str::FromStr;
use std::{collections::HashMap, str::FromStr};

use api_models::{
admin as admin_api, enums as api_enums, payment_methods::RequestPaymentMethodTypes,
Expand All @@ -13,7 +13,7 @@ use euclid::{
types::{NumValue, NumValueRefinement},
};
use hyperswitch_constraint_graph::{CycleCheck, Memoization};
use kgraph_utils::{error::KgraphError, transformers::IntoDirValue};
use kgraph_utils::{error::KgraphError, transformers::IntoDirValue, types::CountryCurrencyFilter};

fn build_test_data<'a>(
total_enabled: usize,
Expand Down Expand Up @@ -71,8 +71,12 @@ fn build_test_data<'a>(
pm_auth_config: None,
status: api_enums::ConnectorStatus::Inactive,
};

kgraph_utils::mca::make_mca_graph(vec![stripe_account]).expect("Failed graph construction")
let config = CountryCurrencyFilter {
connector_configs: HashMap::new(),
default_configs: None,
};
kgraph_utils::mca::make_mca_graph(vec![stripe_account], &config)
.expect("Failed graph construction")
}

fn evaluation(c: &mut Criterion) {
Expand Down
1 change: 1 addition & 0 deletions crates/kgraph_utils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod error;
pub mod mca;
pub mod transformers;
pub mod types;
Loading
Loading