Merge pull request #850 from COLDTURNIP/feature/optimizer_predict_grid_number

optimizer: calculate total number of grids before testing
This commit is contained in:
Yo-An Lin 2022-07-28 18:54:21 +08:00 committed by GitHub
commit a32ef8ca9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -195,10 +195,7 @@ func (o *GridOptimizer) Run(executor Executor, configJson []byte) (map[string][]
var taskC = make(chan BacktestTask, 10000)
var bar = pb.Full.New(cap(taskC))
bar.SetTemplateString(`{{ string . "log" | green}} | {{counters . }} {{bar . }} {{percent . }} {{etime . }} {{rtime . "ETA %s"}}`)
var taskCnt int64 = 0
var taskCnt = 0
var app = func(configJson []byte, next func(configJson []byte) error) error {
var labels = copyLabels(o.ParamLabels)
var params = copyParams(o.CurrentParams)
@ -207,8 +204,10 @@ func (o *GridOptimizer) Run(executor Executor, configJson []byte) (map[string][]
Params: params,
Labels: labels,
}
return nil
}
var appCnt = func(configJson []byte, next func(configJson []byte) error) error {
taskCnt++
bar.SetTotal(taskCnt)
return nil
}
@ -217,15 +216,28 @@ func (o *GridOptimizer) Run(executor Executor, configJson []byte) (map[string][]
var wrapper = func(configJson []byte) error {
return app(configJson, nil)
}
var wrapperCnt = func(configJson []byte) error {
return appCnt(configJson, nil)
}
for i := len(ops) - 1; i >= 0; i-- {
cur := ops[i]
inner := wrapper
innerCnt := wrapperCnt
wrapper = func(configJson []byte) error {
return cur(configJson, inner)
}
wrapperCnt = func(configJson []byte) error {
return cur(configJson, innerCnt)
}
}
if err := wrapperCnt(configJson); err != nil {
return nil, err
}
var bar = pb.Full.New(taskCnt)
bar.SetTemplateString(`{{ string . "log" | green}} | {{counters . }} {{bar . }} {{percent . }} {{etime . }} {{rtime . "ETA %s"}}`)
ctx := context.Background()
var taskGenErr error
go func() {