From 11ae4667d34349af95faeb431d282e0e6c4d9e25 Mon Sep 17 00:00:00 2001
From: Colm Talbot <colm.talbot@ligo.org>
Date: Fri, 11 Feb 2022 19:55:24 +0000
Subject: [PATCH] remove OrderedDict

---
 bilby/core/grid.py             |  3 +--
 bilby/core/result.py           |  6 +++---
 bilby/core/sampler/__init__.py |  5 ++---
 bilby/core/sampler/proposal.py |  3 +--
 bilby/core/sampler/pymc3.py    | 10 ++++------
 5 files changed, 11 insertions(+), 16 deletions(-)

diff --git a/bilby/core/grid.py b/bilby/core/grid.py
index 8e264872d..4efc8997b 100644
--- a/bilby/core/grid.py
+++ b/bilby/core/grid.py
@@ -1,6 +1,5 @@
 import json
 import os
-from collections import OrderedDict
 
 import numpy as np
 
@@ -352,7 +351,7 @@ class Grid(object):
             'label', 'outdir', 'parameter_names', 'n_dims', 'priors',
             'sample_points', 'ln_likelihood', 'ln_evidence',
             'ln_noise_evidence']
-        dictionary = OrderedDict()
+        dictionary = dict()
         for attr in save_attrs:
             try:
                 dictionary[attr] = getattr(self, attr)
diff --git a/bilby/core/result.py b/bilby/core/result.py
index 48797a4f1..e90d7274f 100644
--- a/bilby/core/result.py
+++ b/bilby/core/result.py
@@ -2,7 +2,7 @@ import datetime
 import inspect
 import json
 import os
-from collections import OrderedDict, namedtuple
+from collections import namedtuple
 from copy import copy
 from importlib import import_module
 from itertools import product
@@ -724,7 +724,7 @@ class Result(object):
             'num_likelihood_evaluations', 'samples', 'nested_samples',
             'walkers', 'nburn', 'parameter_labels', 'parameter_labels_with_unit',
             'version']
-        dictionary = OrderedDict()
+        dictionary = dict()
         for attr in save_attrs:
             try:
                 dictionary[attr] = getattr(self, attr)
@@ -1397,7 +1397,7 @@ class Result(object):
             ax.set_ylabel(ylabel)
 
         handles, labels = plt.gca().get_legend_handles_labels()
-        by_label = OrderedDict(zip(labels, handles))
+        by_label = dict(zip(labels, handles))
         plt.legend(by_label.values(), by_label.keys())
         ax.legend(numpoints=3)
         fig.tight_layout()
diff --git a/bilby/core/sampler/__init__.py b/bilby/core/sampler/__init__.py
index 77e481e95..bd259f97a 100644
--- a/bilby/core/sampler/__init__.py
+++ b/bilby/core/sampler/__init__.py
@@ -1,7 +1,6 @@
 import inspect
 import sys
 import datetime
-from collections import OrderedDict
 
 import bilby
 from ..utils import command_line_args, logger, loaded_modules_dict
@@ -161,12 +160,12 @@ def run_sampler(
 
     _check_marginalized_parameters_not_sampled(likelihood, priors)
 
-    if type(priors) in [dict, OrderedDict]:
+    if type(priors) == dict:
         priors = PriorDict(priors)
     elif isinstance(priors, PriorDict):
         pass
     else:
-        raise ValueError("Input priors not understood")
+        raise ValueError("Input priors not understood should be dict or PriorDict")
 
     priors.fill_priors(likelihood, default_priors_file=default_priors_file)
 
diff --git a/bilby/core/sampler/proposal.py b/bilby/core/sampler/proposal.py
index df2c021ca..2d5261658 100644
--- a/bilby/core/sampler/proposal.py
+++ b/bilby/core/sampler/proposal.py
@@ -1,4 +1,3 @@
-from collections import OrderedDict
 from inspect import isclass
 
 import numpy as np
@@ -7,7 +6,7 @@ import random
 from ..prior import Uniform
 
 
-class Sample(OrderedDict):
+class Sample(dict):
 
     def __init__(self, dictionary=None):
         if dictionary is None:
diff --git a/bilby/core/sampler/pymc3.py b/bilby/core/sampler/pymc3.py
index 25522f82f..4ff4b232a 100644
--- a/bilby/core/sampler/pymc3.py
+++ b/bilby/core/sampler/pymc3.py
@@ -1,5 +1,3 @@
-
-from collections import OrderedDict
 from distutils.version import StrictVersion
 
 import numpy as np
@@ -420,7 +418,7 @@ class Pymc3(MCMCSampler):
             # so check for this
             if self.step_method is None:
                 pass
-            elif isinstance(self.step_method, (dict, OrderedDict)):
+            elif isinstance(self.step_method, dict):
                 for key in self.step_method:
                     if key not in self._search_parameter_keys:
                         raise ValueError("Setting a step method for an unknown parameter '{}'".format(key))
@@ -498,7 +496,7 @@ class Pymc3(MCMCSampler):
         methodslist = []
 
         # set the step method
-        if isinstance(self.step_method, (dict, OrderedDict)):
+        if isinstance(self.step_method, dict):
             # create list of step methods (any not given will default to NUTS)
             self.kwargs['step'] = []
             with self.pymc3_model:
@@ -607,7 +605,7 @@ class Pymc3(MCMCSampler):
 
         self.setup_prior_mapping()
 
-        self.pymc3_priors = OrderedDict()
+        self.pymc3_priors = dict()
         pymc3, STEP_METHODS, floatX = self._import_external_sampler()
 
         # initialise a dictionary of multivariate Gaussian parameters
@@ -821,7 +819,7 @@ class Pymc3(MCMCSampler):
                 # set theano Op - pass _search_parameter_keys, which only contains non-fixed variables
                 logl = LogLike(self._search_parameter_keys, self.likelihood, self.pymc3_priors)
 
-                parameters = OrderedDict()
+                parameters = dict()
                 for key in self._search_parameter_keys:
                     try:
                         parameters[key] = self.pymc3_priors[key]
-- 
GitLab