Skip to content

Commit

Permalink
Merge pull request #246 from c-bata/fix-data-race-tpe
Browse files Browse the repository at this point in the history
Fix a concurrency issue in TPESampler
  • Loading branch information
c-bata authored Sep 8, 2023
2 parents 1752dd1 + e0f551c commit fb7e528
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions tpe/sampler.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,9 @@ func getObservationPairs(study *goptuna.Study, paramName string) ([]float64, [][
values := make([]float64, 0, len(trials))
scores := make([][2]float64, 0, len(trials))
for _, trial := range trials {
if trial.State != goptuna.TrialStateComplete && trial.State != goptuna.TrialStatePruned {
continue
}
ir, ok := trial.InternalParams[paramName]
if !ok {
continue
Expand All @@ -552,7 +555,7 @@ func getObservationPairs(study *goptuna.Study, paramName string) ([]float64, [][
if trial.State == goptuna.TrialStateComplete {
score0 = math.Inf(-1)
score1 = sign * trial.Value
} else if trial.State == goptuna.TrialStatePruned {
} else {
if len(trial.IntermediateValues) > 0 {
var step int
var intermediateValue float64
Expand All @@ -569,8 +572,6 @@ func getObservationPairs(study *goptuna.Study, paramName string) ([]float64, [][
score0 = math.Inf(1)
score1 = 0.0
}
} else {
continue
}
values = append(values, paramValue)
scores = append(scores, [2]float64{score0, score1})
Expand Down

0 comments on commit fb7e528

Please sign in to comment.