From 18b3e1643cb34c0b1d286dc306b6f9f5f190b4d5 Mon Sep 17 00:00:00 2001
From: Gregory Ashton <gregory.ashton@ligo.org>
Date: Wed, 13 Oct 2021 07:32:27 -0700
Subject: [PATCH] Improve the cache check

---
 bilby/core/sampler/base_sampler.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/bilby/core/sampler/base_sampler.py b/bilby/core/sampler/base_sampler.py
index e590ee242..215104a98 100644
--- a/bilby/core/sampler/base_sampler.py
+++ b/bilby/core/sampler/base_sampler.py
@@ -512,7 +512,13 @@ class Sampler(object):
                         key, self) is False:
                     logger.debug("Cached value {} is unmatched".format(key))
                     use_cache = False
-            if self.meta_data["likelihood"] != self.cached_result.meta_data["likelihood"]:
+            try:
+                # Recursive check the dictionaries allowing for numpy arrays
+                np.testing.assert_equal(
+                    self.meta_data["likelihood"],
+                    self.cached_result.meta_data["likelihood"]
+                )
+            except AssertionError:
                 use_cache = False
             if use_cache is False:
                 self.cached_result = None
-- 
GitLab