Skip to content

Instantly share code, notes, and snippets.

@avivajpeyi
Created November 14, 2022 04:23
Show Gist options
  • Select an option

  • Save avivajpeyi/ad9f45c803829ecbc9b6e984367c88eb to your computer and use it in GitHub Desktop.

Select an option

Save avivajpeyi/ad9f45c803829ecbc9b6e984367c88eb to your computer and use it in GitHub Desktop.
COMPAS py interface demo

installing

To install COMPAS, it would be nice if all the user needs to do is:

pip install compas

This can be configured to not only install COMPAS python code, but also the CPP code. It can also be confiugured to find user's boost libs etc (no need to manually edit the make-file).

running

Then a user can run COMPAS with:

$ COMPAS --number-of-systems 50

0: Stars merged: (Main_Sequence_>_0.7 -> Main_Sequence_>_0.7) + (Main_Sequence_>_0.7 -> Main_Sequence_>_0.7)
1: Unbound binary: (Main_Sequence_>_0.7 -> Neutron_Star) + (Main_Sequence_>_0.7 -> Thermally_Pulsing_Asymptotic_Giant_Branch)
2: Unbound binary: (Main_Sequence_>_0.7 -> Black_Hole) + (Main_Sequence_>_0.7 -> Main_Sequence_>_0.7)
3: Unbound binary: (Main_Sequence_>_0.7 -> Neutron_Star) + (Main_Sequence_>_0.7 -> Main_Sequence_>_0.7)
4: Unbound binary: (Main_Sequence_>_0.7 -> Black_Hole) + (Main_Sequence_>_0.7 -> Main_Sequence_>_0.7)
5: Allowed time exceeded: (Main_Sequence_>_0.7 -> Carbon-Oxygen_White_Dwarf) + (Main_Sequence_<=_0.7 -> Main_Sequence_<=_0.7)
6: Unbound binary: (Main_Sequence_>_0.7 -> Neutron_Star) + (Main_Sequence_>_0.7 -> Main_Sequence_>_0.7)
7: Double White Dwarf: (Main_Sequence_>_0.7 -> Carbon-Oxygen_White_Dwarf) + (Main_Sequence_>_0.7 -> Carbon-Oxygen_White_Dwarf)
8: Unbound binary: (Main_Sequence_>_0.7 -> Black_Hole) + (Main_Sequence_<=_0.7 -> Main_Sequence_<=_0.7)
9: Stars merged: (Main_Sequence_>_0.7 -> Naked_Helium_Star_Giant_Branch) + (Main_Sequence_>_0.7 -> Main_Sequence_>_0.7)

By including the COMPAS python in an installable, one can do something like this:

$ print_compas_summary COMPAS_Output.h5

Summary of HDF5 file /d/compas/h5out.h5
=======================================

File size    : 2.1520 GB
Last modified: 2021-07-26 16:25:12.928401

COMPAS Filename              Columns   Entries   Unique SEEDs
--------------------------   -------   -------   ------------
Run_Details                      346        30
BSE_Common_Envelopes              73    582485         476514
BSE_Double_Compact_Objects        12      8725           8725
BSE_RLOF                          34   2997481         536332
BSE_Supernovae                    32    103000          87162
BSE_Switch_Log                    13   7472234         956623
BSE_System_Parameters             33   1050000        1050000

python interface

If nicely configured, you may also be able to do this from within python:

import compas


compas_output = compas.CompasOutput(h5path)

print(compas_output)
Summary of CompasOutput object loaded from file /d/compas/h5out.h5
==================================================================

File size    : 2.1520 GB
Last modified: 2021-07-26 16:25:12.928401

COMPAS Filename              Columns   Entries   Unique SEEDs
--------------------------   -------   -------   ------------
Run_Details                      346        30
BSE_Common_Envelopes              73    582485         476514
BSE_Double_Compact_Objects        12      8725           8725
BSE_RLOF                          34   2997481         536332
BSE_Supernovae                    32    103000          87162
BSE_Switch_Log                    13   7472234         956623
BSE_System_Parameters             33   1050000        1050000

And if you wanted the 0th binary:

binary_0 = compas_output.iloc[0]

Or all the binaries with seeds:

binaries_by_seeds = compas_output.iseed[[1222, 2331, 2999]]

The package could also be written to do something like:

from compas.cosmic_integration import CosmicIntegrator


universe = CosmicIntegrator(compas_output=compas_output, **star_formation_parameters)
universe.plot_detection_matrix()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment