pub struct CircuitBuilder<F: Field> {Show 13 fields
input_layer_nodes: Vec<Rc<InputLayerNode>>,
input_shred_nodes: Vec<Rc<InputShred>>,
fiat_shamir_challenge_nodes: Vec<Rc<FiatShamirChallengeNode>>,
output_nodes: Vec<Rc<OutputNode>>,
sector_nodes: Vec<Rc<Sector<F>>>,
gate_nodes: Vec<Rc<GateNode>>,
identity_gate_nodes: Vec<Rc<IdentityGateNode>>,
split_nodes: Vec<Rc<SplitNode>>,
matmult_nodes: Vec<Rc<MatMultNode>>,
lookup_constraint_nodes: Vec<Rc<LookupConstraint>>,
lookup_table_nodes: Vec<Rc<LookupTable>>,
node_to_ptr: HashMap<NodeId, NodeRef<F>>,
circuit_map: CircuitMap,
}Expand description
A struct that owns and manages super::nodes::CircuitNodes during circuit creation.
Fields§
§input_layer_nodes: Vec<Rc<InputLayerNode>>§input_shred_nodes: Vec<Rc<InputShred>>§fiat_shamir_challenge_nodes: Vec<Rc<FiatShamirChallengeNode>>§output_nodes: Vec<Rc<OutputNode>>§sector_nodes: Vec<Rc<Sector<F>>>§gate_nodes: Vec<Rc<GateNode>>§identity_gate_nodes: Vec<Rc<IdentityGateNode>>§split_nodes: Vec<Rc<SplitNode>>§matmult_nodes: Vec<Rc<MatMultNode>>§lookup_constraint_nodes: Vec<Rc<LookupConstraint>>§lookup_table_nodes: Vec<Rc<LookupTable>>§node_to_ptr: HashMap<NodeId, NodeRef<F>>§circuit_map: CircuitMapImplementations§
Source§impl<F: Field> CircuitBuilder<F>
impl<F: Field> CircuitBuilder<F>
Sourcepub fn new() -> Self
pub fn new() -> Self
Constructs an empty CircuitBuilder.
fn into_owned_helper<T: CircuitNode + Debug>(xs: Vec<Rc<T>>) -> Vec<T>
Sourcepub fn build_with_max_layer_size(
self,
maybe_maximum_log_layer_size: Option<usize>,
) -> Result<Circuit<F>>
pub fn build_with_max_layer_size( self, maybe_maximum_log_layer_size: Option<usize>, ) -> Result<Circuit<F>>
Generates a circuit description of all the nodes added so far.
Returns a Circuit struct containing the circuit description and all necessary metadata for attaching inputs.
Sourcepub fn build_with_layer_combination(self) -> Result<Circuit<F>>
pub fn build_with_layer_combination(self) -> Result<Circuit<F>>
A build function that combines layers greedily such that the circuit is optimized for having the smallest number of layers possible.
Sourcepub fn build_without_layer_combination(self) -> Result<Circuit<F>>
pub fn build_without_layer_combination(self) -> Result<Circuit<F>>
A build function that does not combine any layers.
Source§impl<F: Field> CircuitBuilder<F>
impl<F: Field> CircuitBuilder<F>
Sourcepub fn add_input_layer(
&mut self,
layer_label: &str,
layer_visibility: LayerVisibility,
) -> InputLayerNodeRef<F>
pub fn add_input_layer( &mut self, layer_label: &str, layer_visibility: LayerVisibility, ) -> InputLayerNodeRef<F>
Adds an InputLayerNode labeled layer_label to the builder’s node collection, intented to
become a layer_kind input later during circuit instantiation.
Returns a weak pointer to the newly created layer node.
Note that Input Layers and Input Shred have disjoint label scopes. A label has to be unique only in its respective scope, regardless of the inclusive relation between shreds and input layers.
§Panics
If layer_label has already been used for an existing Input Layer.
Sourcepub fn add_input_shred(
&mut self,
label: &str,
num_vars: usize,
source: &InputLayerNodeRef<F>,
) -> NodeRef<F>
pub fn add_input_shred( &mut self, label: &str, num_vars: usize, source: &InputLayerNodeRef<F>, ) -> NodeRef<F>
Returns a reference to the newly created node.
Note that no method in Self requires to differentiate between a reference to an input shred as opposed to a generic NodeRef, so there is no need to retain the specific type information in the returned type.
§Panics
If label has already been used for an existing Input Shred.
Sourcepub fn set_output(&mut self, source: &NodeRef<F>)
pub fn set_output(&mut self, source: &NodeRef<F>)
Adds an zero OutputNode (using OutputNode::new_zero()) to the builder’s node
collection.
TODO(Makis): Add a check for ensuring each node can be set as output at most once.
Sourcepub fn add_fiat_shamir_challenge_node(
&mut self,
num_challenges: usize,
) -> FSNodeRef<F>
pub fn add_fiat_shamir_challenge_node( &mut self, num_challenges: usize, ) -> FSNodeRef<F>
Adds a FiatShamirChallengeNode to the builder’s node colllection. Returns a typed reference to the newly created node.
Sourcepub fn add_sector(&mut self, expr: AbstractExpression<F>) -> NodeRef<F>
pub fn add_sector(&mut self, expr: AbstractExpression<F>) -> NodeRef<F>
Adds a Sector to the builder’s node collection. Returns a typed reference to the newly created node.
Sourcepub fn add_identity_gate_node(
&mut self,
pre_routed_data: &NodeRef<F>,
non_zero_gates: Vec<(u32, u32)>,
num_vars: usize,
num_dataparallel_vars: Option<usize>,
) -> NodeRef<F>
pub fn add_identity_gate_node( &mut self, pre_routed_data: &NodeRef<F>, non_zero_gates: Vec<(u32, u32)>, num_vars: usize, num_dataparallel_vars: Option<usize>, ) -> NodeRef<F>
Adds an IdentityGateNode to the builder’s node collection. Returns a reference to the newly created node.
Note that no method in Self requires to differentiate between a reference to an identity gate node as opposed to a generic NodeRef, so there is no need to retain the specific type information in the returned type.
Sourcepub fn add_gate_node(
&mut self,
lhs: &NodeRef<F>,
rhs: &NodeRef<F>,
nonzero_gates: Vec<(u32, u32, u32)>,
gate_operation: BinaryOperation,
num_dataparallel_bits: Option<usize>,
) -> NodeRef<F>
pub fn add_gate_node( &mut self, lhs: &NodeRef<F>, rhs: &NodeRef<F>, nonzero_gates: Vec<(u32, u32, u32)>, gate_operation: BinaryOperation, num_dataparallel_bits: Option<usize>, ) -> NodeRef<F>
Adds an GateNode to the builder’s node collection. Returns a reference to the newly created node.
Note that no method in Self requires to differentiate between a reference to a gate node as opposed to a generic NodeRef, so there is no need to retain the specific type information in the returned type.
Sourcepub fn add_matmult_node(
&mut self,
matrix_a_node: &NodeRef<F>,
rows_cols_num_vars_a: (usize, usize),
matrix_b_node: &NodeRef<F>,
rows_cols_num_vars_b: (usize, usize),
) -> NodeRef<F>
pub fn add_matmult_node( &mut self, matrix_a_node: &NodeRef<F>, rows_cols_num_vars_a: (usize, usize), matrix_b_node: &NodeRef<F>, rows_cols_num_vars_b: (usize, usize), ) -> NodeRef<F>
Adds an MatMultNode to the builder’s node collection. Returns a reference to the newly created node.
Note that no method in Self requires to differentiate between a reference to a matmult node as opposed to a generic NodeRef, so there is no need to retain the specific type information in the returned type.
Sourcepub fn add_lookup_table(
&mut self,
table: &NodeRef<F>,
fiat_shamir_challenge_node: &FSNodeRef<F>,
) -> LookupTableNodeRef
pub fn add_lookup_table( &mut self, table: &NodeRef<F>, fiat_shamir_challenge_node: &FSNodeRef<F>, ) -> LookupTableNodeRef
Adds an LookupTable to the builder’s node collection. Returns a typed reference to the newly created node.
Sourcepub fn add_lookup_constraint(
&mut self,
lookup_table: &LookupTableNodeRef,
constrained: &NodeRef<F>,
multiplicities: &NodeRef<F>,
) -> LookupConstraintNodeRef
pub fn add_lookup_constraint( &mut self, lookup_table: &LookupTableNodeRef, constrained: &NodeRef<F>, multiplicities: &NodeRef<F>, ) -> LookupConstraintNodeRef
Adds an LookupConstraint to the builder’s node collection. Returns a typed reference to the newly created node.
Sourcepub fn add_split_node(
&mut self,
input_node: &NodeRef<F>,
num_vars: usize,
) -> Vec<NodeRef<F>>
pub fn add_split_node( &mut self, input_node: &NodeRef<F>, num_vars: usize, ) -> Vec<NodeRef<F>>
Adds an SplitNode to the builder’s node collection.
Returns a vector of reference to the 2^num_vars newly created nodes.
Note that no method in Self requires to differentiate between a reference to a split node as opposed to a generic NodeRef, so there is no need to retain the specific type information in the returned type.
fn get_ptr_from_node_id(&self, id: NodeId) -> Rc<dyn CircuitNode>
Trait Implementations§
Auto Trait Implementations§
impl<F> Freeze for CircuitBuilder<F>
impl<F> !RefUnwindSafe for CircuitBuilder<F>
impl<F> !Send for CircuitBuilder<F>
impl<F> !Sync for CircuitBuilder<F>
impl<F> Unpin for CircuitBuilder<F>where
F: Unpin,
impl<F> !UnwindSafe for CircuitBuilder<F>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.