Commit 8e93c048 authored by Alfredo Di Napoli's avatar Alfredo Di Napoli

Add bench for toPyhlo

parent 7ab4eb24
Pipeline #5449 passed with stages
in 286 minutes and 38 seconds
This diff is collapsed.
...@@ -2,18 +2,54 @@ ...@@ -2,18 +2,54 @@
{-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeApplications #-}
module Main where module Main where
import Control.DeepSeq
import Gargantext.Core.Types.Individu import Gargantext.Core.Types.Individu
import Gargantext.Core.Types.Phylo
import Gargantext.Core.Viz.Phylo
import Gargantext.Core.Viz.Phylo.API.Tools (readPhylo)
import Gargantext.Core.Viz.Phylo.PhyloMaker (toPhylo)
import Gargantext.Core.Viz.Phylo.PhyloTools
import Gargantext.Prelude.Crypto.Auth (createPasswordHash) import Gargantext.Prelude.Crypto.Auth (createPasswordHash)
import Test.Tasty.Bench import Test.Tasty.Bench
import Paths_gargantext
phyloConfig :: PhyloConfig
phyloConfig = PhyloConfig {
corpusPath = "corpus.csv"
, listPath = "list.csv"
, outputPath = "data/"
, corpusParser = Csv {_csv_limit = 150000}
, listParser = V4
, phyloName = "Phylo Name"
, phyloScale = 2
, similarity = WeightedLogJaccard {_wlj_sensibility = 0.5, _wlj_minSharedNgrams = 2}
, seaElevation = Constante {_cons_start = 0.1, _cons_gap = 0.1}
, defaultMode = True
, findAncestors = True
, phyloSynchrony = ByProximityThreshold {_bpt_threshold = 0.5, _bpt_sensibility = 0.0, _bpt_scope = AllBranches, _bpt_strategy = MergeAllGroups}
, phyloQuality = Quality {_qua_granularity = 0.8, _qua_minBranch = 3}
, timeUnit = Year {_year_period = 3, _year_step = 1, _year_matchingFrame = 5}
, clique = MaxClique {_mcl_size = 5, _mcl_threshold = 1.0e-4, _mcl_filter = ByThreshold}
, exportLabel = [ BranchLabel {_branch_labelTagger = MostEmergentTfIdf, _branch_labelSize = 2}
, GroupLabel {_group_labelTagger = MostEmergentInclusive, _group_labelSize = 2}
]
, exportSort = ByHierarchy {_sort_order = Desc}
, exportFilter = [ByBranchSize {_branch_size = 3.0}]
}
main :: IO () main :: IO ()
main = defaultMain main = do
[ bgroup "Benchmarks" issue290Phylo <- force . setConfig phyloConfig <$> (readPhylo =<< getDataFileName "bench-data/phylo/issue-290.json")
[ bgroup "User creation" [ defaultMain
bench "createPasswordHash" $ whnfIO (createPasswordHash "rabbit") [ bgroup "Benchmarks"
, bench "toUserHash" $ [ bgroup "User creation" [
whnfIO (toUserHash $ NewUser "alfredo" "alfredo@well-typed.com" (GargPassword "rabbit")) bench "createPasswordHash" $ whnfIO (createPasswordHash "rabbit")
] , bench "toUserHash" $
whnfIO (toUserHash $ NewUser "alfredo" "alfredo@well-typed.com" (GargPassword "rabbit"))
]
, bgroup "Phylo" [
bench "toPhylo" $ nf toPhylo issue290Phylo
]
]
] ]
]
...@@ -17,6 +17,7 @@ license: AGPL-3 ...@@ -17,6 +17,7 @@ license: AGPL-3
license-file: LICENSE license-file: LICENSE
build-type: Simple build-type: Simple
data-files: data-files:
bench-data/phylo/issue-290.json
devops/postgres/extensions.sql devops/postgres/extensions.sql
devops/postgres/schema.sql devops/postgres/schema.sql
ekg-assets/index.html ekg-assets/index.html
...@@ -1157,6 +1158,7 @@ benchmark garg-bench ...@@ -1157,6 +1158,7 @@ benchmark garg-bench
type: exitcode-stdio-1.0 type: exitcode-stdio-1.0
build-depends: base build-depends: base
, bytestring , bytestring
, deepseq
, gargantext , gargantext
, gargantext-prelude , gargantext-prelude
, tasty-bench , tasty-bench
......
...@@ -26,6 +26,7 @@ Phylomemy was first described in Chavalarias, D., Cointet, J.-P., 2013. Phylomem ...@@ -26,6 +26,7 @@ Phylomemy was first described in Chavalarias, D., Cointet, J.-P., 2013. Phylomem
module Gargantext.Core.Types.Phylo where module Gargantext.Core.Types.Phylo where
import Control.DeepSeq
import Control.Lens (makeLenses) import Control.Lens (makeLenses)
import Control.Monad.Fail (fail) import Control.Monad.Fail (fail)
import Data.Aeson import Data.Aeson
...@@ -51,6 +52,8 @@ data Phylo = Phylo { _phylo_Duration :: (Start, End) ...@@ -51,6 +52,8 @@ data Phylo = Phylo { _phylo_Duration :: (Start, End)
, _phylo_Periods :: [PhyloPeriod] , _phylo_Periods :: [PhyloPeriod]
} deriving (Generic) } deriving (Generic)
instance NFData Phylo
-- | UTCTime in seconds since UNIX epoch -- | UTCTime in seconds since UNIX epoch
type Start = POSIXTime type Start = POSIXTime
type End = POSIXTime type End = POSIXTime
...@@ -66,6 +69,8 @@ data PhyloPeriod = PhyloPeriod { _phylo_PeriodId :: PhyloPeriodId ...@@ -66,6 +69,8 @@ data PhyloPeriod = PhyloPeriod { _phylo_PeriodId :: PhyloPeriodId
, _phylo_PeriodLevels :: [PhyloLevel] , _phylo_PeriodLevels :: [PhyloLevel]
} deriving (Generic) } deriving (Generic)
instance NFData PhyloPeriod
type PhyloPeriodId = (Start, End) type PhyloPeriodId = (Start, End)
-- | PhyloLevel : levels of phylomemy on level axis -- | PhyloLevel : levels of phylomemy on level axis
...@@ -78,6 +83,8 @@ data PhyloLevel = PhyloLevel { _phylo_LevelId :: PhyloLevelId ...@@ -78,6 +83,8 @@ data PhyloLevel = PhyloLevel { _phylo_LevelId :: PhyloLevelId
, _phylo_LevelGroups :: [PhyloGroup] , _phylo_LevelGroups :: [PhyloGroup]
} deriving (Generic) } deriving (Generic)
instance NFData PhyloLevel
type PhyloLevelId = (PhyloPeriodId, Int) type PhyloLevelId = (PhyloPeriodId, Int)
-- | PhyloGroup : group of ngrams at each level and step -- | PhyloGroup : group of ngrams at each level and step
...@@ -88,14 +95,16 @@ type PhyloLevelId = (PhyloPeriodId, Int) ...@@ -88,14 +95,16 @@ type PhyloLevelId = (PhyloPeriodId, Int)
data PhyloGroup = PhyloGroup { _phylo_GroupId :: PhyloGroupId data PhyloGroup = PhyloGroup { _phylo_GroupId :: PhyloGroupId
, _phylo_GroupLabel :: Maybe Text , _phylo_GroupLabel :: Maybe Text
, _phylo_GroupNgrams :: [NgramId] , _phylo_GroupNgrams :: [NgramId]
, _phylo_GroupPeriodParents :: [Edge] , _phylo_GroupPeriodParents :: [Edge]
, _phylo_GroupPeriodChilds :: [Edge] , _phylo_GroupPeriodChilds :: [Edge]
, _phylo_GroupLevelParents :: [Edge] , _phylo_GroupLevelParents :: [Edge]
, _phylo_GroupLevelChilds :: [Edge] , _phylo_GroupLevelChilds :: [Edge]
} deriving (Generic) } deriving (Generic)
instance NFData PhyloGroup
type PhyloGroupId = (PhyloLevelId, Int) type PhyloGroupId = (PhyloLevelId, Int)
type Edge = (PhyloGroupId, Weight) type Edge = (PhyloGroupId, Weight)
type Weight = Double type Weight = Double
......
...@@ -26,6 +26,7 @@ one 8, e54847. ...@@ -26,6 +26,7 @@ one 8, e54847.
module Gargantext.Core.Viz.Phylo where module Gargantext.Core.Viz.Phylo where
import Control.DeepSeq
import Control.Lens (makeLenses) import Control.Lens (makeLenses)
import Data.Aeson import Data.Aeson
import Data.Aeson.TH (deriveJSON) import Data.Aeson.TH (deriveJSON)
...@@ -62,7 +63,7 @@ data SeaElevation = ...@@ -62,7 +63,7 @@ data SeaElevation =
| Adaptative | Adaptative
{ _adap_steps :: Double } { _adap_steps :: Double }
| Evolving | Evolving
{ _evol_neighborhood :: Bool } { _evol_neighborhood :: Bool }
deriving (Show,Generic,Eq) deriving (Show,Generic,Eq)
instance ToSchema SeaElevation instance ToSchema SeaElevation
...@@ -74,8 +75,8 @@ data PhyloSimilarity = ...@@ -74,8 +75,8 @@ data PhyloSimilarity =
| WeightedLogSim | WeightedLogSim
{ _wls_sensibility :: Double { _wls_sensibility :: Double
, _wls_minSharedNgrams :: Int } , _wls_minSharedNgrams :: Int }
| Hamming | Hamming
{ _hmg_sensibility :: Double { _hmg_sensibility :: Double
, _hmg_minSharedNgrams :: Int} , _hmg_minSharedNgrams :: Int}
deriving (Show,Generic,Eq) deriving (Show,Generic,Eq)
...@@ -188,7 +189,6 @@ data PhyloConfig = ...@@ -188,7 +189,6 @@ data PhyloConfig =
, exportFilter :: [Filter] , exportFilter :: [Filter]
} deriving (Show,Generic,Eq) } deriving (Show,Generic,Eq)
-------------------------------- --------------------------------
-- | SubConfig API & 1Click | -- -- | SubConfig API & 1Click | --
-------------------------------- --------------------------------
...@@ -205,8 +205,8 @@ data PhyloSubConfigAPI = ...@@ -205,8 +205,8 @@ data PhyloSubConfigAPI =
subConfigAPI2config :: PhyloSubConfigAPI -> PhyloConfig subConfigAPI2config :: PhyloSubConfigAPI -> PhyloConfig
subConfigAPI2config subConfig = defaultConfig subConfigAPI2config subConfig = defaultConfig
{ similarity = WeightedLogJaccard (_sc_phyloProximity subConfig) 2 { similarity = WeightedLogJaccard (_sc_phyloProximity subConfig) 2
, phyloSynchrony = ByProximityThreshold (_sc_phyloSynchrony subConfig) 0 AllBranches MergeAllGroups , phyloSynchrony = ByProximityThreshold (_sc_phyloSynchrony subConfig) 0 AllBranches MergeAllGroups
, phyloQuality = Quality (_sc_phyloQuality subConfig) 3 , phyloQuality = Quality (_sc_phyloQuality subConfig) 3
, timeUnit = _sc_timeUnit subConfig , timeUnit = _sc_timeUnit subConfig
...@@ -217,7 +217,7 @@ subConfigAPI2config subConfig = defaultConfig ...@@ -217,7 +217,7 @@ subConfigAPI2config subConfig = defaultConfig
-------------------------- --------------------------
-- | SubConfig 1Click | -- -- | SubConfig 1Click | --
-------------------------- --------------------------
defaultConfig :: PhyloConfig defaultConfig :: PhyloConfig
defaultConfig = defaultConfig =
...@@ -474,7 +474,6 @@ data PhyloScale = ...@@ -474,7 +474,6 @@ data PhyloScale =
instance ToSchema PhyloScale where instance ToSchema PhyloScale where
declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_phylo_") declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_phylo_")
type PhyloGroupId = (PhyloScaleId, Int) type PhyloGroupId = (PhyloScaleId, Int)
-- | BranchId : (a scale, a sequence of branch index) -- | BranchId : (a scale, a sequence of branch index)
...@@ -552,19 +551,16 @@ data Filter = ByBranchSize { _branch_size :: Double } deriving (Show,Generic,Eq) ...@@ -552,19 +551,16 @@ data Filter = ByBranchSize { _branch_size :: Double } deriving (Show,Generic,Eq)
instance ToSchema Filter where instance ToSchema Filter where
declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "") declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "")
data Order = Asc | Desc deriving (Show,Generic,Eq, ToSchema) data Order = Asc | Desc deriving (Show,Generic,Eq, ToSchema)
data Sort = ByBirthDate { _sort_order :: Order } | ByHierarchy {_sort_order :: Order } deriving (Show,Generic,Eq) data Sort = ByBirthDate { _sort_order :: Order } | ByHierarchy {_sort_order :: Order } deriving (Show,Generic,Eq)
instance ToSchema Sort where instance ToSchema Sort where
declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_sort_") declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_sort_")
data Tagger = MostInclusive | MostEmergentInclusive | MostEmergentTfIdf deriving (Show,Generic,Eq) data Tagger = MostInclusive | MostEmergentInclusive | MostEmergentTfIdf deriving (Show,Generic,Eq)
instance ToSchema Tagger where instance ToSchema Tagger where
declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "") declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "")
data PhyloLabel = data PhyloLabel =
BranchLabel BranchLabel
{ _branch_labelTagger :: Tagger { _branch_labelTagger :: Tagger
...@@ -654,3 +650,30 @@ instance FromJSON PhyloGroup ...@@ -654,3 +650,30 @@ instance FromJSON PhyloGroup
instance ToJSON PhyloGroup instance ToJSON PhyloGroup
$(deriveJSON (unPrefix "_foundations_" ) ''PhyloFoundations) $(deriveJSON (unPrefix "_foundations_" ) ''PhyloFoundations)
-- NFData instances
instance NFData CorpusParser
instance NFData ListParser
instance NFData SeaElevation
instance NFData PhyloSimilarity
instance NFData SynchronyScope
instance NFData SynchronyStrategy
instance NFData Synchrony
instance NFData MaxCliqueFilter
instance NFData Cluster
instance NFData Quality
instance NFData PhyloConfig
instance NFData Software
instance NFData PhyloParam
instance NFData PhyloFoundations
instance NFData PhyloCounts
instance NFData PhyloSources
instance NFData Phylo
instance NFData PhyloPeriod
instance NFData PhyloScale
instance NFData Filter
instance NFData Order
instance NFData Sort
instance NFData Tagger
instance NFData PhyloLabel
...@@ -19,7 +19,7 @@ module Gargantext.Core.Viz.Phylo.API.Tools ...@@ -19,7 +19,7 @@ module Gargantext.Core.Viz.Phylo.API.Tools
where where
import Control.Lens hiding (Context) import Control.Lens hiding (Context)
import Data.Aeson (Value, decodeFileStrict, eitherDecode, encode) import Data.Aeson (Value, decodeFileStrict, encode, eitherDecodeFileStrict')
import Data.ByteString.Lazy qualified as Lazy import Data.ByteString.Lazy qualified as Lazy
import Data.Map.Strict qualified as Map import Data.Map.Strict qualified as Map
import Data.Proxy import Data.Proxy
...@@ -54,6 +54,7 @@ import Prelude qualified ...@@ -54,6 +54,7 @@ import Prelude qualified
import System.FilePath ((</>)) import System.FilePath ((</>))
import System.IO.Temp (withTempDirectory) import System.IO.Temp (withTempDirectory)
import System.Process qualified as Shell import System.Process qualified as Shell
import Gargantext.Utils.UTCTime (timeMeasured)
-------------------------------------------------------------------- --------------------------------------------------------------------
getPhyloData :: HasNodeError err getPhyloData :: HasNodeError err
...@@ -99,7 +100,12 @@ flowPhyloAPI config cId = do ...@@ -99,7 +100,12 @@ flowPhyloAPI config cId = do
-- writePhylo phyloWithCliquesFile phyloWithCliques -- writePhylo phyloWithCliquesFile phyloWithCliques
$(logLocM) DEBUG $ "PhyloConfig old: " <> show config $(logLocM) DEBUG $ "PhyloConfig old: " <> show config
pure $! toPhylo $! setConfig config phyloWithCliques _ <- timeMeasured "flowPhyloAPI.phyloWithCliques" (pure $! phyloWithCliques)
let !phyloConfigured = setConfig config phyloWithCliques
_ <- timeMeasured "flowPhyloAPI.phyloConfigured" (pure $! phyloConfigured)
pure $! toPhylo phyloConfigured
-------------------------------------------------------------------- --------------------------------------------------------------------
corpusIdtoDocuments :: (HasNodeStory env err m, HasNodeError err) corpusIdtoDocuments :: (HasNodeStory env err m, HasNodeError err)
...@@ -195,13 +201,8 @@ writePhylo path phylo = Lazy.writeFile path $ encode phylo ...@@ -195,13 +201,8 @@ writePhylo path phylo = Lazy.writeFile path $ encode phylo
readPhylo :: [Char] -> IO Phylo readPhylo :: [Char] -> IO Phylo
readPhylo path = do readPhylo path = do
phyloJson <- (eitherDecode <$> readJson path) :: IO (Either Prelude.String Phylo) phyloJson <- eitherDecodeFileStrict' @Phylo path
case phyloJson of either errorTrace pure phyloJson
Left err -> do
putStrLn err
undefined
Right phylo -> pure phylo
-- | To read and decode a Json file -- | To read and decode a Json file
readJson :: FilePath -> IO Lazy.ByteString readJson :: FilePath -> IO Lazy.ByteString
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment