optimizer: eliminate limitation of number of grid point

This commit is contained in:
Raphanus Lo 2022-07-15 22:32:07 +08:00
parent 44f3793db8
commit 620381f64b

View File

@ -195,6 +195,10 @@ func (o *GridOptimizer) Run(executor Executor, configJson []byte) (map[string][]
var taskC = make(chan BacktestTask, 10000) 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 app = func(configJson []byte, next func(configJson []byte) error) error { var app = func(configJson []byte, next func(configJson []byte) error) error {
var labels = copyLabels(o.ParamLabels) var labels = copyLabels(o.ParamLabels)
var params = copyParams(o.CurrentParams) var params = copyParams(o.CurrentParams)
@ -203,6 +207,8 @@ func (o *GridOptimizer) Run(executor Executor, configJson []byte) (map[string][]
Params: params, Params: params,
Labels: labels, Labels: labels,
} }
taskCnt++
bar.SetTotal(taskCnt)
return nil return nil
} }
@ -221,20 +227,17 @@ func (o *GridOptimizer) Run(executor Executor, configJson []byte) (map[string][]
} }
ctx := context.Background() ctx := context.Background()
if err := wrapper(configJson); err != nil { var taskGenErr error
return nil, err go func() {
} taskGenErr = wrapper(configJson)
close(taskC) // this will shut down the executor
bar := pb.Full.Start(len(taskC)) }()
bar.SetTemplateString(`{{ string . "log" | green}} | {{counters . }} {{bar . }} {{percent . }} {{etime . }} {{rtime . "ETA %s"}}`)
resultsC, err := executor.Run(ctx, taskC, bar) resultsC, err := executor.Run(ctx, taskC, bar)
if err != nil { if err != nil {
return nil, err return nil, err
} }
close(taskC) // this will shut down the executor
for result := range resultsC { for result := range resultsC {
bar.Increment() bar.Increment()
@ -265,7 +268,11 @@ func (o *GridOptimizer) Run(executor Executor, configJson []byte) (map[string][]
}) })
} }
return metrics, err if taskGenErr != nil {
return metrics, taskGenErr
} else {
return metrics, err
}
} }
func reformatJson(text string) string { func reformatJson(text string) string {