Documentation ¶
Overview ¶
Package diviner implements common data structures to support a black-box optimization framework in the style of Google Vizier [1]. Implementations of optimization algorithms as well runner infrastructure, parallel execution, and a command line tool are implemented in subpackages.
[1] http://www.kdd.org/kdd2017/papers/view/google-vizier-a-service-for-black-box-optimization
Index ¶
- Variables
- func Hash(v Value) uint64
- type Bool
- func (v Bool) Bool() bool
- func (v Bool) Equal(w Value) bool
- func (v Bool) Float() float64
- func (Bool) Get(key string) Value
- func (v Bool) Hash(h hash.Hash)
- func (Bool) Index(int) Value
- func (Bool) Int() int64
- func (Bool) Kind() Kind
- func (Bool) Len() int
- func (v Bool) Less(w Value) bool
- func (Bool) Put(key string, value Value)
- func (Bool) Range(func(key string, value Value))
- func (Bool) Str() string
- func (v Bool) String() string
- type Database
- type Dataset
- type Dict
- type Direction
- type Discrete
- func (*Discrete) Freeze()
- func (*Discrete) Hash() (uint32, error)
- func (d *Discrete) IsValid(v Value) bool
- func (d *Discrete) Kind() Kind
- func (d *Discrete) Sample(r *rand.Rand) Value
- func (d *Discrete) String() string
- func (*Discrete) Truth() starlark.Bool
- func (*Discrete) Type() string
- func (d *Discrete) Values() []Value
- type Float
- func (Float) Bool() bool
- func (v Float) Equal(w Value) bool
- func (v Float) Float() float64
- func (Float) Get(key string) Value
- func (v Float) Hash(h hash.Hash)
- func (Float) Index(int) Value
- func (Float) Int() int64
- func (Float) Kind() Kind
- func (Float) Len() int
- func (v Float) Less(w Value) bool
- func (Float) Put(key string, value Value)
- func (Float) Range(func(key string, value Value))
- func (Float) Str() string
- func (v Float) String() string
- type Int
- func (Int) Bool() bool
- func (v Int) Equal(w Value) bool
- func (Int) Float() float64
- func (Int) Get(key string) Value
- func (v Int) Hash(h hash.Hash)
- func (Int) Index(int) Value
- func (v Int) Int() int64
- func (Int) Kind() Kind
- func (Int) Len() int
- func (v Int) Less(w Value) bool
- func (Int) Put(key string, value Value)
- func (Int) Range(func(key string, value Value))
- func (Int) Str() string
- func (v Int) String() string
- type Kind
- type List
- func (List) Bool() bool
- func (l List) Equal(m Value) bool
- func (List) Float() float64
- func (List) Get(key string) Value
- func (l List) Hash(h hash.Hash)
- func (l List) Index(i int) Value
- func (List) Int() int64
- func (List) Kind() Kind
- func (l List) Len() int
- func (l List) Less(m Value) bool
- func (List) Put(key string, value Value)
- func (List) Range(func(key string, value Value))
- func (List) Str() string
- func (l List) String() string
- type Map
- type Metric
- type Metrics
- type NamedParam
- type NamedValue
- type Objective
- type Oracle
- type Param
- type Params
- type Range
- type Replicates
- type Run
- type RunConfig
- type RunState
- type String
- func (String) Bool() bool
- func (v String) Equal(w Value) bool
- func (String) Float() float64
- func (String) Get(key string) Value
- func (v String) Hash(h hash.Hash)
- func (String) Index(int) Value
- func (String) Int() int64
- func (String) Kind() Kind
- func (String) Len() int
- func (v String) Less(w Value) bool
- func (String) Put(key string, value Value)
- func (String) Range(func(key string, value Value))
- func (v String) Str() string
- func (v String) String() string
- type Study
- type System
- type Trial
- type Value
- type Values
- func (Values) Bool() bool
- func (v Values) Equal(wv Value) bool
- func (Values) Float() float64
- func (v Values) Hash(h hash.Hash)
- func (Values) Index(i int) Value
- func (Values) Int() int64
- func (Values) Kind() Kind
- func (v Values) Len() int
- func (Values) Less(Value) bool
- func (v Values) Sorted() []NamedValue
- func (Values) Str() string
- func (v Values) String() string
Constants ¶
This section is empty.
Variables ¶
var ErrNotExist = errors.New("study or run does not exist")
ErrNotExist is returned from a database when a study or run does not exist.
Functions ¶
Types ¶
type Database ¶
type Database interface { // CreateTable creates the underlying database table. CreateTable(context.Context) error // CreateStudyIfNotExist creates a new study from the provided Study value. // If the study already exists, this is a no-op. CreateStudyIfNotExist(ctx context.Context, study Study) (created bool, err error) // LookupStudy returns the study with the provided name. LookupStudy(ctx context.Context, name string) (Study, error) // ListStudies returns the set of studies matching the provided prefix and whose // last update time is not before the provided time. ListStudies(ctx context.Context, prefix string, since time.Time) ([]Study, error) // NextSeq reserves and returns the next run sequence number for the // provided study. NextSeq(ctx context.Context, study string) (uint64, error) // InsertRun inserts the provided run into a study. The run's study, // values, and config must be populated; other fields are ignored. // If the sequence number is provided (>0), then it is assumed to // have been reserved by NextSeq. The run's study must already // exist, and the returned Run is assigned a sequence number, state, // and creation time. InsertRun(ctx context.Context, run Run) (Run, error) // UpdateRun updates the run named by the provided study and // sequence number with the given run state, message, runtime, and // current retry sequence. // UpdateRun is used also as a keepalive mechanism: runners must // call UpdateRun frequently in order to have the run considered // live by Diviner's tooling. UpdateRun(ctx context.Context, study string, seq uint64, state RunState, message string, runtime time.Duration, retry int) error // AppendRunMetrics reports a new set of metrics to the run named by the provided // study and sequence number. AppendRunMetrics(ctx context.Context, study string, seq uint64, metrics Metrics) error // ListRuns returns the set of runs in the provided study matching the queried // run states. ListRuns only returns runs that have been updated since the provided // time. ListRuns(ctx context.Context, study string, states RunState, since time.Time) ([]Run, error) // LookupRun returns the run named by the provided study and sequence number. LookupRun(ctx context.Context, study string, seq uint64) (Run, error) // Log obtains a reader for the logs emitted by the run named by the study and // sequence number. If !since.IsZero(), show messages added at or after the // given time. If follow is true, the returned reader is a perpetual stream, // updated as new log entries are appended. Log(study string, seq uint64, since time.Time, follow bool) io.Reader // Logger returns an io.WriteCloser, to which log messages can be written, // for the run named by a study and sequence number. Logger(study string, seq uint64) io.WriteCloser }
A Database is used to track and manage studies and runs.
type Dataset ¶
type Dataset struct { // Name is a unique name describing the dataset. Uniqueness is // required: diviner only runs one dataset for each named dataset, Name string // IfNotExist may contain a URL which is checked for existence // before running the script that produces this dataset. It is // assumed the dataset already exists if the URL exists. IfNotExist string // LocalFiles is a set of files (local to where diviner is run) // that should be made available in the script's environment. // These files are copied into the script's working directory, // retaining their basenames. (Thus the set of basenames in // the list should not collide.) LocalFiles []string // Script is a Bash script that is run to produce this dataset. Script string // Systems identifies the list of systems where the dataset run should be // performed. This can be used to schedule jobs with different kinds of // systems requirements. If Len(Systems)>1, each is tried until one of them // successfully allocates a machine. Systems []*System }
A Dataset describes a preprocessing step that's required by a run. It may be shared among multiple runs.
type Direction ¶
type Direction int
Direction is the direction of the objective.
type Discrete ¶
A Discrete is a parameter that takes on a finite set of values.
func NewDiscrete ¶
NewDiscrete returns a new discrete param comprising the given values. NewDiscrete panics if all returned values are not of the same Kind, or if zero values are passed.
func (*Discrete) IsValid ¶
IsValid tells whether the value v belongs to the set of allowable values.
type Map ¶
type Map struct {
// contains filtered or unexported fields
}
Map implements an associative array between Diviner values and Go values. A map is not itself a Value.
func Trials ¶
Trials queries the database db for all runs in the provided study, and returns a set of composite trials for each replicate of a value set. The returned map maps value sets to these composite trials.
Trial metrics are averaged across runs in the states as indicated by the provided run states; flags are set on the returned trials to indicate which replicates they comprise and whether any pending results were used.
TODO(marius): this is a reasonable approach for some metrics, but not for others. We should provide a way for users to (e.g., as part of a study definition) to define their own means of defining composite metrics, e.g., by intepreting metrics from each run, or their outputs directly (e.g., predictions from an evaluation run).
func (*Map) Put ¶
Put associated the value value with the provided key. Existing entries for a value is overridden.
type Metrics ¶
Metrics is a set of measurements output by black boxes. A subset of metrics may be used in the optimization objective, but the set of metrics may include others for diagnostic purposes.
type NamedParam ¶
type NamedParam struct { // Name is the parameter's name. Name string // Param is the parameter. Param }
NamedParam represents a named parameter.
type NamedValue ¶
A NamedValue is a value that is assigned a name.
type Objective ¶
type Objective struct { // Direction indicates the direction (minimize, maximize) of the // the optimization objective. Direction Direction // Metric names the metric to be optimized. Metric string }
Objective is an optimization objective.
type Oracle ¶
type Oracle interface { // Next returns the next n parameter values to run, given the // provided history of trials, the set of parameters and an // objective. If Next returns fewer than n trials, then the oracle // is exhausted. Next(previous []Trial, params Params, objective Objective, n int) ([]Values, error) }
An Oracle is an optimization algorithm that picks a set of parameter values given a history of runs.
type Param ¶
type Param interface { // Kind returns the kind of values encapsulated by this param. Kind() Kind // Values returns the set of values allowable by this parameter. // Nil is returned if the param's image is not finite. Values() []Value // Sample returns a Value from this param sampled by the provided // random number generator. Sample(r *rand.Rand) Value // IsValid tells whether the provided value is valid for this parameter. IsValid(value Value) bool // Params implement starlark.Value so they can be represented // directly in starlark configuration scripts. starlark.Value }
A Param is a kind of parameter. Params determine the range of allowable values of an input.
type Params ¶
Params stores a set of parameters under optimization.
func (Params) IsValid ¶
IsValid returns whether the given set of values are a valid assignment of exactly the parameters in this Params.
func (Params) Sorted ¶
func (p Params) Sorted() []NamedParam
Sorted returns the set of parameters sorted by name.
type Range ¶
type Range struct {
Start, End Value
}
Range is a parameter that is defined over a range of real numbers.
func (*Range) Sample ¶
Sample draws a random sample from within the range represented by this parameter.
type Replicates ¶
type Replicates uint64
Replicates is a bitset of replicate numbers.
func (*Replicates) Clear ¶
func (r *Replicates) Clear(rep int)
Clear clears the replicate number rep in the replicate set r.
func (Replicates) Completed ¶
func (r Replicates) Completed(n int) bool
Completed reports whether n replicates have completed in the replicate set r.
func (Replicates) Contains ¶
func (r Replicates) Contains(rep int) bool
Contains reports whether the replicate set r contains the replicate number rep.
func (Replicates) Count ¶
func (r Replicates) Count() int
Count returns the number of replicates defined in the replicate set r.
func (Replicates) Next ¶
func (r Replicates) Next() (int, Replicates)
Next iterates over replicates. It returns the first replicate in the set as well as the replicate set with that replicate removed. -1 is returned if the replicate set is empty.
Iteration can thus proceed:
var r Replicates for num, r := r.Next(); num != -1; num, r = r.Next() { // Process num }
func (*Replicates) Set ¶
func (r *Replicates) Set(rep int)
Set sets the replicate number rep in the replicate set r.
type Run ¶
type Run struct { // Values is the set of parameter values represented by this run. Values // Study is the name of the study serviced by this run. Study string // Seq is a sequence number assigned to each run in a study. // Together, the study and sequence number uniquely names // a run. Seq uint64 // Replicate is the replicate of this run. Replicate int // State is the current state of the run. See RunState for // descriptions of these. State RunState // Status is a human-consumable status indicating the status // of the run. Status string // Config is the RunConfig for this run. Config RunConfig // Created is the time at which the run was created. Created time.Time // Updated is the last time the run's state was updated. Updated is // used as a keepalive mechanism. Updated time.Time // Runtime is the runtime duration of the run. Runtime time.Duration // Number of times the run was retried. Retries int // Metrics is the history of metrics, in the order reported by the // run. // // TODO(marius): include timestamps for these, or some other // reference (e.g., runtime). Metrics []Metrics }
A Run describes a single run, which, upon successful completion, represents a Trial. Runs are managed by a Database.
type RunConfig ¶
type RunConfig struct { // Datasets contains the set of datasets required by this // run. Datasets []Dataset // Script is a script that should be interpreted by Bash. Script string // LocalFiles is a set of files (local to where diviner is run) // that should be made available in the script's environment. // These files are copied into the script's working directory, // retaining their basenames. (Thus the set of basenames in // the list should not collide.) LocalFiles []string // Systems identifies the list of systems where the run should be // performed. This can be used to schedule jobs with different kinds of // systems requirements. If Len(Systems)>1, each is tried until one of them // successfully allocates a machine. Systems []*System }
A RunConfig describes how to perform a single run of a black box with a set of parameter values. Runs are defined by a bash script and a set of files that must be included in its run environment.
Black boxes emit metrics by printing to standard output lines that begin with "METRICS: ", followed by a set of comma-separated key-value pairs of metric values. Each metric must be a number. For example, the following line emits metrics for "acc" and "loss":
METRICS: acc=0.55,loss=12.3
TODO(marius): make this mechanism more flexible and less error prone.
TODO(marius): allow interpreters other than Bash.
type RunState ¶
type RunState int
RunState describes the current state of a particular run.
const ( // Pending indicates that the run has not yet completed. Pending RunState = 1 << iota // Success indicates that the run has completed and represents // a successful trial. Success // Failure indicates that the run failed. Failure // Any contains all run states. Any = Pending | Success | Failure )
type Study ¶
type Study struct { // Name is the name of the study. Name string // Objective is the objective to be maximized. Objective Objective // Params is the set of parameters accepted by this // study. Params Params // Replicates is the number of additional replicates required for // each trial in the study. Replicates int // Human-readable description of the study. Description string // Oracle is the oracle used to pick parameter values. Oracle Oracle `json:"-"` // TODO(marius): encode oracle name/type/params? // Run is called with a set of Values (i.e., a concrete // instantiation of values in the ranges as indicated by the black // box parameters defined above); it produces a run configuration // which is then used to conduct a trial of these parameter values. // The run's replicate number is passed in. (This may be used to, // e.g., select a model fold.) Parameter id is a unique id for the // run (vis-a-vis diviner's database). It may be used to name data // and other external resources associated with the run. Run func(vals Values, replicate int, id string) (RunConfig, error) `json:"-"` // Acquire returns the metrics associated with the set of // parameter values that are provided. It is used to support // (Go) native trials. Arguments are as in Run. Acquire func(vals Values, replicate int, id string) (Metrics, error) `json:"-"` }
A Study is an experiment comprising a black box, optimization objective, and an oracle responsible for generating trials. Trials can either be managed by Diviner (through Run), or else handled natively within Go (through Acquire). Either Run or Acquire must be defined.
type System ¶
type System struct { // System is the bigmachine system configured by this system. bigmachine.System // ID is a unique identifier for this system. ID string // Parallelism specifies the maximum level of job parallelism allowable for // this system. If <= 0, the system allows unlimited parallelism. Parallelism int // Bash snippet to be prepended to the user script. // If empty, runner.DefaultPreamble is used. Preamble string }
A System describes a configuration of a machine. It is part of SystemPool.
type Trial ¶
type Trial struct { // Values is the set of parameter values used for the run. Values Values // Metrics is the metrics produced by the black box during // the run. Metrics Metrics // Pending indicates whether this is a pending trial. Pending trials // may have incomplete or non-final metrics. Pending bool // Replicates contains the set of completed replicates // comprising this trial. Replicates are stored in a bitset. Replicates Replicates // ReplicateMetrics breaks down metrics for each underlying replicate. // Valid only for trials that comprise multiple replicates. ReplicateMetrics map[int]Metrics // Runs stores the set of runs comprised by this trial. Runs []Run }
A Trial is the result of a single run of a black box.
func ReplicatedTrial ¶
ReplicatedTrials constructs a single trial from the provided trials. The composite trial represents each replicate present in the provided replicates. Metrics are averaged. The provided trials cannot themselves contain multiple replicates.
type Value ¶
type Value interface { // String returns a textual description of the parameter value. String() string // Kind returns the kind of this value. Kind() Kind // Equal tells whether two values are equal. Values of different // kinds are never equal. Equal(Value) bool // Less returns true if the value is less than the provided value. // Less is defined only for values of the same type. Less(Value) bool // Float returns the floating point value of float-typed values. Float() float64 // Int returns the integer value of integer-typed values. Int() int64 // Str returns the string of string-typed values. Str() string // Bool returns the boolean of boolean-typed values. Bool() bool // Len returns the length of a sequence value. Len() int // Index returns the value at an index of a sequence. Index(i int) Value // Hash adds the value's hask to the provided hasher. Hash(h hash.Hash) }
Value is the type of parameter values. Values must be directly comparable.
type Values ¶
Values is a sorted set of named values, used as a concrete instantiation of a set of parameters.
Note: the representation of Values is not optimal. Ideally we would store it as a sorted list of NamedValues. However, backwards compatibility (by way of gob) forces our hand here.
func (Values) Sorted ¶
func (v Values) Sorted() []NamedValue
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
diviner
Diviner is a black-box optimization framework that uses Bigmachine to distribute a large number of computationally expensive trials across clusters of machines.
|
Diviner is a black-box optimization framework that uses Bigmachine to distribute a large number of computationally expensive trials across clusters of machines. |
Package dydb implements a diviner.Database on top of dynamodb and the AWS cloudwatch logs storage.
|
Package dydb implements a diviner.Database on top of dynamodb and the AWS cloudwatch logs storage. |
dynamoattr
Package dynamoattr provides functions for marshaling and unmarshaling Go values to and from DynamoDB items (map[string]*dynamodb.AttributeValue).
|
Package dynamoattr provides functions for marshaling and unmarshaling Go values to and from DynamoDB items (map[string]*dynamodb.AttributeValue). |
Package localdb implements a diviner database on the local file system using boltdb.
|
Package localdb implements a diviner database on the local file system using boltdb. |
Package oracle includes pre-defined oracles for picking parameter values.
|
Package oracle includes pre-defined oracles for picking parameter values. |
Package runner provides a simple parallel cluster runner for diviner studies.
|
Package runner provides a simple parallel cluster runner for diviner studies. |
Package script implements scripting support for defining Diviner studies through Starlark [1].
|
Package script implements scripting support for defining Diviner studies through Starlark [1]. |