multidim

class cosmic.sample.sampler.multidim.InitialBinaryTable

Bases: object

classmethod InitialBinaries(m1, m2, porb, ecc, tphysf, kstar1, kstar2, metallicity, **kwargs)

Create single binary

Parameters:
m1float

Primary mass [Msun]

m2float

Secondary mass [Msun]

porbfloat

Orbital period [days]

eccfloat

Eccentricity

tphysffloat

Time to evolve the binary [Myr]

kstar1array

0-14 Initial stellar type of the larger object; main sequence stars are 0 if m < 0.7 Msun and 1 otherwise

kstar2array

0-14 Initial stellar type of the smaller object; main sequence stars are 0 if m < 0.7 Msun and 1 otherwise

metallicityfloat

Metallicity of the binaries; Z_sun = 0.02

**kwargs
binfracfloat

System-specific probability of the primary star being in a binary

mass0_1,mass0_2,rad1,rad2,lumin1,lumin2, massc1,massc2,radc1,radc2,menv1,menv2,renv1,renv2, ospin1,ospin2,b_0_1,b_0_2,bacc1,bacc2, tacc1,tacc2,epoch1,epoch2,tms1,tms2 bhspin1,bhspin2

Returns:
InitialBinariesDataFrame

Single binary initial conditions

__annotations__ = {}
__dict__ = mappingproxy({'__module__': 'cosmic.sample.initialbinarytable', 'InitialBinaries': <classmethod(<function InitialBinaryTable.InitialBinaries>)>, 'sampler': <classmethod(<function InitialBinaryTable.sampler>)>, '__dict__': <attribute '__dict__' of 'InitialBinaryTable' objects>, '__weakref__': <attribute '__weakref__' of 'InitialBinaryTable' objects>, '__doc__': None, '__annotations__': {}})
__doc__ = None
__module__ = 'cosmic.sample.initialbinarytable'
__weakref__

list of weak references to the object (if defined)

classmethod sampler(format_, *args, **kwargs)

Fetch a method to generate an initial binary sample

Parameters:
formatstr

the method name; Choose from ‘independent’ or ‘multidim’

*args

the arguments necessary for the registered sample method; see help(InitialBinaryTable.sampler(‘independent’) to see the arguments necessary for the independent sample

The available named formats are:
=========== …

Format …

=========== …
independent …

multidim …

=========== …
class cosmic.sample.sampler.multidim.MPIPool(comm=None, use_dill=False)

Bases: BasePool

A processing pool that distributes tasks using MPI.

With this pool class, the master process distributes tasks to worker processes using an MPI communicator. This pool therefore supports parallel processing on large compute clusters and in environments with multiple nodes or computers that each have many processor cores.

This implementation is inspired by @juliohm in this module

Parameters:
commmpi4py.MPI.Comm, optional

An MPI communicator to distribute tasks with. If None, this uses MPI.COMM_WORLD by default.

use_dill: Set `True` to use `dill` serialization. Default is `False`.
__abstractmethods__ = frozenset({})
__doc__ = 'A processing pool that distributes tasks using MPI.\n\n    With this pool class, the master process distributes tasks to worker\n    processes using an MPI communicator. This pool therefore supports parallel\n    processing on large compute clusters and in environments with multiple\n    nodes or computers that each have many processor cores.\n\n    This implementation is inspired by @juliohm in `this module\n    <https://github.com/juliohm/HUM/blob/master/pyhum/utils.py#L24>`_\n\n    Parameters\n    ----------\n    comm : :class:`mpi4py.MPI.Comm`, optional\n        An MPI communicator to distribute tasks with. If ``None``, this uses\n        ``MPI.COMM_WORLD`` by default.\n    use_dill: Set `True` to use `dill` serialization. Default is `False`.\n    '
__init__(comm=None, use_dill=False)
__module__ = 'schwimmbad.mpi'
_abc_impl = <_abc._abc_data object>
close()

Tell all the workers to quit.

static enabled()
map(worker, tasks, callback=None)

Evaluate a function or callable on each task in parallel using MPI.

The callable, worker, is called on each element of the tasks iterable. The results are returned in the expected order (symmetric with tasks).

Parameters:
workercallable

A function or callable object that is executed on each element of the specified tasks iterable. This object must be picklable (i.e. it can’t be a function scoped within a function or a lambda function). This should accept a single positional argument and return a single object.

tasksiterable

A list or iterable of tasks. Each task can be itself an iterable (e.g., tuple) of values or data to pass in to the worker function.

callbackcallable, optional

An optional callback function (or callable) that is called with the result from each worker run and is executed on the master process. This is useful for, e.g., saving results to a file, since the callback is only called on the master thread.

Returns:
resultslist

A list of results from the output of each worker() call.

wait(callback=None)

Tell the workers to wait and listen for the master process. This is called automatically when using MPIPool.map() and doesn’t need to be called by the user.

class cosmic.sample.sampler.multidim.MultiDim

Bases: object

__dict__ = mappingproxy({'__module__': 'cosmic.sample.sampler.multidim', 'initial_sample': <function MultiDim.initial_sample>, 'sample_SFH': <function MultiDim.sample_SFH>, 'set_kstar': <function MultiDim.set_kstar>, '__dict__': <attribute '__dict__' of 'MultiDim' objects>, '__weakref__': <attribute '__weakref__' of 'MultiDim' objects>, '__doc__': None, '__annotations__': {}})
__doc__ = None
__module__ = 'cosmic.sample.sampler.multidim'
__weakref__

list of weak references to the object (if defined)

initial_sample(M1min=0.08, M2min=0.08, M1max=150.0, M2max=150.0, porb_lo=0.15, porb_hi=8.0, rand_seed=0, size=None, nproc=1, pool=None, mp_seeds=None)

Sample initial binary distribution according to Moe & Di Stefano (2017) <http://adsabs.harvard.edu/abs/2017ApJS..230…15M>`_

Parameters:
M1minfloat

minimum primary mass to sample [Msun] DEFAULT: 0.08

M2minfloat

minimum secondary mass to sample [Msun] DEFAULT: 0.08

M1maxfloat

maximum primary mass to sample [Msun] DEFAULT: 150.0

M2maxfloat

maximum primary mass to sample [Msun] DEFAULT: 150.0

porb_lofloat

minimum orbital period to sample [log10(days)]

porb_hifloat

maximum orbital period to sample [log10(days)]

rand_seedint

random seed generator DEFAULT: 0

sizeint, optional

number of evolution times to sample NOTE: this is set in cosmic-pop call as Nstep

Returns:
primary_mass_listarray

array of primary masses with size=size

secondary_mass_listarray

array of secondary masses with size=size

porb_listarray

array of orbital periods in days with size=size

ecc_listarray

array of eccentricities with size=size

mass_singlesfloat

Total mass in single stars needed to generate population

mass_binariesfloat

Total mass in binaries needed to generate population

n_singlesint

Number of single stars needed to generate a population

n_binariesint

Number of binaries needed to generate a population

binfrac_listarray

array of binary probabilities based on primary mass and period with size=size

sample_SFH(SF_start=13700.0, SF_duration=0.0, met=0.02, size=None)

Sample an evolution time for each binary based on a user-specified time at the start of star formation and the duration of star formation. The default is a burst of star formation 13,700 Myr in the past.

Parameters:
SF_startfloat

Time in the past when star formation initiates in Myr

SF_durationfloat

Duration of constant star formation beginning from SF_Start in Myr

metfloat

metallicity of the population [Z_sun = 0.02] Default: 0.02

sizeint, optional

number of evolution times to sample NOTE: this is set in cosmic-pop call as Nstep

Returns:
tphysarray

array of evolution times of size=size

metallicityarray

array of metallicities

set_kstar(mass)

Initialize stellar types according to BSE classification kstar=1 if M>=0.7 Msun; kstar=0 if M<0.7 Msun

Parameters:
massarray

array of masses

Returns:
kstararray

array of initial stellar types

class cosmic.sample.sampler.multidim.MultiPool(processes=None, initializer=None, initargs=(), **kwargs)

Bases: Pool

A modified version of multiprocess.pool.Pool that has better behavior with regard to KeyboardInterrupts in the map() method.

NOTE: This is no longer built off of the standard library multiprocessing.pool.Pool – this uses the version from multiprocess, which uses dill to pickle objects instead of the standard library pickle.

Parameters:
processesint, optional

The number of worker processes to use; defaults to the number of CPUs.

initializercallable, optional

If specified, a callable that will be invoked by each worker process when it starts.

initargsiterable, optional

Arguments for initializer; it will be called as initializer(*initargs).

kwargs:

Extra arguments passed to the multiprocess.pool.Pool superclass.

__annotations__ = {}
__doc__ = '\n    A modified version of :class:`multiprocess.pool.Pool` that has better\n    behavior with regard to ``KeyboardInterrupts`` in the :func:`map` method.\n\n    NOTE: This is no longer built off of the standard library\n    :class:`multiprocessing.pool.Pool` -- this uses the version from `multiprocess`,\n    which uses `dill` to pickle objects instead of the standard library `pickle`.\n\n    Parameters\n    ----------\n    processes : int, optional\n        The number of worker processes to use; defaults to the number of CPUs.\n    initializer : callable, optional\n        If specified, a callable that will be invoked by each worker process\n        when it starts.\n    initargs : iterable, optional\n        Arguments for ``initializer``; it will be called as\n        ``initializer(*initargs)``.\n    kwargs:\n        Extra arguments passed to the :class:`multiprocess.pool.Pool` superclass.\n\n    '
__init__(processes=None, initializer=None, initargs=(), **kwargs)
__module__ = 'schwimmbad.multiprocessing'
static enabled()
map(func, iterable, chunksize=None, callback=None)

Equivalent to the built-in map() function and multiprocessing.pool.Pool.map(), without catching KeyboardInterrupt.

Parameters:
workercallable

A function or callable object that is executed on each element of the specified tasks iterable. This object must be picklable (i.e. it can’t be a function scoped within a function or a lambda function). This should accept a single positional argument and return a single object.

tasksiterable

A list or iterable of tasks. Each task can be itself an iterable (e.g., tuple) of values or data to pass in to the worker function.

callbackcallable, optional

An optional callback function (or callable) that is called with the result from each worker run and is executed on the master process. This is useful for, e.g., saving results to a file, since the callback is only called on the master thread.

Returns:
resultslist

A list of results from the output of each worker() call.

wait_timeout = 3600
class cosmic.sample.sampler.multidim.Worker

Bases: object

__call__(task)

Call self as a function.

__dict__ = mappingproxy({'__module__': 'cosmic.sample.sampler.multidim', '__call__': <function Worker.__call__>, '_sample_initial_pop': <function Worker._sample_initial_pop>, '__dict__': <attribute '__dict__' of 'Worker' objects>, '__weakref__': <attribute '__weakref__' of 'Worker' objects>, '__doc__': None, '__annotations__': {}})
__doc__ = None
__module__ = 'cosmic.sample.sampler.multidim'
__weakref__

list of weak references to the object (if defined)

_sample_initial_pop(M1min, M2min, M1max, M2max, porb_hi, porb_lo, size, seed)
cosmic.sample.sampler.multidim.get_multidim_sampler(final_kstar1, final_kstar2, rand_seed, nproc, SF_start, SF_duration, met, size, **kwargs)

adapted version of Maxwell Moe’s IDL code that generates a population of single and binary stars

Below is the adapted version of Maxwell Moe’s IDL code that generates a population of single and binary stars based on the paper Mind your P’s and Q’s By Maxwell Moe and Rosanne Di Stefano

The python code has been adopted by Mads Sørensen

Version history: V. 0.1; 2017/02/03 By Mads Sørensen - This is a pure adaption from IDL to Python. - The function idl_tabulate is similar to the IDL function int_tabulated except, this function seems to be slightly more exact in its solution. Therefore, relative to the IDL code, there are small numerical differences.

Comments below beginning with ; is the original nodes by Maxwell Moe. Please read these careful for understanding the script. ; NOTE - This version produces only the statistical distributions of ; single stars, binaries, and inner binaries in hierarchical triples. ; Outer tertiaries in hierarchical triples are NOT generated. ; Moreover, given a set of companions, all with period P to ; primary mass M1, this version currently uses an approximation to ; determine the fraction of those companions that are inner binaries ; vs. outer triples. Nevertheless, this approximation reproduces ; the overall multiplicity statistics. ; Step 1 - Tabulate probably density functions of periods, ; mass ratios, and eccentricities based on ; analytic fits to corrected binary star populations. ; Step 2 - Implement Monte Carlo method to generate stellar ; population from those density functions.

Parameters:
final_kstar1list or int

Int or list of final kstar1

final_kstar2list or int

Int or list of final kstar2

rand_seedint

Int to seed random number generator

nprocint

Number of processors to use to generate population

SF_startfloat

Time in the past when star formation initiates in Myr

SF_durationfloat

Duration of constant star formation beginning from SF_Start in Myr

metfloat

Sets the metallicity of the binary population where solar metallicity is 0.02

sizeint

Size of the population to sample

**porb_lofloat

Lower limit in days for the orbital period distribution

**porb_hi: `float`

Upper limit in days for the orbital period distribution

Returns:
InitialBinaryTablepandas.DataFrame

DataFrame in the format of the InitialBinaryTable

mass_singlesfloat

Total mass in single stars needed to generate population

mass_binariesfloat

Total mass in binaries needed to generate population

n_singlesint

Number of single stars needed to generate a population

n_binariesint

Number of binaries needed to generate a population

cosmic.sample.sampler.multidim.register_sampler(data_format, data_class, function, force=False, usage=None)

Register a new method to InitialBinaryTable.sampler() for a given format

Parameters:
data_formatstr

name of the format to be registered

data_classtype

the class that the sampler returns

functioncallable

the method to call from InitialBinaryTable.sampler()

forcebool, optional

overwrite existing registration for data_format if found, default: False