v1alpha1

package
v0.1.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 5, 2024 License: Apache-2.0 Imports: 16 Imported by: 2

Documentation

Index

Constants

View Source
const (
	ErrExperimentNameInvalid  api.ErrorType = "experiment-name-invalid"
	ErrExperimentNameConflict api.ErrorType = "experiment-name-conflict"
	ErrExperimentInvalid      api.ErrorType = "experiment-invalid"
	ErrExperimentNotFound     api.ErrorType = "experiment-not-found"
	ErrExperimentStopped      api.ErrorType = "experiment-stopped"
	ErrTrialInvalid           api.ErrorType = "trial-invalid"
	ErrTrialUnavailable       api.ErrorType = "trial-unavailable"
	ErrTrialNotFound          api.ErrorType = "trial-not-found"
	ErrTrialAlreadyReported   api.ErrorType = "trial-already-reported"
)

Variables

This section is empty.

Functions

func CheckParameterConstraints added in v0.0.25

func CheckParameterConstraints(assignments []Assignment, constraints []Constraint) error

CheckParameterConstraints validates that the supplied assignments do not validate the constraints.

func CheckParameterValue

func CheckParameterValue(p *Parameter, v *api.NumberOrString) error

CheckParameterValue validates that the supplied value can be used for a parameter.

func JoinTrialName added in v0.0.15

func JoinTrialName(e *Experiment, number int64) string

JoinTrialName combines an experiment and a trial.

Types

type API

type API interface {
	// CheckEndpoint verifies we can talk to the backend.
	CheckEndpoint(ctx context.Context) (api.Metadata, error)

	GetAllExperiments(context.Context, ExperimentListQuery) (ExperimentList, error)
	GetAllExperimentsByPage(context.Context, string) (ExperimentList, error)
	GetExperimentByName(context.Context, ExperimentName) (Experiment, error)
	GetExperiment(context.Context, string) (Experiment, error)
	CreateExperimentByName(context.Context, ExperimentName, Experiment) (Experiment, error)
	CreateExperiment(context.Context, string, Experiment) (Experiment, error)
	DeleteExperiment(context.Context, string) error
	LabelExperiment(context.Context, string, ExperimentLabels) error

	GetAllTrials(context.Context, string, TrialListQuery) (TrialList, error)
	CreateTrial(context.Context, string, TrialAssignments) (TrialAssignments, error)
	NextTrial(context.Context, string) (TrialAssignments, error)
	ReportTrial(context.Context, string, TrialValues) error
	AbandonRunningTrial(context.Context, string) error
	LabelTrial(context.Context, string, TrialLabels) error
}

API provides bindings for the supported endpoints

func NewAPI

func NewAPI(client api.Client) API

NewAPI returns a new API implementation for the specified client.

func NewAPIWithEndpoint added in v0.0.15

func NewAPIWithEndpoint(client api.Client, endpoint string) (API, error)

NewAPIWithEndpoint returns a new API implementation with an alternate endpoint.

type Assignment

type Assignment struct {
	// The name of the parameter in the experiment the assignment corresponds to.
	ParameterName string `json:"parameterName"`
	// The assigned value of the parameter.
	Value api.NumberOrString `json:"value"`
}

type Bounds

type Bounds struct {
	// The minimum value for a numeric parameter.
	Min json.Number `json:"min"`
	// The maximum value for a numeric parameter.
	Max json.Number `json:"max"`
}

type Constraint

type Constraint struct {
	// Optional name for constraint.
	Name string `json:"name,omitempty"`

	ConstraintType   ConstraintType `json:"constraintType"`
	*SumConstraint   `json:",omitempty"`
	*OrderConstraint `json:",omitempty"`
}

type ConstraintType

type ConstraintType string
const (
	ConstraintSum   ConstraintType = "sum"
	ConstraintOrder ConstraintType = "order"
)

type Experiment

type Experiment struct {
	// The experiment metadata.
	api.Metadata `json:"-"`
	// The name of the experiment.
	Name ExperimentName `json:"-"`
	// The display name of the experiment.
	DisplayName string `json:"displayName,omitempty"`
	// The number of observations made for this experiment.
	Observations int64 `json:"observations,omitempty"`
	// The target number of observations for this experiment.
	Budget int64 `json:"budget,omitempty"`
	// Controls how the optimizer will generate trials.
	Optimization []Optimization `json:"optimization,omitempty"`
	// The metrics been optimized in the experiment.
	Metrics []Metric `json:"metrics"`
	// Constraints for the experiment.
	Constraints []Constraint `json:"constraints,omitempty"`
	// The search space of the experiment.
	Parameters []Parameter `json:"parameters"`
	// Labels for this experiment.
	Labels map[string]string `json:"labels,omitempty"`
}

Experiment combines the search space, outcomes and optimization configuration

func (*Experiment) UnmarshalJSON added in v0.0.15

func (e *Experiment) UnmarshalJSON(data []byte) error

type ExperimentItem

type ExperimentItem struct {
	Experiment
}

func (*ExperimentItem) UnmarshalJSON added in v0.0.11

func (ei *ExperimentItem) UnmarshalJSON(b []byte) error

type ExperimentLabels

type ExperimentLabels struct {
	// New labels for this experiment.
	Labels map[string]string `json:"labels"`
}

type ExperimentList

type ExperimentList struct {
	// The experiment list metadata.
	api.Metadata `json:"-"`
	// The list of experiments.
	Experiments []ExperimentItem `json:"experiments,omitempty"`
}

type ExperimentListQuery

type ExperimentListQuery struct{ api.IndexQuery }

type ExperimentName

type ExperimentName string

ExperimentName represents a name token used to identify an experiment.

func SplitTrialName

func SplitTrialName(name string) (ExperimentName, int64)

SplitTrialName provides a consistent experience when trying to split a "trial name" into an experiment name and a trial number. When the provided name does not contain a number, the resulting number will be less than zero.

func (ExperimentName) String added in v0.0.15

func (n ExperimentName) String() string

type Lister added in v0.0.21

type Lister struct {
	// API is the Experiment API used to fetch objects.
	API API
	// BatchSize overrides the default batch size for fetching lists.
	BatchSize int
}

Lister is a helper to individually visit all items in a list (even across page boundaries).

func (*Lister) ForEachExperiment added in v0.0.21

func (l *Lister) ForEachExperiment(ctx context.Context, q ExperimentListQuery, f func(*ExperimentItem) error) error

ForEachExperiment iterates over all the experiments matching the supplied query.

func (*Lister) ForEachNamedExperiment added in v0.0.25

func (l *Lister) ForEachNamedExperiment(ctx context.Context, names []string, ignoreNotFound bool, f func(*ExperimentItem) error) error

ForEachNamedExperiment iterates over all the named experiments, optionally ignoring those that do not exist.

func (*Lister) ForEachNamedTrial added in v0.0.25

func (l *Lister) ForEachNamedTrial(ctx context.Context, names []string, q TrialListQuery, ignoreNotFound bool, f func(*TrialItem) error) error

ForEachNamedTrial iterates over all the named trials, optionally ignoring those that do not exist.

func (*Lister) ForEachTrial added in v0.0.21

func (l *Lister) ForEachTrial(ctx context.Context, exp *Experiment, q TrialListQuery, f func(*TrialItem) error) (err error)

ForEachTrial iterates over all trials for an experiment matching the supplied query.

type Metric

type Metric struct {
	// The name of the metric.
	Name string `json:"name"`
	// The flag indicating this metric should be minimized.
	Minimize bool `json:"minimize,omitempty"`
	// The flag indicating this metric is optimized (nil defaults to true).
	Optimize *bool `json:"optimize,omitempty"`
}

type Optimization

type Optimization struct {
	// The name of the optimization parameter.
	Name string `json:"name"`
	// The value of the optimization parameter.
	Value string `json:"value"`
}

type OrderConstraint

type OrderConstraint struct {
	// Name of lower parameter.
	LowerParameter string `json:"lowerParameter"`
	// Name of upper parameter.
	UpperParameter string `json:"upperParameter"`
}

type Parameter

type Parameter struct {
	// The name of the parameter.
	Name string `json:"name"`
	// The type of the parameter.
	Type ParameterType `json:"type"`
	// The domain of the parameter.
	Bounds *Bounds `json:"bounds,omitempty"`
	// The discrete values for a categorical parameter.
	Values []string `json:"values,omitempty"`
}

Parameter is a variable that is going to be tuned in an experiment

func (*Parameter) LowerBound

func (p *Parameter) LowerBound() (*api.NumberOrString, error)

LowerBound attempts to return the lower bound for this parameter.

func (*Parameter) ParseValue

func (p *Parameter) ParseValue(s string) (*api.NumberOrString, error)

ParseValue attempts to parse the supplied value into a NumberOrString based on the type of this parameter.

func (*Parameter) RandomValue added in v0.0.25

func (p *Parameter) RandomValue() (*api.NumberOrString, error)

RandomValue returns a random value for a parameter.

func (*Parameter) UpperBound

func (p *Parameter) UpperBound() (*api.NumberOrString, error)

UpperBound attempts to return the upper bound for this parameter.

type ParameterType

type ParameterType string
const (
	ParameterTypeInteger     ParameterType = "int"
	ParameterTypeDouble      ParameterType = "double"
	ParameterTypeCategorical ParameterType = "categorical"
)

type Server added in v0.0.11

type Server struct {
	api.Metadata `json:"-"`
}

type SumConstraint

type SumConstraint struct {
	// Flag indicating if bound is upper or lower bound.
	IsUpperBound bool `json:"isUpperBound,omitempty"`
	// Bound for inequality constraint.
	Bound float64 `json:"bound"`
	// Parameters and weights for constraint.
	Parameters []SumConstraintParameter `json:"parameters"`
}

type SumConstraintParameter

type SumConstraintParameter struct {
	// Name of parameter to be used in constraint.
	ParameterName string `json:"parameterName"`
	// Weight for parameter in constraint.
	Weight float64 `json:"weight"`
}

type TrialAssignments

type TrialAssignments struct {
	// The trial metadata.
	api.Metadata `json:"-"`
	// The list of parameter names and their assigned values.
	Assignments []Assignment `json:"assignments"`
	// Labels for this trial.
	Labels map[string]string `json:"labels,omitempty"`
}

func NewTrialAssignments added in v0.1.7

func NewTrialAssignments(e *Experiment, assignments map[string]string, baselines map[string]*api.NumberOrString, defaultBehavior string) (*TrialAssignments, error)

NewTrialAssignments constructs a trial assignments instance using the supplied string values. The default behavior can be "none", "baseline", "minimum", "maximum", or "random".

type TrialItem

type TrialItem struct {
	TrialAssignments
	TrialValues

	// The current trial status.
	Status TrialStatus `json:"status"`
	// Ordinal number indicating when during an experiment the trail was generated.
	Number int64 `json:"number"`

	// Experiment is a reference back to the experiment this trial item is associated with. This field is never
	// populated by the API, but may be useful for consumers to maintain a connection between resources.
	Experiment *Experiment `json:"-"`
}

func (*TrialItem) UnmarshalJSON added in v0.0.11

func (ti *TrialItem) UnmarshalJSON(b []byte) error

type TrialLabels

type TrialLabels struct {
	// New labels for this trial.
	Labels map[string]string `json:"labels"`
}

type TrialList

type TrialList struct {
	// The trial list metadata.
	api.Metadata `json:"-"`
	// The list of trials.
	Trials []TrialItem `json:"trials"`

	// Experiment is a reference back to the experiment this trial item is associated with. This field is never
	// populated by the API, but may be useful for consumers to maintain a connection between resources.
	Experiment *Experiment `json:"-"`
}

type TrialListQuery

type TrialListQuery struct{ api.IndexQuery }

func (*TrialListQuery) AddStatus added in v0.0.11

func (q *TrialListQuery) AddStatus(status TrialStatus)

func (*TrialListQuery) SetStatus added in v0.0.11

func (q *TrialListQuery) SetStatus(status ...TrialStatus)

type TrialStatus

type TrialStatus string
const (
	TrialStaged    TrialStatus = "staged"
	TrialActive    TrialStatus = "active"
	TrialCompleted TrialStatus = "completed"
	TrialFailed    TrialStatus = "failed"
	TrialAbandoned TrialStatus = "abandoned"
)

type TrialValues

type TrialValues struct {
	// The observed values.
	Values []Value `json:"values,omitempty"`
	// Indicator that the trial failed, Values is ignored when true.
	Failed bool `json:"failed,omitempty"`
	// FailureReason is a the machine-readable reason code for the failure, if Failed is true.
	FailureReason string `json:"failureReason,omitempty"`
	// FailureMessage is a human-readable explanation of the failure, if Failed is true.
	FailureMessage string `json:"failureMessage,omitempty"`
	// StartTime is the time at which the trial was started.
	StartTime *time.Time `json:"startTime,omitempty"`
	// CompletionTime is the time at which the trial was completed.
	CompletionTime *time.Time `json:"completionTime,omitempty"`
}

type Value

type Value struct {
	// The name of the metric in the experiment the value corresponds to.
	MetricName string `json:"metricName"`
	// The observed value of the metric.
	Value float64 `json:"value"`
	// The observed error of the metric.
	Error float64 `json:"error,omitempty"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL