From e385b057302040e6ce5dd61cdf14cad2cdcc8757 Mon Sep 17 00:00:00 2001
From: Robert Izzard <r.izzard@surrey.ac.uk>
Date: Sun, 21 Nov 2021 09:21:40 +0000
Subject: [PATCH] add multiplictity to the const_dt function : no idea how it
 worked previously!

---
 binarycpython/utils/cache.py                 | 68 +++++++++++++++++++-
 binarycpython/utils/grid.py                  |  5 +-
 binarycpython/utils/grid_options_defaults.py | 10 +--
 binarycpython/utils/spacing_functions.py     |  4 +-
 4 files changed, 76 insertions(+), 11 deletions(-)

diff --git a/binarycpython/utils/cache.py b/binarycpython/utils/cache.py
index 021f1bcc3..50dfe03c0 100644
--- a/binarycpython/utils/cache.py
+++ b/binarycpython/utils/cache.py
@@ -107,7 +107,7 @@ class cache():
             else:
                 # function isn't wrapped, which means it was previously
                 # unwrapped, so rewrap it if not using NoCache
-                if usecachetype != 'NoCache':
+                if usecachetype != 'NoCache' and func in self.cached_function_cache:
                     _code = 'module.{}.{} = self.cached_function_cache["{}"]'.format(x[0],x[1],func)
                     exec(_code)
 
@@ -216,3 +216,69 @@ class cache():
                     print('')
             print("Best cache type {type} with maxsize {maxsize}\n".format(type=best_type,maxsize=best_maxsize))
         return
+
+
+    """
+Cache speed test of function distribution_functions.powerlaw_constant
+                          0        1        2        4        8       16       32       64      128      256
+NoCache            6.28e+07
+NullCache          6.39e+07 6.40e+07 6.41e+07 6.39e+07 6.44e+07 6.43e+07 6.37e+07 6.40e+07 6.38e+07 6.40e+07
+FIFOCache          6.41e+07 6.37e+07 6.40e+07 6.39e+07 6.40e+07 6.37e+07 6.41e+07 6.40e+07 6.41e+07 6.40e+07
+LRUCache           6.42e+07 6.41e+07 6.42e+07 6.41e+07 6.38e+07 6.43e+07 6.41e+07 6.43e+07 6.40e+07 6.41e+07
+TTLCache           6.41e+07 6.35e+07 6.37e+07 6.39e+07 6.37e+07 6.42e+07 6.39e+07 6.38e+07 6.37e+07 6.38e+07
+Best cache type NullCache with maxsize 8
+
+Cache speed test of function distribution_functions.calculate_constants_three_part_powerlaw
+                          0        1        2        4        8       16       32       64      128      256
+NoCache            1.44e+07
+NullCache          9.13e+06 9.18e+06 9.20e+06 9.21e+06 9.20e+06 9.12e+06 9.18e+06 9.18e+06 9.15e+06 9.12e+06
+FIFOCache          2.53e+07 2.52e+07 2.51e+07 2.50e+07 2.51e+07 2.52e+07 2.52e+07 2.52e+07 2.52e+07 2.51e+07
+LRUCache           1.62e+07 1.62e+07 1.62e+07 1.62e+07 1.62e+07 1.62e+07 1.62e+07 1.62e+07 1.62e+07 1.62e+07
+TTLCache           1.43e+07 1.43e+07 1.43e+07 1.43e+07 1.43e+07 1.44e+07 1.42e+07 1.43e+07 1.43e+07 1.43e+07
+Best cache type FIFOCache with maxsize 0
+
+Cache speed test of function distribution_functions.gaussian_normalizing_const
+                          0        1        2        4        8       16       32       64      128      256
+NoCache               64183
+NullCache             64340    64339    64544    64260    64491    64382    64400    63974    63954    64338
+FIFOCache          2.62e+07 2.62e+07 2.62e+07 2.61e+07 2.61e+07 2.59e+07 2.61e+07 2.59e+07 2.57e+07 2.59e+07
+LRUCache           1.66e+07 1.66e+07 1.65e+07 1.66e+07 1.65e+07 1.65e+07 1.64e+07 1.65e+07 1.64e+07 1.65e+07
+TTLCache           1.42e+07 1.44e+07 1.42e+07 1.44e+07 1.43e+07 1.43e+07 1.42e+07 1.44e+07 1.42e+07 1.44e+07
+Best cache type FIFOCache with maxsize 1
+
+Cache speed test of function spacing_functions.const_linear
+                          0        1        2        4        8       16       32       64      128      256
+NoCache            1.22e+06
+NullCache          1.05e+06 1.05e+06 1.06e+06 1.05e+06 1.05e+06 1.06e+06 1.05e+06 1.05e+06 1.05e+06 1.05e+06
+FIFOCache          2.85e+07 2.85e+07 2.86e+07 2.85e+07 2.84e+07 2.85e+07 2.84e+07 2.84e+07 2.85e+07 2.81e+07
+LRUCache           1.77e+07 1.79e+07 1.73e+07 1.73e+07 1.76e+07 1.79e+07 1.76e+07 1.74e+07 1.74e+07 1.72e+07
+TTLCache           1.46e+07 1.49e+07 1.50e+07 1.53e+07 1.51e+07 1.53e+07 1.52e+07 1.51e+07 1.47e+07 1.50e+07
+Best cache type FIFOCache with maxsize 2
+
+Cache speed test of function spacing_functions.const_int
+                          0        1        2        4        8       16       32       64      128      256
+NoCache            4.23e+07
+NullCache          1.65e+07 1.66e+07 1.65e+07 1.64e+07 1.66e+07 1.65e+07 1.59e+07 1.59e+07 1.65e+07 1.64e+07
+FIFOCache          2.86e+07 2.86e+07 2.87e+07 2.86e+07 2.84e+07 2.86e+07 2.81e+07 2.79e+07 2.78e+07 2.85e+07
+LRUCache           1.78e+07 1.78e+07 1.77e+07 1.75e+07 1.77e+07 1.78e+07 1.78e+07 1.78e+07 1.74e+07 1.75e+07
+TTLCache           1.55e+07 1.54e+07 1.55e+07 1.54e+07 1.55e+07 1.49e+07 1.52e+07 1.51e+07 1.52e+07 1.54e+07
+Best cache type NoCache with maxsize 0
+
+Cache speed test of function spacing_functions.const_ranges
+                          0        1        2        4        8       16       32       64      128      256
+NoCache            2.54e+05
+NullCache          2.25e+05 2.25e+05 2.24e+05 2.25e+05 2.25e+05 2.25e+05 2.25e+05 2.26e+05 2.25e+05 2.26e+05
+FIFOCache          2.58e+07 2.55e+07 2.53e+07 2.54e+07 2.56e+07 2.57e+07 2.56e+07 2.57e+07 2.58e+07 2.58e+07
+LRUCache           1.62e+07 1.63e+07 1.62e+07 1.62e+07 1.61e+07 1.62e+07 1.62e+07 1.62e+07 1.61e+07 1.63e+07
+TTLCache           1.41e+07 1.43e+07 1.42e+07 1.42e+07 1.40e+07 1.42e+07 1.42e+07 1.43e+07 1.40e+07 1.43e+07
+Best cache type FIFOCache with maxsize 128
+
+Cache speed test of function spacing_functions.gaussian_zoom
+                          0        1        2        4        8       16       32       64      128      256
+NoCache               24703
+NullCache             24872    24935    24927    24896    24968    24964    24882    24840    24873    24913
+FIFOCache          2.54e+07 2.54e+07 2.54e+07 2.54e+07 2.53e+07 2.52e+07 2.53e+07 2.51e+07 2.52e+07 2.52e+07
+LRUCache           1.63e+07 1.63e+07 1.63e+07 1.64e+07 1.63e+07 1.64e+07 1.63e+07 1.63e+07 1.63e+07 1.63e+07
+TTLCache           1.43e+07 1.43e+07 1.42e+07 1.42e+07 1.43e+07 1.42e+07 1.43e+07 1.43e+07 1.43e+07 1.43e+07
+Best cache type FIFOCache with maxsize 0
+    """
diff --git a/binarycpython/utils/grid.py b/binarycpython/utils/grid.py
index b9b0b9c47..71dc78c61 100644
--- a/binarycpython/utils/grid.py
+++ b/binarycpython/utils/grid.py
@@ -457,6 +457,7 @@ class Population(analytics,
         for param_name in sorted(parameter_dict):
             argline += "{} {} ".format(param_name, parameter_dict[param_name])
         argline = argline.strip()
+
         return argline
 
     ###################################################
@@ -1939,7 +1940,7 @@ class Population(analytics,
                 raise ValueError
 
             # Set up the grid code with a dry run option to see total probability
-            print("Do dry {}".format(self.grid_options["do_dry_run"]))
+            print("Do dry run? {}".format(self.grid_options["do_dry_run"]))
             if self.grid_options["do_dry_run"]:
                 print("Doing dry run to calculate total starcount and probability")
                 self._generate_grid_code(dry_run=True)
@@ -1949,7 +1950,7 @@ class Population(analytics,
                 self._load_grid_function()
 
                 # Do a dry run
-                print("Do dry run")
+                print("Doing dry run")
                 self._dry_run()
 
                 self.verbose_print(
diff --git a/binarycpython/utils/grid_options_defaults.py b/binarycpython/utils/grid_options_defaults.py
index 8f6d66d68..a5a83a400 100644
--- a/binarycpython/utils/grid_options_defaults.py
+++ b/binarycpython/utils/grid_options_defaults.py
@@ -183,12 +183,12 @@ class grid_options_defaults():
                 #
                 # if n is None, no cache is set up
                 "distribution_functions.powerlaw_constant" : (0, "NoCache", "1,100,-2"),
-                "distribution_functions.calculate_constants_three_part_powerlaw" : (4, None, "0.1,0.5,1,100,-1.3,-2.3,-2.3"),
-                "distribution_functions.gaussian_normalizing_const" : (0, None, "1.0,1.0,-10.0,+10.0"),
-                "spacing_functions.const_linear" : (0, None, "1,10,9"),
+                "distribution_functions.calculate_constants_three_part_powerlaw" : (16, "FIFOCache", "0.1,0.5,1,100,-1.3,-2.3,-2.3"),
+                "distribution_functions.gaussian_normalizing_const" : (16, "FIFOCache", "1.0,1.0,-10.0,+10.0"),
+                "spacing_functions.const_linear" : (16, "FIFOCache", "1,10,9"),
                 "spacing_functions.const_int" : (0, None, "1,10,9"),
-                "spacing_functions.const_ranges" : (0, None, "((0.1,0.65,10),(0.65,0.85,20),(0.85,10.0,10))"),
-                "spacing_functions.gaussian_zoom" : (0, None, "1.0,10.0,5.0,2.0,0.9,100"),
+                "spacing_functions.const_ranges" : (16, "FIFOCache", "((0.1,0.65,10),(0.65,0.85,20),(0.85,10.0,10))"),
+                "spacing_functions.gaussian_zoom" : (16, "FIFOCache", "1.0,10.0,5.0,2.0,0.9,100"),
             },
 
             ########################################
diff --git a/binarycpython/utils/spacing_functions.py b/binarycpython/utils/spacing_functions.py
index a16be46c6..bc3d53288 100644
--- a/binarycpython/utils/spacing_functions.py
+++ b/binarycpython/utils/spacing_functions.py
@@ -183,9 +183,6 @@ class spacing_functions():
         return np.unique(array)
 
 
-    @cachetools.cachedmethod(
-        lambda self: self.caches["spacing_functions.const_dt"]
-    )
     def const_dt(self,cachedir=None,usecache=True,**kwargs):
         """
         const_dt returns a list of masses spaced at a constant age difference
@@ -279,6 +276,7 @@ class spacing_functions():
                 start_at=0,
                 slurm=0,
                 condor=0,
+                multiplicity=1,
             )
 
             # make a grid in M1
-- 
GitLab