Struct SpaceSchema
pub struct SpaceSchema { /* private fields */ }Expand description
An ordered set of declared parameters.
Two orders coexist on purpose:
- declaration order is what
iteryields and what theGridsampler enumerates in, so a schema written by a human keeps reading like the struct it came from; - sorted order is what
Assignmentuses 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
impl SpaceSchema
pub fn empty() -> Self
pub fn empty() -> Self
An empty schema.
pub fn new<I>(specs: I) -> Result<Self>where
I: IntoIterator<Item = ParamSpec>,
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 declare(
&mut self,
name: impl Into<String>,
distribution: Distribution,
) -> Result<()>
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 distribution(&self, name: &str) -> Option<&Distribution>
pub fn distribution(&self, name: &str) -> Option<&Distribution>
The support declared for name, if it exists.
pub fn cardinality(&self) -> Option<u64>
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<()>
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
impl Clone for SpaceSchema
§fn clone(&self) -> SpaceSchema
fn clone(&self) -> SpaceSchema
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more