Documentation
¶
Index ¶
Constants ¶
const RunParam = "run"
RunParam names the column a Monte Carlo table numbers its runs in.
Variables ¶
var ( // ErrSweepRange reports a range no sequence of values follows from: a // non-numeric endpoint, endpoints measuring different things, a zero step, a // step whose sign never reaches the endpoint, a real range stating none, or an // endpoint or step that is no value of the swept parameter's type. ErrSweepRange = errors.New("invalid sweep range") // ErrSweepParameter reports a parameter the target declares none of, or one // the invocation already binds. ErrSweepParameter = errors.New("invalid sweep parameter") // ErrSweepSamples reports a sample request that draws nothing, states a step, // or asks for a distribution no library in this build states. ErrSweepSamples = errors.New("invalid sample request") // ErrSweepBudget reports a sweep asking for more runs than its budget allows. ErrSweepBudget = errors.New("sweep run budget exceeded") // ErrSweepEmpty reports a sweep or sample naming no range at all. ErrSweepEmpty = errors.New("no sweep range") // ErrSweepDistribution reports a distribution asked for by name. Sampling is // uniform over a range: the bundled library states no probability // distributions, so nothing in the model gives a named one a meaning. ErrSweepDistribution = errors.New("no distribution library") )
Typed refusals a sweep reports rather than running anything.
var ErrSweepRuns = errors.New("invalid run request")
ErrSweepRuns reports a Monte Carlo that runs nothing or states a range too.
Functions ¶
func RunNumber ¶
func RunNumber(bindings []SweepBinding) (int64, bool)
RunNumber is the number of the run a Monte Carlo row is, from its bindings.
Types ¶
type SweepBinding ¶
SweepBinding is one parameter bound to the value one row runs with.
type SweepNumbers ¶
type SweepNumbers uint8
SweepNumbers is which numbers a swept parameter's type takes, which decides the values its range produces and how a sampled range draws them.
const ( // SweepIntegers produces Integers however the endpoints are written, and // refuses an endpoint or step that is not one. SweepIntegers SweepNumbers // SweepReals produces reals however the endpoints are written. SweepReals )
type SweepPlan ¶
type SweepPlan struct {
Ranges []SweepRange
Sampled bool
Samples int64
Seed uint64
Runs int64
// MonteCarlo marks a plan made by MonteCarloPlan, whatever number of runs it asks for.
MonteCarlo bool
// Seedless marks a Monte Carlo whose runs derive no model seed: made by SeedlessMonteCarloPlan.
Seedless bool
}
SweepPlan is what a sweep asks for: the ranges its parameters take, for a sampled sweep the number of draws and the seed they are drawn from, and for a Monte Carlo the number of runs, each seeded by RunSeed of Seed, and no range.
func MonteCarloPlan ¶
MonteCarloPlan is the plan of runs runs seeded from seed: one row per run and no ranges.
func ResolvePlan ¶
func ResolvePlan(ctx *runtime.Context, sym *symbols.Symbol, plan SweepPlan, positional int, named []string) (SweepPlan, error)
ResolvePlan refuses a range over a parameter the target does not declare, its subject or one the invocation binds, and types each range by its parameter.
func SeedlessMonteCarloPlan ¶
SeedlessMonteCarloPlan is the plan of runs runs seeded from nothing: a fixed draw policy resolves every RandomFunctions call, and a weighted decision is an unseeded draw.
func (SweepPlan) Drawn ¶
Drawn reports whether the plan's rows come from Seed: a sampled sweep or a seeded Monte Carlo; a swept table steps its ranges, a seedless Monte Carlo derives no seed.
func (SweepPlan) IsMonteCarlo ¶
IsMonteCarlo reports whether the plan runs one behavior repeatedly: made by MonteCarloPlan, or stating runs.
type SweepRange ¶
type SweepRange struct {
Param string
From runtime.Value
To runtime.Value
Step runtime.Value
HasStep bool
Type SweepType
}
SweepRange is one parameter's range as values: its endpoints, the step a sampled range leaves unstated, and the type ResolveSweepPlan produces them in.
type SweepRow ¶
type SweepRow struct {
Bindings []SweepBinding
Outputs []runtime.CalcOutputValue
Verdicts []runtime.AnalysisVerdict
// The object this run's verdicts are about, where a case ran on one.
Subject *runtime.Instance
Evaluations []runtime.AnalysisEvaluation
Inputs []runtime.InputBinding
Elapsed time.Duration
Err error
// Context is the context the run was made in, which its outputs, subject and
// evaluations are read through: no other context knows the objects they name.
// It is nil for a run that released it (SweepRunResult.ReleaseContext).
Context *runtime.Context
// Trace is what the run recorded, nil when nothing was; a row keeps it
// whether or not it keeps its context.
Trace *runtime.TraceRecorder
}
SweepRow is one run of a sweep: what it was given, what it produced, how long it took, and what stopped it when it failed.
type SweepRun ¶
type SweepRun func(ctx *runtime.Context, bindings []SweepBinding) (SweepRunResult, error)
SweepRun makes one run of a sweep in ctx, the row's own context, with the parameters bound as the row states. An error is that row's failure, not the table's; what the run produced before failing may be returned beside it.
type SweepRunResult ¶
type SweepRunResult struct {
Outputs []runtime.CalcOutputValue
Verdicts []runtime.AnalysisVerdict
// Inputs are the values the run bound the case's input parameters to, in
// declaration order, the row's own binding included.
Inputs []runtime.InputBinding
// The object the run was about, where a case ran on one.
Subject *runtime.Instance
// Evaluations are the applications the run made of a calc held as a value,
// in the order made.
Evaluations []runtime.AnalysisEvaluation
// ReleaseContext marks a run whose outputs read without the context that made
// them: the row keeps the trace and lets the context, and the run's objects, go.
ReleaseContext bool
}
SweepRunResult is what one run of a sweep produced. A calc's returned value is reported as an output named "result", so a calc row and a case row read alike.
type SweepTable ¶
type SweepTable struct {
Target string
Params []string
// Types are the parameters' types as the plan resolved them, one per Param.
Types []SweepType
Sampled bool
Seed uint64
Runs int64
// Seedless marks a Monte Carlo whose runs derived no model seed from Seed.
Seedless bool
Rows []SweepRow
}
SweepTable is every run of one sweep, in the order they were made: a swept table runs lexicographically over its parameters in the order they were given, each from its first endpoint; a sampled table runs in draw order; a Monte Carlo in run order, its one parameter the run's number.
func NewSweepTable ¶
func NewSweepTable(target string, plan SweepPlan) SweepTable
NewSweepTable is the table of a plan before any row is run: the target, the parameters and their types in plan order, and how the rows are drawn.
func RunSweepWith ¶
func RunSweepWith(stop context.Context, workers SweepWorkers, target string, plan SweepPlan, runs int64, run SweepRun) (SweepTable, error)
RunSweepWith makes one run per row of the plan on the workers and reports the table in plan order whatever order the rows finish in; the table does not depend on the jobs. A run that failed is that row's typed error; the table is completed either way. A plan of more rows than runs allows (First's SweepRunBudget when runs is zero) is refused before any run is made. A caller that goes away starts no further row and takes the table with it: the rows in flight finish and are discarded, and the caller's error is the sweep's, as it is when one job meets it between two rows.
type SweepType ¶
type SweepType struct {
Numbers SweepNumbers
// Untyped reports a parameter declaring no type, whose range is read as written.
Untyped bool
// Positive excludes zero, which no scalar type's numbers alone rule out.
Positive bool
// contains filtered or unexported fields
}
SweepType is a swept parameter's declared type, which its range's values are produced in and each endpoint is admitted to as an argument is.
type SweepWorkers ¶
type SweepWorkers struct {
First *runtime.Context
Jobs int
Fresh func(job int) (*runtime.Context, error)
}
SweepWorkers is who makes a sweep's rows: up to Jobs going concurrently, each row in a context of its own — First for the first row, the one the rows are enumerated in, and Fresh building every other for the job making it.