ryukzak / nitta

BSD 3-Clause "New" or "Revised" License
21 stars 6 forks source link

Ml for synthesis prototype - Refactoring #260

Closed ryukzak closed 9 months ago

ryukzak commented 9 months ago

To: https://github.com/ryukzak/nitta/pull/167/files

Changes overview:

TODOs:

subForestIO
    BackendCtx{nodeScores, mlBackendGetter}
    tree@Tree{sSubForestVar} = do
        (firstTime, subForest) <-
            atomically $
                tryReadTMVar sSubForestVar >>= \case
                    Just subForest -> return (False, subForest)
                    Nothing -> do
                        subForest <- exploreSubForestVar tree
                        putTMVar sSubForestVar subForest
                        return (True, subForest)

        when firstTime $ traceProcessedNode tree

        -- FIXME: ML scores are evaluated here every time subForestIO is called. how to cache it like the default score? IO in STM isn't possible.
        -- also it looks inelegant, is there a way to refactor it?
        let modelNames = mapMaybe (T.stripPrefix mlScoreKeyPrefix) nodeScores
        if
            | null subForest -> return subForest
            | null nodeScores -> return subForest
            | null modelNames -> return subForest
            | otherwise -> do
                MlBackendServer{baseUrl} <- mlBackendGetter
                case baseUrl of
                    Nothing -> return subForest
                    Just mlBackendBaseUrl -> do
                        -- (addMlScoreToSubforestSkipErrorsIO subForestAccum modelName) gets called for each modelName
                        foldM (addMlScoreToSubforestSkipErrorsIO mlBackendBaseUrl) subForest modelNames