Graph

Struct Graph 

Source
pub struct Graph {
    pub node_features: Array2<f64>,
    pub edge_indices: Array2<usize>,
    pub edge_features: Option<Array2<f64>>,
    pub graph_features: Option<Array1<f64>>,
    pub num_nodes: usize,
    pub num_edges: usize,
}
Expand description

Graph data structure

Fields§

§node_features: Array2<f64>

Node features

§edge_indices: Array2<usize>

Edge indices (source, target pairs)

§edge_features: Option<Array2<f64>>

Edge features

§graph_features: Option<Array1<f64>>

Graph-level features

§num_nodes: usize

Number of nodes

§num_edges: usize

Number of edges

Implementations§

Source§

impl Graph

Source

pub fn new( node_features: Array2<f64>, edge_indices: Array2<usize>, edge_features: Option<Array2<f64>>, graph_features: Option<Array1<f64>>, ) -> Self

Create a new graph

Examples found in repository?
examples/quantum_ml_ultrathink_showcase.rs (line 577)
556fn generate_complex_graphs(num_graphs: usize) -> Result<Vec<Graph>> {
557    let mut graphs = Vec::new();
558
559    for graph_idx in 0..num_graphs {
560        let num_nodes = 10 + graph_idx % 20; // 10-30 nodes
561        let num_edges = num_nodes * 2; // Sparse graphs
562
563        // Generate node features
564        let node_features = Array2::from_shape_fn((num_nodes, 64), |(i, j)| {
565            let node_factor = i as f64 * 0.1;
566            let feature_factor = j as f64 * 0.05;
567            (node_factor + feature_factor).sin() + fastrand::f64() * 0.1
568        });
569
570        // Generate edge indices (ensuring valid connections)
571        let mut edge_indices = Array2::zeros((2, num_edges));
572        for edge in 0..num_edges {
573            edge_indices[[0, edge]] = fastrand::usize(..num_nodes);
574            edge_indices[[1, edge]] = fastrand::usize(..num_nodes);
575        }
576
577        let graph = Graph::new(node_features, edge_indices, None, None);
578        graphs.push(graph);
579    }
580
581    Ok(graphs)
582}
583
584fn extract_pde_features_with_qpinn() -> Result<Array1<f64>> {
585    // Simulate PDE feature extraction
586    Ok(Array1::from_shape_fn(20, |i| (i as f64 * 0.2).exp() * 0.1))
587}
588
589fn process_temporal_with_qrc(features: &Array1<f64>) -> Result<Array2<f64>> {
590    // Simulate temporal processing
591    let temporal_length = 10;
592    Ok(Array2::from_shape_fn(
593        (temporal_length, features.len()),
594        |(t, f)| features[f] * (t as f64 * 0.1).cos(),
595    ))
596}
597
598fn create_relationship_graph(patterns: &Array2<f64>) -> Result<Graph> {
599    let num_nodes = patterns.nrows();
600    let node_features = patterns.clone();
601
602    // Create edges based on similarity
603    let mut edges = Vec::new();
604    for i in 0..num_nodes {
605        for j in i + 1..num_nodes {
606            if fastrand::f64() < 0.3 {
607                // 30% connection probability
608                edges.push(i);
609                edges.push(j);
610            }
611        }
612    }
613
614    let num_edges = edges.len() / 2;
615    let edge_indices = Array2::from_shape_vec((2, num_edges), edges)?;
616
617    Ok(Graph::new(node_features, edge_indices, None, None))
618}
Source

pub fn get_neighbors(&self, node: usize) -> Vec<usize>

Get neighbors of a node

Examples found in repository?
examples/quantum_ml_ultrathink_showcase.rs (line 623)
620fn analyze_with_qgat(graph: &Graph) -> Result<Array1<f64>> {
621    // Simulate QGAT analysis
622    Ok(Array1::from_shape_fn(graph.num_nodes, |i| {
623        let neighbors = graph.get_neighbors(i);
624        neighbors.len() as f64 * 0.1 + fastrand::f64() * 0.05
625    }))
626}
Source

pub fn get_adjacency_matrix(&self) -> Array2<f64>

Get adjacency matrix

Trait Implementations§

Source§

impl Clone for Graph

Source§

fn clone(&self) -> Graph

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Graph

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Graph

§

impl RefUnwindSafe for Graph

§

impl Send for Graph

§

impl Sync for Graph

§

impl Unpin for Graph

§

impl UnwindSafe for Graph

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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> Ungil for T
where T: Send,