Skip to main content

CompiledGraph

Struct CompiledGraph 

Source
pub struct CompiledGraph {
    pub nodes: Vec<NodeEntry>,
    pub free_keys: Vec<String>,
    pub node_free_cols: Vec<Vec<(usize, usize)>>,
    pub tied_plan: TiedPlan,
    pub dataset_offsets: Vec<usize>,
}
Expand description

The compiled representation of a FitGraphSpec, ready for evaluation.

Fields§

§nodes: Vec<NodeEntry>

Nodes in their original declaration order (used for evaluation).

§free_keys: Vec<String>

Keys "node_id.param_name" for all free parameters, sorted by node_id alphabetically, then by model param order within a node.

§node_free_cols: Vec<Vec<(usize, usize)>>

Per-node Jacobian column layout, pre-computed during [compile].

node_free_cols[i] lists (local_param_idx, jac_col) for every free parameter on nodes[i]. Used by the solver to avoid string-parsing free_keys on every iteration.

§tied_plan: TiedPlan

Dependency-ordered plan for tied (expr_edge) parameters.

Empty when the graph declares no expr_edges. When non-empty, the solver calls TiedPlan::apply on the flat parameter map after updating the free parameters on every iteration, so that each tied target is recomputed from its expression before the model is evaluated.

Applied per-iteration by spectrafit-solver::lm_problem::set_free_and_tied — the single set_params entry shared by both the nalgebra-LM and faer trust-region front-ends. The FD Jacobian re-applies ties per perturbation, and the analytic Jacobian is swapped for FD when ties are present so chain-rule terms are captured. End-to-end coverage: dispatch::tests::test_tied_amplitude_fit_recovers_ratio and test_tied_fit_reduces_free_param_count in the solver crate.

§dataset_offsets: Vec<usize>

Per-dataset point boundaries for simultaneous multi-dataset (“global analysis”) fits: cumulative offsets of length n_datasets + 1, so dataset i owns the concatenated point-range [offsets[i], offsets[i+1]).

Empty by default (single-dataset / fully-global fits). The solver dispatch fills it from the dataset sizes after compile(). The executor only consults it when it is non-empty AND at least one node carries a [NodeEntry::dataset_index]; otherwise every node contributes to all points exactly as before (the all-global path is byte-identical).

Implementations§

Source§

impl CompiledGraph

Source

pub fn compile(graph: &FitGraphSpec) -> Result<Self, CoreError>

Compile a FitGraphSpec into a CompiledGraph.

§Errors

Returns CoreError::Eval if:

  • an unknown model type is encountered
  • a required parameter is missing from the spec
  • two nodes share the same id (would silently corrupt the free-column layout and overwrite components)
  • expr_edges contain duplicate targets (cycle / conflict)
Source

pub fn node_params( &self, node_idx: usize, flat: &HashMap<String, f64>, ) -> Result<Vec<f64>, CoreError>

Extract the parameter value vector for node at node_idx from the flat dict.

Values are ordered to match model.param_names().

§Errors

Returns CoreError::Eval (via GraphError::MissingParamKey) if flat has no entry for one of the node’s "node_id.param_name" keys.

Source

pub fn n_dims(&self) -> Result<usize, CoreError>

The common coordinate dimensionality shared by every node in the graph.

The executor lays the flat x buffer out point-major (stride = n_dims), so all nodes must agree on how many coordinate components a single point carries. A graph that mixes a 1-D and a 2-D model over the same coordinate grid is rejected.

Returns 1 for an empty graph (degenerate but harmless; evaluation produces zeros).

§Errors

Returns CoreError::Eval if nodes declare differing n_dims.

Auto Trait Implementations§

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

impl<T> Pointable for T

§

const ALIGN: usize

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

Source§

type Output = T

Should always be Self
§

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

§

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

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

fn is_in_subset(&self) -> bool

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

fn to_subset_unchecked(&self) -> SS

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

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.