pub struct CompiledProgram {
pub instruction: String,
pub demo_indices: SmallVec<[u32; 8]>,
pub score: f64,
pub optimizer: String,
pub metadata: BTreeMap<String, String>,
}Expand description
A compiled program from optimization, serializable to disk.
This captures the artifacts produced by an optimizer run:
- The tuned instruction/system prompt
- Indices into a demo pool for few-shot examples
- The score achieved during optimization
- Which optimizer produced the result
- Arbitrary string metadata
§Serialization
CompiledProgram supports JSON serialization via save /
load, and a compact format via
save_compact.
Fields§
§instruction: StringThe optimized instruction/prompt.
demo_indices: SmallVec<[u32; 8]>Indices of selected demonstration examples.
score: f64Final optimization score achieved.
optimizer: StringName of the optimizer that produced this.
metadata: BTreeMap<String, String>Optional metadata (e.g., hyperparameters, dataset info).
Implementations§
Source§impl CompiledProgram
impl CompiledProgram
Sourcepub fn new(
instruction: String,
demo_indices: SmallVec<[u32; 8]>,
score: f64,
optimizer: String,
) -> Self
pub fn new( instruction: String, demo_indices: SmallVec<[u32; 8]>, score: f64, optimizer: String, ) -> Self
Create a new compiled program.
§Arguments
instruction- The optimized instruction/system promptdemo_indices- Indices into the training set for selected demosscore- Final optimization score (typically 0.0..=1.0)optimizer- Name of the optimizer that produced this result
Sourcepub fn with_meta(self, key: impl Into<String>, value: impl Into<String>) -> Self
pub fn with_meta(self, key: impl Into<String>, value: impl Into<String>) -> Self
Add a metadata entry, returning self for chaining.
Sourcepub fn save(&self, path: &str) -> Result<()>
pub fn save(&self, path: &str) -> Result<()>
Save to a pretty-printed JSON file.
§Errors
Returns an error if the file cannot be created or serialization fails.
Sourcepub fn load(path: &str) -> Result<Self>
pub fn load(path: &str) -> Result<Self>
Load from a JSON file.
§Errors
Returns an error if the file cannot be read or deserialization fails.
Sourcepub fn save_compact(&self, path: &str) -> Result<()>
pub fn save_compact(&self, path: &str) -> Result<()>
Save to a compact (non-pretty) JSON file.
This produces a smaller file than save by omitting
whitespace formatting. Uses serde_json for broad compatibility;
a binary format (e.g., bincode) could be swapped in without
changing the public API.
§Errors
Returns an error if the file cannot be created or serialization fails.
Sourcepub fn from_json(json: &str) -> Result<Self>
pub fn from_json(json: &str) -> Result<Self>
Deserialize from a JSON string (useful for embedding in configs).
Sourcepub fn to_json_compact(&self) -> Result<String>
pub fn to_json_compact(&self) -> Result<String>
Serialize to a compact JSON string (no whitespace).
Trait Implementations§
Source§impl Clone for CompiledProgram
impl Clone for CompiledProgram
Source§fn clone(&self) -> CompiledProgram
fn clone(&self) -> CompiledProgram
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CompiledProgram
impl Debug for CompiledProgram
Source§impl<'de> Deserialize<'de> for CompiledProgram
impl<'de> Deserialize<'de> for CompiledProgram
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for CompiledProgram
impl RefUnwindSafe for CompiledProgram
impl Send for CompiledProgram
impl Sync for CompiledProgram
impl Unpin for CompiledProgram
impl UnsafeUnpin for CompiledProgram
impl UnwindSafe for CompiledProgram
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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