Documentation
¶
Overview ¶
Package optblock holds the ONE rule set for a ComposedRequest `optimize` block (types.OptimizeSpec) short of solving it: the structural checks, the variable bounds resolved against the batch params, the objective and constraint compile against the block's environment, and the effective seed of its Latin-hypercube starts. Predict (internal/descriptor) and the runtime (internal/service) both call Check on the same block before any fit or slot runs, so the two refuse the same block with the same code, message and details; the runtime then solves what Compile returns.
The environment an objective or constraint reads:
- every decision variable, a float64 identifier bound per iterate (never a params constant: params fold at compile, a variable must change between evaluations);
- the batch params as params.<name> (exprenv.Bound.Params, folded);
- coef(fit, term[, stat]) over the batch's `fits` — every all-literal call judged statically by model.CheckCoef;
- the expression built-ins (hill(), exp(), …), the embedder's ExprFunctions and, with a registered LookupTable, lookup().
No record field is in reach. A bound or start is a number or a params reference, resolved here.
No-execute leaf: it imports types, errors and the no-execute expression and model leaves only, never the engine (TestOptBlock_ImportBoundary).
Index ¶
Constants ¶
const ( ReasonNameMissing = "name_missing" ReasonNameDuplicate = "name_duplicate" ReasonVariablesMissing = "variables_missing" ReasonObjectiveMissing = "objective_missing" ReasonDirectionMissing = "direction_missing" ReasonDirectionUnknown = "direction_unknown" ReasonConstraintExprMissing = "constraint_expr_missing" ReasonConstraintTypeUnknown = "constraint_type_unknown" ReasonTooManyEqualities = "too_many_equalities" ReasonStartsInvalid = "starts_invalid" ReasonToleranceInvalid = "tolerance_invalid" ReasonMaxIterationsInvalid = "max_iterations_invalid" )
The PULSE_OPTIMIZE_SPEC_INVALID reasons.
const ( ReasonNameInvalid = "name_invalid" ReasonNameReserved = "name_reserved" ReasonBoundMissing = "bound_missing" ReasonBoundInvalid = "bound_invalid" ReasonBoundNotNumeric = "bound_not_numeric" ReasonBoundsCrossed = "bounds_crossed" ReasonStartOutOfBounds = "start_out_of_bounds" ReasonUnknownIdentifier = "unknown_identifier" ReasonCompileError = "compile_error" ReasonNotNumeric = "not_numeric" )
The PULSE_OPTIMIZE_VARIABLE_INVALID reasons (name_missing and name_duplicate are shared with the block's).
Variables ¶
This section is empty.
Functions ¶
func Check ¶
func Check(specs []types.OptimizeSpec, env Env) *errors.CodedError
Check judges every block in order and returns the first refusal (nil when every block passes): Compile against env with every request-bound function declared but never run.
func CheckLoaded ¶
func CheckLoaded(specs []types.OptimizeSpec, env Env) ([]*model.Loaded, *errors.CodedError)
CheckLoaded is Check that also returns each block's decoded `models` files, index-aligned with specs (nil where a block loads none; nil throughout on a refusal) — what Env.Loaded hands a later Compile.
func EffectiveSeed ¶
func EffectiveSeed(spec *types.OptimizeSpec) int64
EffectiveSeed is the seed a block's Latin-hypercube starts are drawn with: spec.RNGSeed when non-zero, else regresample.DeriveSeed — the one rng_seed 0 derivation every seeded draw shares — over the block's wire form with rng_seed excluded (never the clock). It reads the spec only; predict and the runtime report the same seed.
Types ¶
type Compiled ¶
type Compiled struct {
Names []string
Lower, Upper []float64
Start []float64
Objective *vm.Program
Constraints []*vm.Program
// Refs and Loaded are the block's `models` entries and their
// decoded files (zero / nil when it loads none): the runtime binds
// them above the batch's fits for coef().
Refs model.Refs
Loaded *model.Loaded
}
Compiled is one block ready to solve: the variables in block order with their resolved bounds and start (NaN where the block sets none), and the objective and constraints compiled once. Evaluate a program with expr.Run(prog, Compiled.Vars(x)).
func Compile ¶
func Compile(spec *types.OptimizeSpec, i int, env Env, bound exprenv.Bound) (*Compiled, *errors.CodedError)
Compile is one block's rules in order — its structure, then each variable (name, bounds, start), then the objective and each constraint (params, identifiers, compile, result type, coef()) — and on success the block ready to solve. i is the block's index (every refusal's details.optimize); bound carries the request-bound implementations (its Params are replaced by env.Params): predict's Check passes placeholders, the runtime its bound models. The block name list rule (missing / duplicate names) is Check's.
type Env ¶
type Env struct {
// Params are the batch's normalized params (the ComposedRequest's
// top-level `params` through exprenv.NormalizeParams).
Params exprenv.Params
// Fits are the names coef() resolves: the batch's `fits`
// (model.CatalogFromFits).
Fits model.Catalog
// Extensions are the embedder's ExprFunction names; Lookup reports a
// registered LookupTable (lookup() is declared).
Extensions []string
Lookup bool
// Outer is the namespace a block's `models` entry may not rebind:
// the instance's registered populations and the batch's fits
// (model.WithinCatalog). Nil checks the entries against each other
// only.
Outer model.Catalog
// Load reads and decodes a block's `models` files (model.LoadFiles
// plus the instance's loaded-type checks): predict's and the
// runtime's loaders run the same rules. Nil refuses any file as
// unreadable.
Load Loader
// Loaded, when set, are the files an earlier Check already read,
// index-aligned with the blocks (nil where a block loads none):
// Compile reuses them instead of reading again, so the runtime
// solves exactly what it validated.
Loaded []*model.Loaded
}
Env is what a block's expressions may call beyond the decision variables and the expr-lang built-ins.