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

feat(mpz-circuits-generic): implement generic circuit struct #156

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

brech1
Copy link
Member

@brech1 brech1 commented Jun 10, 2024

Description

This PR aims to introduce a new generic circuit struct:

pub struct Circuit<T> {
    input_count: usize,
    output_count: usize,
    gates: Vec<T>,
}

The Circuit is a collection of gates. Since for the execution of these gates is important that these form a directed acyclic graph (DAG), the correct way of building this circuit is using the CircuitBuilder

pub struct CircuitBuilder<T> {
    current_node: Node,
    inputs: Vec<Node>,
    outputs: Vec<Node>,
    gates: Vec<T>,
    stack_size: usize,
}

The CircuitBuilder API ensures that the gates are ordered topologically, this means in the order they should be executed taking dependencies into account

Here is our only constrain for the gates, they have to implement the Component trait, this means that they should be able to return an iterator over the nodes.

pub trait Component {
    fn get_inputs(&self) -> impl Iterator<Item = &Node>;
    fn get_outputs(&self) -> impl Iterator<Item = &Node>;
}

The Node struct:

pub struct Node(pub(crate) u32);

Example

let mut builder = CircuitBuilder::<Gate>::new();

let (in_0, in_1) = (builder.add_input(), builder.add_input());

let &Gate { output, .. } = builder
    .add_gate(|next| Gate {
        inputs: vec![in_0, in_1],
        output: next.next(),
    })
    .unwrap();
    
let &Gate { output, .. } = builder
    .add_gate(|next| Gate {
        inputs: vec![in_0, output],
        output: next.next(),
    })
    .unwrap();

builder.add_output(output);

@sinui0
Copy link
Collaborator

sinui0 commented Jun 12, 2024

is this awaiting review?

@brech1
Copy link
Member Author

brech1 commented Jun 12, 2024

is this awaiting review?

Yes, I added the checks we discussed on our last call

@sinui0 sinui0 self-requested a review June 12, 2024 20:34
@sinui0 sinui0 force-pushed the threading-refactor branch 2 times, most recently from 197d9e8 to e25d123 Compare June 25, 2024 21:20
Base automatically changed from threading-refactor to dev June 26, 2024 12:51
@brech1 brech1 closed this Jul 2, 2024
@brech1 brech1 reopened this Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants