pub struct PregelBuilder<'a> { /* private fields */ }
Expand description

The PregelBuilder struct represents a builder for configuring the Pregel algorithm to be executed on a given graph.

Properties:

  • graph: The graph property is a GraphFrame struct that represents the graph data structure used in the Pregel algorithm. It contains information about the vertices and edges of the graph.

  • max_iterations: The maximum number of iterations that the Pregel algorithm will run for.

  • vertex_column: vertex_column is a property of the PregelBuilder struct that represents the name of the column in the graph’s vertex DataFrame that contains the vertex IDs. This column is used to identify and locate a column where we apply some of the provided operations during the Pregel computation.

  • initial_message: initial_message is an expression that defines the initial message that each vertex in the graph will receive before the computation starts. This message can be used to initialize the state of each vertex or to provide some initial information to the computation.

  • send_messages: send_messages is a tuple containing two expressions. The first expression represents the message sending function that determines whether the message will go from Src to Dst or vice-versa. The second expression represents the message sending function that determines which messages to send from a vertex to its neighbors.

  • aggregate_messages: aggregate_messages is an expression that defines how messages sent to a vertex should be aggregated. In Pregel, messages are sent from one vertex to another and can be aggregated before being processed by the receiving vertex. The aggregate_messages expression specifies how these messages should be combined.

  • v_prog: v_prog is an expression that defines the vertex program for the Pregel algorithm. It specifies the computation that each vertex performs during each iteration of the algorithm. The vertex program can take as input the current state of the vertex, the messages received from its neighbors or and any other relevant information.

Implementations§

source§

impl<'a> PregelBuilder<'a>

source

pub fn new(graph: GraphFrame) -> Self

This function creates a new instance of a PregelBuilder with default values.

Arguments:

  • graph: The graph parameter is of type GraphFrame and represents the graph on which the Pregel algorithm will be executed.

Returns:

A new instance of the PregelBuilder struct.

Examples found in repository?
examples/maximum_value.rs (line 26)
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
fn main() -> Result<(), Box<dyn Error>> {
    let edges = df![
        Subject.as_ref() => [0, 1, 1, 2, 2, 3],
        Object.as_ref() => [1, 0, 3, 1, 3, 2],
    ]?;

    let vertices = df![
        VertexId.as_ref() => [0, 1, 2, 3],
        Custom("value").as_ref() => [3, 6, 2, 1],
    ]?;

    let pregel = PregelBuilder::new(GraphFrame::new(vertices, edges)?)
        .max_iterations(4)
        .with_vertex_column(Custom("max_value"))
        .initial_message(col(Custom("value").as_ref()))
        .send_messages(
            MessageReceiver::Object,
            Column::subject(Custom("max_value")),
        )
        .aggregate_messages(Column::msg(None).max())
        .v_prog(max_exprs([
            col(Custom("max_value").as_ref()),
            Column::msg(None),
        ]))
        .build();

    Ok(println!("{}", pregel.run()?))
}
More examples
Hide additional examples
examples/pagerank.rs (line 25)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
fn main() -> Result<(), Box<dyn Error>> {
    let edges = df![
        Subject.as_ref() => [0, 0, 1, 2, 3, 4, 4, 4],
        Object.as_ref() => [1, 2, 2, 3, 3, 1, 2, 3],
    ]?;

    let vertices = GraphFrame::from_edges(edges.clone())?.out_degrees()?;

    let damping_factor = 0.85;
    let num_vertices: f64 = vertices.column(VertexId.as_ref())?.len() as f64;

    let pregel = PregelBuilder::new(GraphFrame::new(vertices, edges)?)
        .max_iterations(4)
        .with_vertex_column(Custom("rank"))
        .initial_message(lit(1.0 / num_vertices))
        .send_messages(
            MessageReceiver::Subject,
            Column::subject(Column::Custom("rank")) / Column::subject(Column::Custom("out_degree")),
        )
        .send_messages(
            MessageReceiver::Object,
            Column::subject(Custom("rank")) / Column::subject(Custom("out_degree")),
        )
        .aggregate_messages(Column::msg(None).sum())
        .v_prog(
            Column::msg(None) * lit(damping_factor) + lit((1.0 - damping_factor) / num_vertices),
        )
        .build();

    Ok(println!("{}", pregel.run()?))
}
source

pub fn max_iterations(self, max_iterations: u8) -> Self

This function sets the maximum number of iterations for the Pregel algorithm and returns the modified PregelBuilder.

Arguments:

  • max_iterations: The max_iterations parameter is an unsigned 8-bit integer that represents the maximum number of iterations that the Pregel algorithm or process can perform. This method sets the max_iterations field of a struct to the provided value and returns the modified struct instance.

Returns:

The max_iterations method returns Self, which refers to the same struct instance that the method was called on. This allows for method chaining, where multiple methods can be called on the same struct instance in a single expression.

Examples found in repository?
examples/maximum_value.rs (line 27)
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
fn main() -> Result<(), Box<dyn Error>> {
    let edges = df![
        Subject.as_ref() => [0, 1, 1, 2, 2, 3],
        Object.as_ref() => [1, 0, 3, 1, 3, 2],
    ]?;

    let vertices = df![
        VertexId.as_ref() => [0, 1, 2, 3],
        Custom("value").as_ref() => [3, 6, 2, 1],
    ]?;

    let pregel = PregelBuilder::new(GraphFrame::new(vertices, edges)?)
        .max_iterations(4)
        .with_vertex_column(Custom("max_value"))
        .initial_message(col(Custom("value").as_ref()))
        .send_messages(
            MessageReceiver::Object,
            Column::subject(Custom("max_value")),
        )
        .aggregate_messages(Column::msg(None).max())
        .v_prog(max_exprs([
            col(Custom("max_value").as_ref()),
            Column::msg(None),
        ]))
        .build();

    Ok(println!("{}", pregel.run()?))
}
More examples
Hide additional examples
examples/pagerank.rs (line 26)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
fn main() -> Result<(), Box<dyn Error>> {
    let edges = df![
        Subject.as_ref() => [0, 0, 1, 2, 3, 4, 4, 4],
        Object.as_ref() => [1, 2, 2, 3, 3, 1, 2, 3],
    ]?;

    let vertices = GraphFrame::from_edges(edges.clone())?.out_degrees()?;

    let damping_factor = 0.85;
    let num_vertices: f64 = vertices.column(VertexId.as_ref())?.len() as f64;

    let pregel = PregelBuilder::new(GraphFrame::new(vertices, edges)?)
        .max_iterations(4)
        .with_vertex_column(Custom("rank"))
        .initial_message(lit(1.0 / num_vertices))
        .send_messages(
            MessageReceiver::Subject,
            Column::subject(Column::Custom("rank")) / Column::subject(Column::Custom("out_degree")),
        )
        .send_messages(
            MessageReceiver::Object,
            Column::subject(Custom("rank")) / Column::subject(Custom("out_degree")),
        )
        .aggregate_messages(Column::msg(None).sum())
        .v_prog(
            Column::msg(None) * lit(damping_factor) + lit((1.0 - damping_factor) / num_vertices),
        )
        .build();

    Ok(println!("{}", pregel.run()?))
}
source

pub fn with_vertex_column(self, vertex_column: Column) -> Self

This function sets the vertex column identifier for a struct and returns the struct.

Arguments:

  • vertex_column: vertex_column is a parameter of type ColumnIdentifier which represents the column identifier for the vertex column in a graph database. The with_vertex_column method takes in a ColumnIdentifier value and sets it as the vertex_column property of the struct instance. It then returns

Returns:

The with_vertex_column method returns Self, which refers to the same struct instance that the method was called on. This allows for method chaining, where multiple methods can be called on the same struct instance in a single expression.

Examples found in repository?
examples/maximum_value.rs (line 28)
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
fn main() -> Result<(), Box<dyn Error>> {
    let edges = df![
        Subject.as_ref() => [0, 1, 1, 2, 2, 3],
        Object.as_ref() => [1, 0, 3, 1, 3, 2],
    ]?;

    let vertices = df![
        VertexId.as_ref() => [0, 1, 2, 3],
        Custom("value").as_ref() => [3, 6, 2, 1],
    ]?;

    let pregel = PregelBuilder::new(GraphFrame::new(vertices, edges)?)
        .max_iterations(4)
        .with_vertex_column(Custom("max_value"))
        .initial_message(col(Custom("value").as_ref()))
        .send_messages(
            MessageReceiver::Object,
            Column::subject(Custom("max_value")),
        )
        .aggregate_messages(Column::msg(None).max())
        .v_prog(max_exprs([
            col(Custom("max_value").as_ref()),
            Column::msg(None),
        ]))
        .build();

    Ok(println!("{}", pregel.run()?))
}
More examples
Hide additional examples
examples/pagerank.rs (line 27)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
fn main() -> Result<(), Box<dyn Error>> {
    let edges = df![
        Subject.as_ref() => [0, 0, 1, 2, 3, 4, 4, 4],
        Object.as_ref() => [1, 2, 2, 3, 3, 1, 2, 3],
    ]?;

    let vertices = GraphFrame::from_edges(edges.clone())?.out_degrees()?;

    let damping_factor = 0.85;
    let num_vertices: f64 = vertices.column(VertexId.as_ref())?.len() as f64;

    let pregel = PregelBuilder::new(GraphFrame::new(vertices, edges)?)
        .max_iterations(4)
        .with_vertex_column(Custom("rank"))
        .initial_message(lit(1.0 / num_vertices))
        .send_messages(
            MessageReceiver::Subject,
            Column::subject(Column::Custom("rank")) / Column::subject(Column::Custom("out_degree")),
        )
        .send_messages(
            MessageReceiver::Object,
            Column::subject(Custom("rank")) / Column::subject(Custom("out_degree")),
        )
        .aggregate_messages(Column::msg(None).sum())
        .v_prog(
            Column::msg(None) * lit(damping_factor) + lit((1.0 - damping_factor) / num_vertices),
        )
        .build();

    Ok(println!("{}", pregel.run()?))
}
source

pub fn initial_message(self, initial_message: Expr) -> Self

This function sets the initial message for a Rust struct and returns the struct.

Arguments:

  • initial_message: initial_message is a parameter of type Expr that is used in a method of a struct. The method takes ownership of self and returns it after setting the initial_message field of the struct to the value of the initial_message parameter. This method can be used

Returns:

The initial_message method returns Self, which refers to the same struct instance that the method was called on. This allows for method chaining, where multiple methods can be called on the same struct instance in a single expression.

Examples found in repository?
examples/maximum_value.rs (line 29)
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
fn main() -> Result<(), Box<dyn Error>> {
    let edges = df![
        Subject.as_ref() => [0, 1, 1, 2, 2, 3],
        Object.as_ref() => [1, 0, 3, 1, 3, 2],
    ]?;

    let vertices = df![
        VertexId.as_ref() => [0, 1, 2, 3],
        Custom("value").as_ref() => [3, 6, 2, 1],
    ]?;

    let pregel = PregelBuilder::new(GraphFrame::new(vertices, edges)?)
        .max_iterations(4)
        .with_vertex_column(Custom("max_value"))
        .initial_message(col(Custom("value").as_ref()))
        .send_messages(
            MessageReceiver::Object,
            Column::subject(Custom("max_value")),
        )
        .aggregate_messages(Column::msg(None).max())
        .v_prog(max_exprs([
            col(Custom("max_value").as_ref()),
            Column::msg(None),
        ]))
        .build();

    Ok(println!("{}", pregel.run()?))
}
More examples
Hide additional examples
examples/pagerank.rs (line 28)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
fn main() -> Result<(), Box<dyn Error>> {
    let edges = df![
        Subject.as_ref() => [0, 0, 1, 2, 3, 4, 4, 4],
        Object.as_ref() => [1, 2, 2, 3, 3, 1, 2, 3],
    ]?;

    let vertices = GraphFrame::from_edges(edges.clone())?.out_degrees()?;

    let damping_factor = 0.85;
    let num_vertices: f64 = vertices.column(VertexId.as_ref())?.len() as f64;

    let pregel = PregelBuilder::new(GraphFrame::new(vertices, edges)?)
        .max_iterations(4)
        .with_vertex_column(Custom("rank"))
        .initial_message(lit(1.0 / num_vertices))
        .send_messages(
            MessageReceiver::Subject,
            Column::subject(Column::Custom("rank")) / Column::subject(Column::Custom("out_degree")),
        )
        .send_messages(
            MessageReceiver::Object,
            Column::subject(Custom("rank")) / Column::subject(Custom("out_degree")),
        )
        .aggregate_messages(Column::msg(None).sum())
        .v_prog(
            Column::msg(None) * lit(damping_factor) + lit((1.0 - damping_factor) / num_vertices),
        )
        .build();

    Ok(println!("{}", pregel.run()?))
}
source

pub fn send_messages(self, to: MessageReceiver, send_messages: Expr) -> Self

This function sets the message sending behavior for a Pregel computation in Rust. Chaining this method allows for multiple message sending behaviors to be specified for a single Pregel computation.

Examples
use polars::prelude::*;
use pregel_rs::graph_frame::GraphFrame;
use pregel_rs::pregel::Column;
use pregel_rs::pregel::Column::{Custom, Object, VertexId, Subject};
use pregel_rs::pregel::{MessageReceiver, Pregel, PregelBuilder};
use std::error::Error;

// Simple example of a Pregel algorithm where we chain several `send_messages` calls. In
// this example, we send a message to the source of an edge and then to the destination of
// the same edge. It has no real use case, but it demonstrates how to chain multiple calls.
fn main() -> Result<(), Box<dyn Error>> {

    let edges = df![
        Subject.as_ref() => [0, 1, 1, 2, 2, 3],
        Object.as_ref() => [1, 0, 3, 1, 3, 2],
    ]?;

    let vertices = df![
        VertexId.as_ref() => [0, 1, 2, 3],
        Custom("value").as_ref() => [3, 6, 2, 1],
    ]?;

    let pregel = PregelBuilder::new(GraphFrame::new(vertices, edges)?)
        .max_iterations(4)
        .with_vertex_column(Custom("aux"))
        .initial_message(lit(0))
        .send_messages(MessageReceiver::Subject, lit(1))
        .send_messages(MessageReceiver::Object, lit(-1))
        .aggregate_messages(Column::msg(None).sum())
        .v_prog(Column::msg(None) + lit(1))
        .build();

    Ok(println!("{:?}", pregel.run()))
}

Arguments:

  • to: to is a parameter of type MessageReceiver. It represents the destination vertex or vertices to which messages will be sent during the computation.
  • send_messages: send_messages is a parameter of type Expr. It is used to specify the function that will be applied to each vertex in the graph to send messages to its neighboring vertices.

Returns:

The send_messages method returns Self, which refers to the same struct instance that the method was called on. This allows for method chaining, where multiple methods can be called on the same struct instance in a single expression.

Examples found in repository?
examples/maximum_value.rs (lines 30-33)
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
fn main() -> Result<(), Box<dyn Error>> {
    let edges = df![
        Subject.as_ref() => [0, 1, 1, 2, 2, 3],
        Object.as_ref() => [1, 0, 3, 1, 3, 2],
    ]?;

    let vertices = df![
        VertexId.as_ref() => [0, 1, 2, 3],
        Custom("value").as_ref() => [3, 6, 2, 1],
    ]?;

    let pregel = PregelBuilder::new(GraphFrame::new(vertices, edges)?)
        .max_iterations(4)
        .with_vertex_column(Custom("max_value"))
        .initial_message(col(Custom("value").as_ref()))
        .send_messages(
            MessageReceiver::Object,
            Column::subject(Custom("max_value")),
        )
        .aggregate_messages(Column::msg(None).max())
        .v_prog(max_exprs([
            col(Custom("max_value").as_ref()),
            Column::msg(None),
        ]))
        .build();

    Ok(println!("{}", pregel.run()?))
}
More examples
Hide additional examples
examples/pagerank.rs (lines 29-32)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
fn main() -> Result<(), Box<dyn Error>> {
    let edges = df![
        Subject.as_ref() => [0, 0, 1, 2, 3, 4, 4, 4],
        Object.as_ref() => [1, 2, 2, 3, 3, 1, 2, 3],
    ]?;

    let vertices = GraphFrame::from_edges(edges.clone())?.out_degrees()?;

    let damping_factor = 0.85;
    let num_vertices: f64 = vertices.column(VertexId.as_ref())?.len() as f64;

    let pregel = PregelBuilder::new(GraphFrame::new(vertices, edges)?)
        .max_iterations(4)
        .with_vertex_column(Custom("rank"))
        .initial_message(lit(1.0 / num_vertices))
        .send_messages(
            MessageReceiver::Subject,
            Column::subject(Column::Custom("rank")) / Column::subject(Column::Custom("out_degree")),
        )
        .send_messages(
            MessageReceiver::Object,
            Column::subject(Custom("rank")) / Column::subject(Custom("out_degree")),
        )
        .aggregate_messages(Column::msg(None).sum())
        .v_prog(
            Column::msg(None) * lit(damping_factor) + lit((1.0 - damping_factor) / num_vertices),
        )
        .build();

    Ok(println!("{}", pregel.run()?))
}
source

pub fn send_messages_function( self, to: MessageReceiver, send_messages: impl FnMut() -> Expr + 'a ) -> Self

This is a Rust function that adds a new message to be sent to a message receiver using a closure that returns an expression.

Arguments:

  • to: to is a parameter of type MessageReceiver which represents the recipient of the message being sent. It could be an email address, phone number, or any other means of communication.

  • send_messages: send_messages is a closure that takes no arguments and returns an Expr. It is used to generate the messages that will be sent to the to message receiver. The closure is passed as an argument to the send_messages_function method and is stored in a SendMessage struct

Returns:

The Self object is being returned, which allows for method chaining.

source

pub fn aggregate_messages(self, aggregate_messages: Expr) -> Self

This function sets the aggregate_messages field of a struct to a given expression and returns the struct.

Arguments:

  • aggregate_messages: aggregate_messages is a parameter of type Expr that is used in a method of a struct. The method takes ownership of the struct instance (self) and assigns the value of aggregate_messages to the corresponding field of the struct. The method then returns the modified struct instance. This

Returns:

The aggregate_messages method returns Self, which refers to the same struct instance that the method was called on. This allows for method chaining, where multiple methods can be called on the same struct instance in a single expression.

Examples found in repository?
examples/maximum_value.rs (line 34)
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
fn main() -> Result<(), Box<dyn Error>> {
    let edges = df![
        Subject.as_ref() => [0, 1, 1, 2, 2, 3],
        Object.as_ref() => [1, 0, 3, 1, 3, 2],
    ]?;

    let vertices = df![
        VertexId.as_ref() => [0, 1, 2, 3],
        Custom("value").as_ref() => [3, 6, 2, 1],
    ]?;

    let pregel = PregelBuilder::new(GraphFrame::new(vertices, edges)?)
        .max_iterations(4)
        .with_vertex_column(Custom("max_value"))
        .initial_message(col(Custom("value").as_ref()))
        .send_messages(
            MessageReceiver::Object,
            Column::subject(Custom("max_value")),
        )
        .aggregate_messages(Column::msg(None).max())
        .v_prog(max_exprs([
            col(Custom("max_value").as_ref()),
            Column::msg(None),
        ]))
        .build();

    Ok(println!("{}", pregel.run()?))
}
More examples
Hide additional examples
examples/pagerank.rs (line 37)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
fn main() -> Result<(), Box<dyn Error>> {
    let edges = df![
        Subject.as_ref() => [0, 0, 1, 2, 3, 4, 4, 4],
        Object.as_ref() => [1, 2, 2, 3, 3, 1, 2, 3],
    ]?;

    let vertices = GraphFrame::from_edges(edges.clone())?.out_degrees()?;

    let damping_factor = 0.85;
    let num_vertices: f64 = vertices.column(VertexId.as_ref())?.len() as f64;

    let pregel = PregelBuilder::new(GraphFrame::new(vertices, edges)?)
        .max_iterations(4)
        .with_vertex_column(Custom("rank"))
        .initial_message(lit(1.0 / num_vertices))
        .send_messages(
            MessageReceiver::Subject,
            Column::subject(Column::Custom("rank")) / Column::subject(Column::Custom("out_degree")),
        )
        .send_messages(
            MessageReceiver::Object,
            Column::subject(Custom("rank")) / Column::subject(Custom("out_degree")),
        )
        .aggregate_messages(Column::msg(None).sum())
        .v_prog(
            Column::msg(None) * lit(damping_factor) + lit((1.0 - damping_factor) / num_vertices),
        )
        .build();

    Ok(println!("{}", pregel.run()?))
}
source

pub fn aggregate_messages_function( self, aggregate_messages: impl FnMut() -> Expr + 'a ) -> Self

This function sets the aggregate_messages field of a struct to a closure that returns an Expr.

Arguments:

  • aggregate_messages: aggregate_messages is a closure that takes no arguments and returns an Expr object. The closure is passed as an argument to the aggregate_messages_function method and is stored in the self.aggregate_messages field. The closure is expected to be implemented by the caller and will be used

Returns:

The Self object is being returned. This allows for method chaining, where multiple methods can be called on the same object in a single expression.

source

pub fn v_prog(self, v_prog: Expr) -> Self

This function sets the value of a field in a struct and returns the struct itself.

Arguments:

  • v_prog: v_prog is a parameter of type Expr that is being passed to a method called v_prog. The method takes ownership of self (which is of the same type as the struct or object that the method belongs to) and assigns the value of v_prog to

Returns:

The v_prog method returns Self, which refers to the same struct instance that the method was called on. This allows for method chaining, where multiple methods can be called on the same struct instance in a single expression.

Examples found in repository?
examples/maximum_value.rs (lines 35-38)
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
fn main() -> Result<(), Box<dyn Error>> {
    let edges = df![
        Subject.as_ref() => [0, 1, 1, 2, 2, 3],
        Object.as_ref() => [1, 0, 3, 1, 3, 2],
    ]?;

    let vertices = df![
        VertexId.as_ref() => [0, 1, 2, 3],
        Custom("value").as_ref() => [3, 6, 2, 1],
    ]?;

    let pregel = PregelBuilder::new(GraphFrame::new(vertices, edges)?)
        .max_iterations(4)
        .with_vertex_column(Custom("max_value"))
        .initial_message(col(Custom("value").as_ref()))
        .send_messages(
            MessageReceiver::Object,
            Column::subject(Custom("max_value")),
        )
        .aggregate_messages(Column::msg(None).max())
        .v_prog(max_exprs([
            col(Custom("max_value").as_ref()),
            Column::msg(None),
        ]))
        .build();

    Ok(println!("{}", pregel.run()?))
}
More examples
Hide additional examples
examples/pagerank.rs (lines 38-40)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
fn main() -> Result<(), Box<dyn Error>> {
    let edges = df![
        Subject.as_ref() => [0, 0, 1, 2, 3, 4, 4, 4],
        Object.as_ref() => [1, 2, 2, 3, 3, 1, 2, 3],
    ]?;

    let vertices = GraphFrame::from_edges(edges.clone())?.out_degrees()?;

    let damping_factor = 0.85;
    let num_vertices: f64 = vertices.column(VertexId.as_ref())?.len() as f64;

    let pregel = PregelBuilder::new(GraphFrame::new(vertices, edges)?)
        .max_iterations(4)
        .with_vertex_column(Custom("rank"))
        .initial_message(lit(1.0 / num_vertices))
        .send_messages(
            MessageReceiver::Subject,
            Column::subject(Column::Custom("rank")) / Column::subject(Column::Custom("out_degree")),
        )
        .send_messages(
            MessageReceiver::Object,
            Column::subject(Custom("rank")) / Column::subject(Custom("out_degree")),
        )
        .aggregate_messages(Column::msg(None).sum())
        .v_prog(
            Column::msg(None) * lit(damping_factor) + lit((1.0 - damping_factor) / num_vertices),
        )
        .build();

    Ok(println!("{}", pregel.run()?))
}
source

pub fn v_prog_function(self, v_prog: impl FnMut() -> Expr + 'a) -> Self

This is a Rust function that takes a closure that returns an expression and sets it as a field in a struct.

Arguments:

  • v_prog: v_prog is a closure that takes no arguments and returns an Expr object. The closure is passed as an argument to the v_prog_function method. The impl FnMut() -> Expr + 'a syntax specifies that the closure must be mutable (FnMut) and that it must not capture any variables from the enclosing scope ('a). The closure is stored in the self.v_prog field of the struct.

Returns:

The Self object is being returned. This allows for method chaining, where multiple methods can be called on the same object in a single expression.

source

pub fn build(self) -> Pregel<'a>

The function returns a Pregel struct with the specified properties. This is, Pregel structs are to be created using the Builder Pattern, a creational design pattern that provides a way to construct complex structs in a step-by-step manner, allowing for the creation of several different configurations or variations of the same struct without directly exposing the underlying complexity. It allows for flexibility in creating different variations of objects while keeping the construction process modular and manageable.

Examples
use polars::prelude::*;
use pregel_rs::graph_frame::GraphFrame;
use pregel_rs::pregel::Column;
use pregel_rs::pregel::Column::{Custom, Object, VertexId, Subject};
use pregel_rs::pregel::{MessageReceiver, Pregel, PregelBuilder};
use std::error::Error;

// Simple example of a Pregel algorithm that finds the maximum value in a graph.
fn main() -> Result<(), Box<dyn Error>> {
let edges = df![
        Subject.as_ref() => [0, 1, 1, 2, 2, 3],
        Object.as_ref() => [1, 0, 3, 1, 3, 2],
    ]?;

    let vertices = df![
        VertexId.as_ref() => [0, 1, 2, 3],
        Custom("value").as_ref() => [3, 6, 2, 1],
    ]?;

    let pregel = PregelBuilder::new(GraphFrame::new(vertices, edges)?)
        .max_iterations(4)
        .with_vertex_column(Custom("max_value"))
        .initial_message(col(Custom("value").as_ref()))
        .send_messages(MessageReceiver::Object, Column::subject(Custom("max_value")))
        .aggregate_messages(Column::msg(None).max())
        .v_prog(max_exprs([col(Custom("max_value").as_ref()), Column::msg(None)]))
        .build();

    Ok(println!("{}", pregel.run()?))
}

Returns:

The build method is returning an instance of the Pregel struct with the values of the fields set to the values of the corresponding fields in the Builder struct.

Examples found in repository?
examples/maximum_value.rs (line 39)
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
fn main() -> Result<(), Box<dyn Error>> {
    let edges = df![
        Subject.as_ref() => [0, 1, 1, 2, 2, 3],
        Object.as_ref() => [1, 0, 3, 1, 3, 2],
    ]?;

    let vertices = df![
        VertexId.as_ref() => [0, 1, 2, 3],
        Custom("value").as_ref() => [3, 6, 2, 1],
    ]?;

    let pregel = PregelBuilder::new(GraphFrame::new(vertices, edges)?)
        .max_iterations(4)
        .with_vertex_column(Custom("max_value"))
        .initial_message(col(Custom("value").as_ref()))
        .send_messages(
            MessageReceiver::Object,
            Column::subject(Custom("max_value")),
        )
        .aggregate_messages(Column::msg(None).max())
        .v_prog(max_exprs([
            col(Custom("max_value").as_ref()),
            Column::msg(None),
        ]))
        .build();

    Ok(println!("{}", pregel.run()?))
}
More examples
Hide additional examples
examples/pagerank.rs (line 41)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
fn main() -> Result<(), Box<dyn Error>> {
    let edges = df![
        Subject.as_ref() => [0, 0, 1, 2, 3, 4, 4, 4],
        Object.as_ref() => [1, 2, 2, 3, 3, 1, 2, 3],
    ]?;

    let vertices = GraphFrame::from_edges(edges.clone())?.out_degrees()?;

    let damping_factor = 0.85;
    let num_vertices: f64 = vertices.column(VertexId.as_ref())?.len() as f64;

    let pregel = PregelBuilder::new(GraphFrame::new(vertices, edges)?)
        .max_iterations(4)
        .with_vertex_column(Custom("rank"))
        .initial_message(lit(1.0 / num_vertices))
        .send_messages(
            MessageReceiver::Subject,
            Column::subject(Column::Custom("rank")) / Column::subject(Column::Custom("out_degree")),
        )
        .send_messages(
            MessageReceiver::Object,
            Column::subject(Custom("rank")) / Column::subject(Custom("out_degree")),
        )
        .aggregate_messages(Column::msg(None).sum())
        .v_prog(
            Column::msg(None) * lit(damping_factor) + lit((1.0 - damping_factor) / num_vertices),
        )
        .build();

    Ok(println!("{}", pregel.run()?))
}

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for PregelBuilder<'a>

§

impl<'a> !Send for PregelBuilder<'a>

§

impl<'a> !Sync for PregelBuilder<'a>

§

impl<'a> Unpin for PregelBuilder<'a>

§

impl<'a> !UnwindSafe for PregelBuilder<'a>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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, U> Into<U> for Twhere 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.
§

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

§

fn vzip(self) -> V