Skip to main content

SpaceSchema

Struct SpaceSchema 

pub struct SpaceSchema { /* private fields */ }
Expand description

An ordered set of declared parameters.

Two orders coexist on purpose:

  • declaration order is what iter yields and what the Grid sampler enumerates in, so a schema written by a human keeps reading like the struct it came from;
  • sorted order is what Assignment uses for the resulting values.

Both are deterministic; neither is a hash order. Lookup by name goes through an index, so get stays cheap for wide spaces.

Duplicate names are rejected at construction: a name is a parameter’s identity, and two supports for one identity is exactly the ambiguity the compatibility gate exists to prevent.

use atune_core::space::{Distribution, ParamSpec, SpaceSchema};

let schema = SpaceSchema::new([
    ParamSpec::new("lr", Distribution::float_log(1e-5, 1e-2).unwrap()).unwrap(),
    ParamSpec::new("batch", Distribution::int_log(16, 512).unwrap()).unwrap(),
])
.unwrap();

assert_eq!(schema.len(), 2);
assert_eq!(schema.names().collect::<Vec<_>>(), ["lr", "batch"]); // declaration order
assert!(schema.get("batch").is_some());

Implementations§

§

impl SpaceSchema

pub fn empty() -> Self

An empty schema.

pub fn new<I>(specs: I) -> Result<Self>
where I: IntoIterator<Item = ParamSpec>,

Builds a schema from parameter declarations, in declaration order.

§Errors

Error::InvalidSpace if a name occurs twice.

pub fn push(&mut self, spec: ParamSpec) -> Result<()>

Appends a declaration.

§Errors

Error::InvalidSpace if the name is already declared.

pub fn declare( &mut self, name: impl Into<String>, distribution: Distribution, ) -> Result<()>

Declares name with distribution.

§Errors

Error::InvalidSpace if the name is empty or already declared, or the distribution is malformed.

pub fn get(&self, name: &str) -> Option<&ParamSpec>

The declaration for name, if it exists.

pub fn distribution(&self, name: &str) -> Option<&Distribution>

The support declared for name, if it exists.

pub fn contains(&self, name: &str) -> bool

true if name is declared.

pub fn iter(&self) -> Iter<'_, ParamSpec> ⓘ

The declarations, in declaration order.

pub fn names(&self) -> impl Iterator<Item = &str>

The declared names, in declaration order.

pub fn len(&self) -> usize

The number of declared parameters.

pub fn is_empty(&self) -> bool

true if nothing is declared.

pub fn cardinality(&self) -> Option<u64>

The number of distinct configurations, or None if any parameter is continuous.

Saturates at u64::MAX. This is what an exhaustive sampler checks before deciding a space can be enumerated at all.

pub fn validate_assignment(&self, params: &Assignment) -> Result<()>

Checks that every value in params belongs to its declared support.

Extra bindings that the schema does not declare are ignored: a define-by-run objective may legitimately suggest parameters outside a statically declared subset.

§Errors

Error::OutOfRange naming the first offending parameter.

Trait Implementations§

§

impl Clone for SpaceSchema

§

fn clone(&self) -> SpaceSchema

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for SpaceSchema

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
§

impl Default for SpaceSchema

§

fn default() -> SpaceSchema

Returns the “default value” for a type. Read more
§

impl<'de> Deserialize<'de> for SpaceSchema

§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
§

impl From<SpaceSchema> for Vec<ParamSpec>

§

fn from(schema: SpaceSchema) -> Self

Converts to this type from the input type.
§

impl<'a> IntoIterator for &'a SpaceSchema

§

type Item = &'a ParamSpec

The type of the elements being iterated over.
§

type IntoIter = Iter<'a, ParamSpec>

Which kind of iterator are we turning this into?
§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
§

impl PartialEq for SpaceSchema

§

fn eq(&self, other: &SpaceSchema) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
§

impl Serialize for SpaceSchema

§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
§

impl StructuralPartialEq for SpaceSchema

§

impl TryFrom<Vec<ParamSpec>> for SpaceSchema

§

type Error = Error

The type returned in the event of a conversion error.
§

fn try_from(specs: Vec<ParamSpec>) -> Result<Self>

Performs the conversion.

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more