Struct Solutions

Source
pub struct Solutions {
    cfg: Cfg,
    ctx: Context,
    solutions: Vec<(&'static Expr, Bits)>,
    solved_examples: Bits,
    pub threads: MappedFutures<Vec<usize>, JoinHandle<Expression>>,
    start_time: Instant,
    last_update: Instant,
    ite_limit: usize,
    tree_hole: Vec<Box<[u128]>>,
}
Expand description

A structure encapsulating the state and configuration for managing synthesis solutions along with multi-threaded search execution.

It integrates various components such as a configuration context, a collection of candidate solutions paired with evaluation bits, and management of concurrent solution search threads. Additionally, it tracks the synthesis start time, last update timestamp, an adaptive limit parameter, and a filtering structure (tree hole) used during example set generation and thread interruption.

Fields§

§cfg: Cfg§ctx: Context§solutions: Vec<(&'static Expr, Bits)>§solved_examples: Bits§threads: MappedFutures<Vec<usize>, JoinHandle<Expression>>§start_time: Instant§last_update: Instant§ite_limit: usize§tree_hole: Vec<Box<[u128]>>

Implementations§

Source§

impl Solutions

Source

pub fn new(cfg: Cfg, ctx: Context) -> Self

Creates a new instance with the provided configuration and context. This function initializes the internal condition tracker based on the context, ensuring that no previous tracker is present, and then sets up all the initial fields required for solution management and concurrent search execution, including a default tree hole, empty solution set, and mapped futures for thread management.

Source

pub fn count(&self) -> usize

Counts the number of stored synthesis solutions.

Returns the total count of solution entries currently maintained within the internal collection.

Source

pub fn add_new_solution(&mut self, expr: &'static Expr) -> Option<&'static Expr>

Adds a new candidate solution by evaluating an expression and updating the internal solution set accordingly.

The method first attempts to derive an evaluation result from the provided expression and then checks if this new result is subsumed by any existing solution; if so, it immediately returns without modification. Otherwise, it filters out any previously stored solutions that are redundant relative to the new one, updates the union of solved examples, and adds the new solution.

Continues by assessing whether the inclusive solved example set now covers all required cases, returning the expression if complete. In parallel, it iterates over the currently scheduled threads, aborting any whose example sets are fully encompassed by the new evaluation and triggering the launch of new threads. Finally, it leverages auxiliary mechanisms to generate a final solution if possible, or returns None if the candidate fails to yield a valid update.

Source

pub fn generate_result(&self, limit: bool) -> Option<&'static Expr>

Determines and generates a synthesized result based on solved examples.

Checks whether the complete set of examples has been addressed; if so, it invokes a tree-learning procedure using a configurable operator limit depending on the provided flag and returns the synthesized solution expression. Otherwise, it returns none.

Source

pub fn learn_tree(&self, ite_limit_rate: usize) -> Option<&'static Expr>

Learns a decision tree that synthesizes an expression using the current set of solutions and conditions, dynamically adjusting the iteration limit based on elapsed time and a provided rate parameter.

Computes an adaptive limit derived from the runtime duration and toggles a global condition tracker before invoking a tree learning procedure. Returns an expression reference if the tree learning process determines that a complete solution has been found, otherwise yields None.

Source

pub fn check_cover(&self, example_set: &[usize]) -> bool

Checks whether any stored solution in the current context fully covers the specified example set.

This function iterates over all solutions and verifies if all indices in the provided example set are included in the corresponding coverage bitmask of any solution. It returns true as soon as a matching solution is found, and false otherwise.

Source

pub fn generate_example_set(&mut self) -> Option<Vec<usize>>

Generates a new set of example indices for initiating a synthesis thread. This method iterates over potential subset sizes, calculating binomial coefficients to limit enumeration, and constructs candidate subsets based on configured conditions—either filtering through a predefined mask or generating all possible combinations.

It randomizes the order of these candidate subsets and validates each by ensuring that the example set is neither already covered by existing solutions nor in use by running threads. When a valid subset is found, it returns the set; otherwise, it yields None if no appropriate example set can be generated.

Source

pub fn update_tree_hole(&mut self, tree_hole: Vec<Box<[u128]>>)

Updates the tree hole configuration for the current synthesis process while ensuring that threads no longer covered by the new configuration are aborted and replaced. This method assigns the new tree hole, iterates through the active thread example sets, verifies each against the updated tree hole using a helper function, and for any that fail the condition, it aborts the corresponding thread and promptly creates a replacement thread to preserve continuous progress in the synthesis search.

Source

pub fn create_new_thread(&mut self)

Creates a new asynchronous thread to perform synthesis search using a generated example set. This function attempts to generate a candidate example set and, if successful, constructs a new context augmented with these examples to spawn an additional thread executing the synthesis process; otherwise, it logs that no example set is available.

Source

pub fn create_all_search_thread(&mut self)

Creates and registers an asynchronous thread that performs exhaustive search over all examples from the current context.

This function gathers every example index by iterating from 0 to the context’s length, clones the current configuration and context, and then spawns a new search thread using those values. The resulting thread is inserted into the solutions’ thread registry, initiating a comprehensive condition search for viable synthesis solutions.

Source

pub async fn solve_loop(&mut self) -> &'static Expr

Continuously polls and adapts the synthesis process until a valid expression covering all examples is discovered.

This asynchronous loop concurrently listens for solutions generated by worker threads and performs periodic adaptive adjustments. It evaluates incoming candidate expressions, updates and manages the set of current solutions, and dynamically modifies search parameters using time-based adjustments. When a complete solution is identified, it aborts remaining threads and returns the synthesized expression.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> AllocForAny<T> for T

Source§

fn galloc(self) -> &'static T

Provides a method to allocate an instance of T on the heap with a static lifetime.

This implementation of galloc takes ownership of the T instance and uses the alloc function to place it in a location with a static lifetime, presumably managing it in a way that ensures its persistence for the duration of the program. This can be particularly useful for scenarios where a static lifetime is required, such as when interfacing with systems or patterns that necessitate global state or long-lived data.

Source§

fn galloc_mut(self) -> &'static T

Provides a method that moves the instance and returns a reference to it allocated with a static lifetime.

This method utilizes alloc_mut to perform the allocation, likely involving allocating the resource in a manner that ensures it lives for the entire duration of the application. These semantics allow the user to safely assume that the reference will not expire during the program’s execution, making it suitable for long-lived data structures or operations that require such guarantees.

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> 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, 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