From 2a6418eb4afc4223781146a3af8de0b1155e4430 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20B=C3=A4renz?= Date: Wed, 8 Feb 2023 14:32:15 +0100 Subject: [PATCH 1/5] Fix typo --- .github/workflows/nix.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml index 4ac4a7f5..b9c399d6 100644 --- a/.github/workflows/nix.yml +++ b/.github/workflows/nix.yml @@ -38,5 +38,5 @@ jobs: CACHIX_AUTH_TOKEN: ${{ secrets.CACHIX_AUTH_TOKEN }} - name: Build run: nix --print-build-logs build .#packages.${{ matrix.system }}.monad-bayes - - name: Development environenment + - name: Development environment run: nix --print-build-logs develop .#packages.${{ matrix.system }}.monad-bayes --command echo Ready From cacfbf8568ddab9799acc1bb061c16c8ea21a1d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20B=C3=A4renz?= Date: Wed, 8 Feb 2023 14:32:47 +0100 Subject: [PATCH 2/5] Error on warnings in dev mode & on CI --- flake.nix | 2 +- monad-bayes.cabal | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/flake.nix b/flake.nix index 1e7bdb37..1e203b0f 100644 --- a/flake.nix +++ b/flake.nix @@ -85,7 +85,7 @@ }; }; - cabal2nixOptions = "--benchmark"; + cabal2nixOptions = "--benchmark -fdev"; }; jupyterEnvironment = mkJupyterlabFromPath ./kernels {inherit pkgs monad-bayes;}; diff --git a/monad-bayes.cabal b/monad-bayes.cabal index d7147ab6..ce735816 100644 --- a/monad-bayes.cabal +++ b/monad-bayes.cabal @@ -102,7 +102,7 @@ library if flag(dev) ghc-options: - -Wall -Wno-missing-local-signatures -Wno-trustworthy-safe + -Wall -Werror -Wno-missing-local-signatures -Wno-trustworthy-safe -Wno-missing-import-lists -Wno-implicit-prelude -Wno-monomorphism-restriction @@ -136,7 +136,7 @@ executable example if flag(dev) ghc-options: - -Wall -Wcompat -Wincomplete-record-updates + -Wall -Werror -Wcompat -Wincomplete-record-updates -Wincomplete-uni-patterns -Wnoncanonical-monad-instances else @@ -198,7 +198,7 @@ test-suite monad-bayes-test if flag(dev) ghc-options: - -Wall -Wno-missing-local-signatures -Wno-unsafe + -Wall -Werror -Wno-missing-local-signatures -Wno-unsafe -Wno-missing-import-lists -Wno-implicit-prelude else @@ -252,7 +252,7 @@ benchmark speed-bench if flag(dev) ghc-options: - -Wall -Wno-missing-local-signatures -Wno-unsafe + -Wall -Werror -Wno-missing-local-signatures -Wno-unsafe -Wno-missing-import-lists -Wno-implicit-prelude else From 80de2358f9a3d64faecbf100e7a3ebbd18c18e3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20B=C3=A4renz?= Date: Wed, 8 Feb 2023 15:50:58 +0100 Subject: [PATCH 3/5] Activate redundant constraints warning --- monad-bayes.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monad-bayes.cabal b/monad-bayes.cabal index ce735816..1b20eea9 100644 --- a/monad-bayes.cabal +++ b/monad-bayes.cabal @@ -104,7 +104,7 @@ library ghc-options: -Wall -Werror -Wno-missing-local-signatures -Wno-trustworthy-safe -Wno-missing-import-lists -Wno-implicit-prelude - -Wno-monomorphism-restriction + -Wno-monomorphism-restriction -Wredundant-constraints else ghc-options: -Wall From e188c0329674f84a5506e3bacc24830b60e82d1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20B=C3=A4renz?= Date: Wed, 8 Feb 2023 17:22:29 +0100 Subject: [PATCH 4/5] Fix warnings --- benchmark/Speed.hs | 3 +-- models/LDA.hs | 2 +- src/Control/Monad/Bayes/Inference/MCMC.hs | 2 +- src/Control/Monad/Bayes/Inference/TUI.hs | 3 +-- src/Control/Monad/Bayes/Sampler/Lazy.hs | 2 +- src/Control/Monad/Bayes/Sampler/Strict.hs | 2 +- src/Math/Integrators/StormerVerlet.hs | 2 +- test/TestAdvanced.hs | 13 +------------ test/TestDistribution.hs | 5 +---- test/TestInference.hs | 3 +-- test/TestIntegrator.hs | 2 +- test/TestPipes.hs | 2 -- test/TestPopulation.hs | 1 - test/TestSampler.hs | 2 +- test/TestStormerVerlet.hs | 5 +++-- test/TestWeighted.hs | 1 - 16 files changed, 15 insertions(+), 35 deletions(-) diff --git a/benchmark/Speed.hs b/benchmark/Speed.hs index eeadff8a..5232fdca 100644 --- a/benchmark/Speed.hs +++ b/benchmark/Speed.hs @@ -4,7 +4,7 @@ module Main (main) where -import Control.Monad.Bayes.Class (MonadDistribution, MonadMeasure) +import Control.Monad.Bayes.Class (MonadMeasure) import Control.Monad.Bayes.Inference.MCMC (MCMCConfig (MCMCConfig, numBurnIn, numMCMCSteps, proposal), Proposal (SingleSiteMH)) import Control.Monad.Bayes.Inference.RMSMC (rmsmcDynamic) import Control.Monad.Bayes.Inference.SMC (SMCConfig (SMCConfig, numParticles, numSteps, resampler), smc) @@ -27,7 +27,6 @@ import HMM qualified import LDA qualified import LogReg qualified import System.Process.Typed (runProcess) -import System.Random.Stateful (IOGenM, StatefulGen, StdGen, mkStdGen, newIOGenM) data ProbProgSys = MonadBayes deriving stock (Show) diff --git a/models/LDA.hs b/models/LDA.hs index 84f95985..2f990657 100644 --- a/models/LDA.hs +++ b/models/LDA.hs @@ -15,7 +15,7 @@ import Control.Monad.Bayes.Class MonadMeasure, factor, ) -import Control.Monad.Bayes.Sampler.Strict (sampleIO, sampleIOfixed) +import Control.Monad.Bayes.Sampler.Strict (sampleIOfixed) import Control.Monad.Bayes.Traced (mh) import Control.Monad.Bayes.Weighted (unweighted) import Data.Map qualified as Map diff --git a/src/Control/Monad/Bayes/Inference/MCMC.hs b/src/Control/Monad/Bayes/Inference/MCMC.hs index c25ecdd4..2aadded7 100644 --- a/src/Control/Monad/Bayes/Inference/MCMC.hs +++ b/src/Control/Monad/Bayes/Inference/MCMC.hs @@ -44,7 +44,7 @@ mcmcDynamic (MCMCConfig {..}) m = burnIn numBurnIn $ unweighted $ Dynamic.mh num -- -- | draw iid samples until you get one that has non-zero likelihood independentSamples :: Monad m => Static.Traced m a -> P.Producer (MHResult a) m (Trace a) -independentSamples (Static.Traced w d) = +independentSamples (Static.Traced _w d) = P.repeatM d >-> P.takeWhile' ((== 0) . probDensity) >-> P.map (MHResult False) diff --git a/src/Control/Monad/Bayes/Inference/TUI.hs b/src/Control/Monad/Bayes/Inference/TUI.hs index 9ea4aadc..494afcef 100644 --- a/src/Control/Monad/Bayes/Inference/TUI.hs +++ b/src/Control/Monad/Bayes/Inference/TUI.hs @@ -19,9 +19,8 @@ import Control.Monad.Bayes.Enumerator (toEmpirical) import Control.Monad.Bayes.Inference.MCMC import Control.Monad.Bayes.Sampler.Strict (SamplerIO, sampleIO) import Control.Monad.Bayes.Traced (Traced) -import Control.Monad.Bayes.Traced.Common +import Control.Monad.Bayes.Traced.Common hiding (burnIn) import Control.Monad.Bayes.Weighted -import Control.Monad.State.Class (put) import Data.Scientific (FPFormat (Exponent), formatScientific, fromFloatDigits) import Data.Text qualified as T import Data.Text.Lazy qualified as TL diff --git a/src/Control/Monad/Bayes/Sampler/Lazy.hs b/src/Control/Monad/Bayes/Sampler/Lazy.hs index 5e91aa8e..3bedbe59 100644 --- a/src/Control/Monad/Bayes/Sampler/Lazy.hs +++ b/src/Control/Monad/Bayes/Sampler/Lazy.hs @@ -6,7 +6,7 @@ -- | This is a port of the implementation of LazyPPL: https://lazyppl.bitbucket.io/ module Control.Monad.Bayes.Sampler.Lazy where -import Control.Monad (ap, liftM) +import Control.Monad (ap) import Control.Monad.Bayes.Class (MonadDistribution (random)) import Control.Monad.Bayes.Weighted (Weighted, weighted) import Numeric.Log (Log (..)) diff --git a/src/Control/Monad/Bayes/Sampler/Strict.hs b/src/Control/Monad/Bayes/Sampler/Strict.hs index 22f535f4..e84d3fc6 100644 --- a/src/Control/Monad/Bayes/Sampler/Strict.hs +++ b/src/Control/Monad/Bayes/Sampler/Strict.hs @@ -77,7 +77,7 @@ instance StatefulGen g m => MonadDistribution (Sampler g m) where -- >>> import System.Random.Stateful hiding (random) -- >>> newIOGenM (mkStdGen 1729) >>= sampleWith random -- 4.690861245089605e-2 -sampleWith :: StatefulGen g m => Sampler g m a -> g -> m a +sampleWith :: Sampler g m a -> g -> m a sampleWith (Sampler m) = runReaderT m -- | initialize random seed using system entropy, and sample diff --git a/src/Math/Integrators/StormerVerlet.hs b/src/Math/Integrators/StormerVerlet.hs index 0bcf8a8f..6b48229e 100644 --- a/src/Math/Integrators/StormerVerlet.hs +++ b/src/Math/Integrators/StormerVerlet.hs @@ -25,7 +25,7 @@ type Integrator a = -- | Störmer-Verlet integration scheme for systems of the form -- \(\mathbb{H}(p,q) = T(p) + V(q)\) stormerVerlet2H :: - (Applicative f, Num (f a), Show (f a), Fractional a) => + (Applicative f, Num (f a), Fractional a) => -- | Step size a -> -- | \(\frac{\partial H}{\partial q}\) diff --git a/test/TestAdvanced.hs b/test/TestAdvanced.hs index 45c15cf8..d715939a 100644 --- a/test/TestAdvanced.hs +++ b/test/TestAdvanced.hs @@ -1,15 +1,7 @@ module TestAdvanced where -import ConjugatePriors - ( betaBernoulli', - betaBernoulliAnalytic, - gammaNormal', - gammaNormalAnalytic, - normalNormal', - normalNormalAnalytic, - ) import Control.Arrow -import Control.Monad (join, replicateM) +import Control.Monad (join) import Control.Monad.Bayes.Class import Control.Monad.Bayes.Enumerator import Control.Monad.Bayes.Inference.MCMC @@ -19,9 +11,6 @@ import Control.Monad.Bayes.Inference.SMC import Control.Monad.Bayes.Inference.SMC2 import Control.Monad.Bayes.Population import Control.Monad.Bayes.Sampler.Strict -import Control.Monad.Bayes.Traced -import Control.Monad.Bayes.Weighted -import Numeric.Log (Log) mcmcConfig :: MCMCConfig mcmcConfig = MCMCConfig {numMCMCSteps = 0, numBurnIn = 0, proposal = SingleSiteMH} diff --git a/test/TestDistribution.hs b/test/TestDistribution.hs index 8c54739e..87a90c49 100644 --- a/test/TestDistribution.hs +++ b/test/TestDistribution.hs @@ -9,13 +9,10 @@ module TestDistribution where import Control.Monad (replicateM) -import Control.Monad.Bayes.Class (MonadDistribution, mvNormal) +import Control.Monad.Bayes.Class (mvNormal) import Control.Monad.Bayes.Sampler.Strict -import Control.Monad.Identity (runIdentity) -import Control.Monad.State (evalStateT) import Data.Matrix (fromList) import Data.Vector qualified as V -import System.Random.MWC (toSeed) -- Test the sampled covariance is approximately the same as the -- specified covariance. diff --git a/test/TestInference.hs b/test/TestInference.hs index 3fecc16f..7a2d404a 100644 --- a/test/TestInference.hs +++ b/test/TestInference.hs @@ -20,7 +20,6 @@ import Control.Monad.Bayes.Inference.SMC import Control.Monad.Bayes.Integrator (normalize) import Control.Monad.Bayes.Integrator qualified as Integrator import Control.Monad.Bayes.Population -import Control.Monad.Bayes.Population (collapse, runPopulation) import Control.Monad.Bayes.Sampler.Strict (Sampler, sampleIOfixed) import Control.Monad.Bayes.Sampler.Strict qualified as Sampler import Control.Monad.Bayes.Weighted (Weighted) @@ -28,7 +27,7 @@ import Control.Monad.Bayes.Weighted qualified as Weighted import Data.AEq (AEq ((~==))) import Numeric.Log (Log) import Sprinkler (soft) -import System.Random.Stateful (IOGenM, StdGen, mkStdGen, newIOGenM) +import System.Random.Stateful (IOGenM, StdGen) sprinkler :: MonadMeasure m => m Bool sprinkler = Sprinkler.soft diff --git a/test/TestIntegrator.hs b/test/TestIntegrator.hs index 7dc7ff3a..585bb39d 100644 --- a/test/TestIntegrator.hs +++ b/test/TestIntegrator.hs @@ -14,7 +14,7 @@ import Control.Monad.Bayes.Class import Control.Monad.Bayes.Integrator import Control.Monad.Bayes.Sampler.Strict import Control.Monad.Bayes.Weighted (weighted) -import Control.Monad.ST (ST, runST) +import Control.Monad.ST (runST) import Data.AEq (AEq ((~==))) import Data.List (sortOn) import Data.Set (fromList) diff --git a/test/TestPipes.hs b/test/TestPipes.hs index 77944cdb..4efe68ad 100644 --- a/test/TestPipes.hs +++ b/test/TestPipes.hs @@ -7,9 +7,7 @@ import Control.Monad.Bayes.Class () import Control.Monad.Bayes.Enumerator (enumerator) import Data.AEq (AEq ((~==))) import HMM (hmm, hmmPosterior) -import Pipes ((>->)) import Pipes.Prelude (toListM) -import qualified Pipes.Prelude as Pipes urns :: Int -> Bool urns n = enumerator (urn n) ~== enumerator (urnP n) diff --git a/test/TestPopulation.hs b/test/TestPopulation.hs index c365e2be..a2aea9b2 100644 --- a/test/TestPopulation.hs +++ b/test/TestPopulation.hs @@ -14,7 +14,6 @@ import Control.Monad.Bayes.Population as Population import Control.Monad.Bayes.Sampler.Strict (sampleIOfixed) import Data.AEq (AEq ((~==))) import Sprinkler (soft) -import System.Random.Stateful (mkStdGen, newIOGenM) weightedSampleSize :: MonadDistribution m => Population m a -> m Int weightedSampleSize = fmap length . population diff --git a/test/TestSampler.hs b/test/TestSampler.hs index 156e5b37..f746b9ee 100644 --- a/test/TestSampler.hs +++ b/test/TestSampler.hs @@ -4,7 +4,7 @@ import qualified Control.Foldl as Fold import Control.Monad (replicateM) import Control.Monad.Bayes.Class (MonadDistribution (normal)) import Control.Monad.Bayes.Sampler.Strict (sampleSTfixed) -import Control.Monad.ST (ST, runST) +import Control.Monad.ST (runST) testMeanAndVariance :: Bool testMeanAndVariance = isDiff diff --git a/test/TestStormerVerlet.hs b/test/TestStormerVerlet.hs index 6c567371..9dc510a6 100644 --- a/test/TestStormerVerlet.hs +++ b/test/TestStormerVerlet.hs @@ -10,6 +10,7 @@ import qualified Data.Vector as V import qualified Linear as L import Linear.V import Math.Integrators.StormerVerlet +import Statistics.Function (square) gConst :: Double gConst = 6.67384e-11 @@ -81,8 +82,8 @@ energy x = keJ + keS + peJ + peS qS = qs ^. _2 pJ = ps ^. _1 pS = ps ^. _2 - keJ = (* 0.5) $ (/ jupiterMass) $ sum $ fmap (^ 2) pJ - keS = (* 0.5) $ (/ sunMass) $ sum $ fmap (^ 2) pS + keJ = (* 0.5) $ (/ jupiterMass) $ sum $ fmap square pJ + keS = (* 0.5) $ (/ sunMass) $ sum $ fmap square pS r = qJ L.^-^ qS ri = r `L.dot` r peJ = 0.5 * gConst * sunMass * jupiterMass / (sqrt ri) diff --git a/test/TestWeighted.hs b/test/TestWeighted.hs index 95942f1e..1e09971f 100644 --- a/test/TestWeighted.hs +++ b/test/TestWeighted.hs @@ -13,7 +13,6 @@ import Control.Monad.State (unless, when) import Data.AEq (AEq ((~==))) import Data.Bifunctor (second) import Numeric.Log (Log (Exp, ln)) -import System.Random.Stateful (mkStdGen, newIOGenM) model :: MonadMeasure m => m (Int, Double) model = do From d4ce1c9d7d0780f4b306935d6b7cf765226a90e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20B=C3=A4renz?= Date: Wed, 8 Feb 2023 17:22:39 +0100 Subject: [PATCH 5/5] Disable name-shadowing warning --- monad-bayes.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monad-bayes.cabal b/monad-bayes.cabal index 1b20eea9..bd5a5a87 100644 --- a/monad-bayes.cabal +++ b/monad-bayes.cabal @@ -103,7 +103,7 @@ library if flag(dev) ghc-options: -Wall -Werror -Wno-missing-local-signatures -Wno-trustworthy-safe - -Wno-missing-import-lists -Wno-implicit-prelude + -Wno-missing-import-lists -Wno-implicit-prelude -Wno-name-shadowing -Wno-monomorphism-restriction -Wredundant-constraints else