From 51884973910e289376a96b22783bf99d3d228f4d Mon Sep 17 00:00:00 2001
From: Gregorio Carullo <gregorio.carullo@ligo.org>
Date: Sat, 22 Jul 2023 17:49:16 +0200
Subject: [PATCH 1/3] Add basic structure for nessai integration

---
 pyRing/pyRing.py | 23 +++++++++++++++++++++++
 requirements.txt |  3 ++-
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/pyRing/pyRing.py b/pyRing/pyRing.py
index a3f3853..7223bb5 100644
--- a/pyRing/pyRing.py
+++ b/pyRing/pyRing.py
@@ -1955,6 +1955,29 @@ def main():
             work.run()
             x           = work.posterior_samples.ravel()
             logZ_signal = work.logZ
+
+        elif(input_par['sampler']=='nessai'):
+
+            try   : import nessai
+            except: raise Exception('The nessai sampler requires the nessai package. Please install it through `pip install nessai`.')
+            print('* Using nessai version: `{}`.\n'.format(nessai.__version__))
+
+            # Danny, please update the block below (from raynest to nessai options) with the required edits.
+
+            # print('* The sampling output appears in the `{}/Nested_sampler/raynest.log` file.\n'.format(input_par['output']))
+            # work=raynest.raynest(signal_model,
+            #                      verbose   = sampler_params['verbose'],
+            #                      nlive     = sampler_params['nlive'],
+            #                      maxmcmc   = sampler_params['maxmcmc'],
+            #                      nnest     = sampler_params['nnest'],
+            #                      nensemble = sampler_params['nensemble'],
+            #                      output    = input_par['output']+'/Nested_sampler',
+            #                      seed      = sampler_params['seed'],
+            #                      resume    = sampler_params['resume'])
+            # work.run()
+            # x           = work.posterior_samples.ravel()
+            # logZ_signal = work.logZ
+
         else:
             raise ValueError('Unsupported sampler passed under the option `sampler` of the `Sampler settings` section.')
 
diff --git a/requirements.txt b/requirements.txt
index 7dcdd9d..122a53b 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -5,8 +5,9 @@ gwpy
 h5py
 lalsuite
 matplotlib
+nessai
 numpy
 pesummary
 raynest
 seaborn
-scipy
\ No newline at end of file
+scipy
-- 
GitLab


From eaa32d06ece05067b9faf6d80e57117eb2e50cd9 Mon Sep 17 00:00:00 2001
From: Gregorio Carullo <gregorio.carullo@ligo.org>
Date: Sat, 22 Jul 2023 17:54:48 +0200
Subject: [PATCH 2/3] Edit init

---
 pyRing/initialise.py | 6 ++++--
 pyRing/pyRing.py     | 2 +-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/pyRing/initialise.py b/pyRing/initialise.py
index 44d8b17..b14bc49 100644
--- a/pyRing/initialise.py
+++ b/pyRing/initialise.py
@@ -1024,7 +1024,7 @@ to be intended as part of the default value.
                # Sampler parameters. #
                #=====================#
 
-               sampler                      Option to switch between different samplers. Available options: [`cpnest`, `raynest`]. Default: 'cpnest'.
+               sampler                      Option to switch between different samplers. Available options: [`cpnest`, `nessai`, `raynest`]. Default: 'cpnest'.
                
                #===============================#
                # Branch-independent parameters #
@@ -1048,6 +1048,8 @@ to be intended as part of the default value.
                nensemble                    Total number of ensemble processes running (`raynest` sampler only). nensemble = nnest * N_ev, where N_ev is the number of live points being  \
     substituted at each NS step. Requires N_ev << nlive. Also n_cpu = nnest+nensemble. Default: 1.
 
+               FILLME: add the documentation of the nessai parameters
+
        *******************************************************
        * Parameters to be passed to the [Injection] section. *
        *******************************************************
@@ -1061,7 +1063,7 @@ to be intended as part of the default value.
        * Parameters to be passed to the [Plot] section. *
        **************************************************
        
-                imr-samples               File containing the posterior samples from an IMR run to compare against ringdown values in plots. Needs to be either a full posterior in the GWTC-1 format or the marginalised posterior on Mf-af, with two columns and the ['Mf', 'af'] header.
+               imr-samples               File containing the posterior samples from an IMR run to compare against ringdown values in plots. Needs to be either a full posterior in the GWTC-1 format or the marginalised posterior on Mf-af, with two columns and the ['Mf', 'af'] header.
 
 """
                                                      
diff --git a/pyRing/pyRing.py b/pyRing/pyRing.py
index 7223bb5..79db247 100644
--- a/pyRing/pyRing.py
+++ b/pyRing/pyRing.py
@@ -1962,7 +1962,7 @@ def main():
             except: raise Exception('The nessai sampler requires the nessai package. Please install it through `pip install nessai`.')
             print('* Using nessai version: `{}`.\n'.format(nessai.__version__))
 
-            # Danny, please update the block below (from raynest to nessai options) with the required edits.
+            # Update the block below (from raynest to nessai options) with the required edits.
 
             # print('* The sampling output appears in the `{}/Nested_sampler/raynest.log` file.\n'.format(input_par['output']))
             # work=raynest.raynest(signal_model,
-- 
GitLab


From 8042936e36922b88abd2efa43f6198664f78d0c8 Mon Sep 17 00:00:00 2001
From: Gregorio Carullo <gregorio.carullo@ligo.org>
Date: Sat, 22 Jul 2023 17:56:25 +0200
Subject: [PATCH 3/3] Add example nessai config file

---
 .../config_gw150914_local_data_nessai.ini     | 39 +++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100644 pyRing/config_files/config_gw150914_local_data_nessai.ini

diff --git a/pyRing/config_files/config_gw150914_local_data_nessai.ini b/pyRing/config_files/config_gw150914_local_data_nessai.ini
new file mode 100644
index 0000000..adb0ef5
--- /dev/null
+++ b/pyRing/config_files/config_gw150914_local_data_nessai.ini
@@ -0,0 +1,39 @@
+[input]
+
+run-type=full
+pesummary=0
+output=gw150914_local_data_32s_nessai_sampler
+data-H1=data/Real_data/GW150914/H-H1_GWOSC_4KHZ_R1-1126259447-32.txt
+data-L1=data/Real_data/GW150914/L-L1_GWOSC_4KHZ_R1-1126259447-32.txt
+trigtime=1126259462.4232266
+detectors=H1,L1
+template=Damped-sinusoids
+sky-frame = equatorial
+screen-output=1
+
+[Sampler settings]
+
+sampler=nessai
+# Update with nessai parameters
+#verbose=2
+#nlive=1024
+#maxmcmc=1024
+#nnest=1
+#nensemble=1
+#seed=1234
+#resume=1
+#periodic_checkpoint_interval=900
+
+[Priors]
+
+mf-time-prior=67.9
+#10Mf after the peaktime
+fix-t=0.00335
+fix-ra=1.1579
+fix-dec=-1.1911
+
+[Injection]
+
+[Plot]
+
+imr-samples=data/Real_data/GW150914/GW150914_LAL_IMRPhenomP_O1_GWOSC_Mf_af_samples.txt
-- 
GitLab