TeamCOMPAS / COMPAS

COMPAS rapid binary population synthesis code
http://compas.science
MIT License
64 stars 67 forks source link

Generating binaries using stroopwafelinterface.py #753

Closed syedalimohsinbukhari closed 1 year ago

syedalimohsinbukhari commented 2 years ago

Hi,

When I generate binaries using stroopwafelinterface.py using the default values it gives me a 0 rate_of_hits. I even tried it for 10M binaries but still got the same result.

### Include options from local pythonSubmit file      
usePythonSubmit = False #If false, use stroopwafel defaults

### Set default stroopwafel inputs - these are overwritten by any command-line arguments

compas_executable = os.path.join(os.environ.get('COMPAS_ROOT_DIR'), 'src/COMPAS')   # Location of the executable      # Note: overrides pythonSubmit value
num_systems = int(1e7)              # Number of binary systems to evolve                                              # Note: overrides pythonSubmit value
output_folder = 'output/'           # Location of output folder (relative to cwd)                                     # Note: overrides pythonSubmit value
random_seed_base = 0                # The initial random seed to increment from                                       # Note: overrides pythonSubmit value

num_cores = 10                      # Number of cores to parallelize over 
num_per_core = int(1e6)             # Number of binaries per batch
mc_only = True                      # Exclude adaptive importance sampling (currently not implemented, leave set to True)
run_on_hpc = False                  # Run on slurm based cluster HPC

output_filename = 'samples.csv'     # output filename for the stroopwafel samples
debug = False                       # show COMPAS output/errors

And the resulting log file is

rate_of_hits = 0.000000
uncertainity = 0.000000

Also, I noticed that the interesting_systems function is reading the COMPAS CSV files. Is it because I'm not providing it with these files?

def interesting_systems(batch):
    """
    This is a mandatory function, it tells stroopwafel what an interesting system is. User is free to define whatever looks interesting to them.
    IN:
        batch (dict): As input you will be given the current batch which just finished its execution. You can take in all the keys you defined in the configure_code_run method above
    OUT:
        Number of interesting systems
        In the below example, I define all the NSs as interesting, so I read the files, get the SEED from the system_params file and define the key is_hit in the end for all interesting systems 
    """
    try:
        folder = os.path.join(output_folder, batch['output_container'])
        shutil.move(batch['grid_filename'], folder + '/grid_' + str(batch['number']) + '.csv')
        system_parameters = pd.read_csv(folder + '/BSE_System_Parameters.csv', skiprows = 2)
        system_parameters.rename(columns = lambda x: x.strip(), inplace = True)
        seeds = system_parameters['SEED']
        for index, sample in enumerate(batch['samples']):
            seed = seeds[index]
            sample.properties['SEED'] = seed
            sample.properties['is_hit'] = 0
            sample.properties['batch'] = batch['number']
        double_compact_objects = pd.read_csv(folder + '/BSE_Double_Compact_Objects.csv', skiprows = 2)
        double_compact_objects.rename(columns = lambda x: x.strip(), inplace = True)
        #Generally, this is the line you would want to change.
        dns = double_compact_objects[np.logical_and(double_compact_objects['Merges_Hubble_Time'] == 1, \
            np.logical_and(double_compact_objects['Stellar_Type_1'] == 14, double_compact_objects['Stellar_Type_2'] == 14))]
        interesting_systems_seeds = set(dns['SEED'])
        for sample in batch['samples']:
            if sample.properties['SEED'] in interesting_systems_seeds:
                sample.properties['is_hit'] = 1
        return len(dns)
    except IOError as error:
        return 0

If so, how should I approach this. Should I generate the COMPAS binaries first?

avigna commented 2 years ago

Hi! Apologies for the late reply. I think the issue is on our end, rather than on yours. We've made a couple of fixes to the repo (make sure to git pull), but I think we still need to update the stroopwafel libraries. Alternatively, you can download them and link them manually. I will get back to this asap with either a full fix, the pertinent link for the manual download, or both.

avigna commented 2 years ago

Hi again! So there are 3 alternatives:

  1. Download the stroopwafel code directly from here and call to it directly instead of via from stroopwafel import ...,
  2. Find your stroopwaffel install, find the sw.py file and modify it as done here,
  3. or wait 2-3 weeks until one of the stroopwaffel experts updates the pip install egg.

I will come back when option 3 is ready and available.

stellarphysicsandpopulations commented 2 years ago

Thank you, Alejandro! Both for your helpfulness and for giving the apology I should have given... (Indeed sorry to the original questioner for the delay.)

(Hopefully soon there will also be a major update to the Stroopwafel structure for which one of the intents is to make it easier for the COMPAS team to keep the "how to talk with COMPAS" parts up-to-date, when COMPAS itself changes, without needing to be an expert in the rest of the code.)

avigna commented 2 years ago

Hello again! Stroopwafel has now been updated and should work if you do pip install --upgrade stroopwafel. I hope this helps with your problem. Could you try giving it a go again and letting us know if it does?

avigna commented 1 year ago

It's been a few months since this has been open. If there are no further comments/questions regarading this particular issue before September 9th, I will close this issue. If more time is needed or someone wants to keep it open, please let me know.