evolve
- class cosmic.evolve.Evolve¶
Bases:
object- __dict__ = mappingproxy({'__module__': 'cosmic.evolve', '__init__': <function Evolve.__init__>, 'evolve': <classmethod(<function Evolve.evolve>)>, '__dict__': <attribute '__dict__' of 'Evolve' objects>, '__weakref__': <attribute '__weakref__' of 'Evolve' objects>, '__doc__': None, '__annotations__': {}})¶
- __doc__ = None¶
- __init__()¶
initialize Evolve
- __module__ = 'cosmic.evolve'¶
- __weakref__¶
list of weak references to the object (if defined)
- classmethod evolve(initialbinarytable, pool=None, bpp_columns=None, bcm_columns=None, dt_mass_modifiers=[(40, 70, 0.3), (70, inf, 0.1)], **kwargs)¶
After setting a number of initial conditions we evolve the system.
- Parameters:
- initialbinarytableDataFrame
Initial conditions of the binary
- poolMultiprocessing pool
Pool of workers to use to evolve systems in parallel
- bpp_columnslist, optional, default: None
Columns to save in the bpp table (key evolutionary stage table)
- bcm_columnslist, optional, default: None
Columns to save in the bcm table (detailed evolution table)
- dt_modifierslist of tuples, optional, default: [(40, 70, 0.3), (70, np.inf, 0.1)]
List of tuples specifying the mass ranges and corresponding modifiers for the timestep size. Our recommended default improves the numerical stability at higher masses. Each tuple should be of the form (m_low, m_high, mod) and will modify the default timestep by a factor of mod for systems with a primary mass in the range m_low <= mass_1 < m_high. For example, (40, 70, 0.3) would multiply the default timestep size by 0.3 for systems with primary mass between [40, 70) solar masses. We apply the modifier to the pts1, pts2, and pts3 parameters which control the timestep size in different evolutionary phases. These changes are logged in the initial conditions table so you can keep track of which systems had their timesteps modified. Avoid overlapping mass ranges for different modifiers as this will result in multiple modifiers being applied in the overlap region. NOTE: these modifiers are only applied to columns which aren’t present in the initialbinarytable that is passed in (i.e. they only modify values provided by a BSEDict or params.ini file)
- **kwargs:
There are three ways to tell evolve and thus the fortran what you want all the flags and other BSE specific parameters to be. If you pass both a dictionary of flags and/or a inifile and a table with the BSE parameters in the columns, the column values will be overwritten by what is in the dictionary or ini file.
NUMBER 1: PASS A DICTIONARY OF FLAGS
BSEDict
NUMBER 2: PASS A PANDAS DATA FRAME WITH PARAMS DEFINED AS COLUMNS
All you need is the initialbinarytable if the all the BSE parameters are defined as columns
NUMBER 3: PASS PATH TO A INI FILE WITH THE FLAGS DEFINED
params
You can also add a progress bar by setting: progress=True
- randomseedint, optional, default let numpy choose for you
If you would like the random seed that the underlying fortran code uses to be the same for all of the initial conditions you passed then you can send this keyword argument in. It is recommended to just let numpy choose a random number as the Fortran random seed and then this number will be returned as a column in the initial binary table so that you can reproduce the results.
- nprocint, optional, default: 1
number of CPUs to use to evolve systems in parallel
- idxint, optional, default: 0
initial index of the bcm/bpp arrays
- dtpfloat, optional: default: tphysf
timestep size in Myr for bcm output where tphysf is total evolution time in Myr
- n_per_blockint, optional, default: -1
number of systems to evolve in a block with _evolve_multi_system, to allow larger multiprocessing queues and reduced overhead. If less than 1 use _evolve_single_system
- Returns:
- output_bpp
pandas.DataFrame Table of key evolutionary stages for each binary
- output_bcm
pandas.DataFrame Table of detailed evolution for each binary
- initialbinarytableDataFrame
Initial conditions for each binary
- output_bpp
- class cosmic.evolve.MultiPool(processes=None, initializer=None, initargs=(), **kwargs)¶
Bases:
PoolA modified version of
multiprocess.pool.Poolthat has better behavior with regard toKeyboardInterruptsin themap()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 asinitializer(*initargs).- kwargs:
Extra arguments passed to the
multiprocess.pool.Poolsuperclass.
- __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 andmultiprocessing.pool.Pool.map(), without catchingKeyboardInterrupt.- Parameters:
- workercallable
A function or callable object that is executed on each element of the specified
tasksiterable. This object must be picklable (i.e. it can’t be a function scoped within a function or alambdafunction). 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.evolve.Path(*args, **kwargs)¶
Bases:
PurePathPurePath subclass that can make system calls.
Path represents a filesystem path but unlike PurePath, also offers methods to do system calls on path objects. Depending on your system, instantiating a Path will return either a PosixPath or a WindowsPath object. You can also instantiate a PosixPath or WindowsPath directly, but cannot instantiate a WindowsPath on a POSIX system or vice versa.
- __doc__ = 'PurePath subclass that can make system calls.\n\n Path represents a filesystem path but unlike PurePath, also offers\n methods to do system calls on path objects. Depending on your system,\n instantiating a Path will return either a PosixPath or a WindowsPath\n object. You can also instantiate a PosixPath or WindowsPath directly,\n but cannot instantiate a WindowsPath on a POSIX system or vice versa.\n '¶
- __enter__()¶
- __exit__(t, v, tb)¶
- __module__ = 'pathlib'¶
- static __new__(cls, *args, **kwargs)¶
Construct a PurePath from one or several strings and or existing PurePath objects. The strings and path objects are combined so as to yield a canonicalized path, which is incorporated into the new PurePath object.
- __slots__ = ()¶
- _accessor = <pathlib._NormalAccessor object>¶
- _make_child_relpath(part)¶
- absolute()¶
Return an absolute version of this path. This function works even if the path doesn’t point to anything.
No normalization is done, i.e. all ‘.’ and ‘..’ will be kept along. Use resolve() to get the canonical path to a file.
- chmod(mode, *, follow_symlinks=True)¶
Change the permissions of the path, like os.chmod().
- classmethod cwd()¶
Return a new path pointing to the current working directory (as returned by os.getcwd()).
- exists()¶
Whether this path exists.
- expanduser()¶
Return a new path with expanded ~ and ~user constructs (as returned by os.path.expanduser)
- glob(pattern)¶
Iterate over this subtree and yield all existing files (of any kind, including directories) matching the given relative pattern.
- group()¶
Return the group name of the file gid.
- hardlink_to(target)¶
Make this path a hard link pointing to the same file as target.
Note the order of arguments (self, target) is the reverse of os.link’s.
- classmethod home()¶
Return a new path pointing to the user’s home directory (as returned by os.path.expanduser(‘~’)).
- is_block_device()¶
Whether this path is a block device.
- is_char_device()¶
Whether this path is a character device.
- is_dir()¶
Whether this path is a directory.
- is_fifo()¶
Whether this path is a FIFO.
- is_file()¶
Whether this path is a regular file (also True for symlinks pointing to regular files).
- is_mount()¶
Check if this path is a POSIX mount point
- is_socket()¶
Whether this path is a socket.
- is_symlink()¶
Whether this path is a symbolic link.
- iterdir()¶
Iterate over the files in this directory. Does not yield any result for the special paths ‘.’ and ‘..’.
- lchmod(mode)¶
Like chmod(), except if the path points to a symlink, the symlink’s permissions are changed, rather than its target’s.
- link_to(target)¶
Make the target path a hard link pointing to this path.
Note this function does not make this path a hard link to target, despite the implication of the function and argument names. The order of arguments (target, link) is the reverse of Path.symlink_to, but matches that of os.link.
Deprecated since Python 3.10 and scheduled for removal in Python 3.12. Use hardlink_to() instead.
- lstat()¶
Like stat(), except if the path points to a symlink, the symlink’s status information is returned, rather than its target’s.
- mkdir(mode=511, parents=False, exist_ok=False)¶
Create a new directory at this given path.
- open(mode='r', buffering=-1, encoding=None, errors=None, newline=None)¶
Open the file pointed by this path and return a file object, as the built-in open() function does.
- owner()¶
Return the login name of the file owner.
- read_bytes()¶
Open the file in bytes mode, read it, and close the file.
- read_text(encoding=None, errors=None)¶
Open the file in text mode, read it, and close the file.
- readlink()¶
Return the path to which the symbolic link points.
- rename(target)¶
Rename this path to the target path.
The target path may be absolute or relative. Relative paths are interpreted relative to the current working directory, not the directory of the Path object.
Returns the new Path instance pointing to the target path.
- replace(target)¶
Rename this path to the target path, overwriting if that path exists.
The target path may be absolute or relative. Relative paths are interpreted relative to the current working directory, not the directory of the Path object.
Returns the new Path instance pointing to the target path.
- resolve(strict=False)¶
Make the path absolute, resolving all symlinks on the way and also normalizing it (for example turning slashes into backslashes under Windows).
- rglob(pattern)¶
Recursively yield all existing files (of any kind, including directories) matching the given relative pattern, anywhere in this subtree.
- rmdir()¶
Remove this directory. The directory must be empty.
- samefile(other_path)¶
Return whether other_path is the same or not as this file (as returned by os.path.samefile()).
- stat(*, follow_symlinks=True)¶
Return the result of the stat() system call on this path, like os.stat() does.
- symlink_to(target, target_is_directory=False)¶
Make this path a symlink pointing to the target path. Note the order of arguments (link, target) is the reverse of os.symlink.
- touch(mode=438, exist_ok=True)¶
Create this file with the given access mode, if it doesn’t exist.
- unlink(missing_ok=False)¶
Remove this file or link. If the path is a directory, use rmdir() instead.
- write_bytes(data)¶
Open the file in bytes mode, write to it, and close the file.
- write_text(data, encoding=None, errors=None, newline=None)¶
Open the file in text mode, write to it, and close the file.
- cosmic.evolve._evolve_multi_system(f)¶
- cosmic.evolve._evolve_single_system(f, zpars=None)¶
- class cosmic.evolve.partial¶
Bases:
objectpartial(func, *args, **keywords) - new function with partial application of the given arguments and keywords.
- __call__(*args, **kwargs)¶
Call self as a function.
- __class_getitem__()¶
See PEP 585
- __delattr__(name, /)¶
Implement delattr(self, name).
- __dict__ = mappingproxy({'__new__': <built-in method __new__ of type object>, '__repr__': <slot wrapper '__repr__' of 'functools.partial' objects>, '__call__': <slot wrapper '__call__' of 'functools.partial' objects>, '__getattribute__': <slot wrapper '__getattribute__' of 'functools.partial' objects>, '__setattr__': <slot wrapper '__setattr__' of 'functools.partial' objects>, '__delattr__': <slot wrapper '__delattr__' of 'functools.partial' objects>, '__reduce__': <method '__reduce__' of 'functools.partial' objects>, '__setstate__': <method '__setstate__' of 'functools.partial' objects>, '__class_getitem__': <method '__class_getitem__' of 'functools.partial' objects>, 'func': <member 'func' of 'functools.partial' objects>, 'args': <member 'args' of 'functools.partial' objects>, 'keywords': <member 'keywords' of 'functools.partial' objects>, '__vectorcalloffset__': <member '__vectorcalloffset__' of 'functools.partial' objects>, '__dict__': <attribute '__dict__' of 'functools.partial' objects>, '__doc__': 'partial(func, *args, **keywords) - new function with partial application\n of the given arguments and keywords.\n', '__module__': 'functools', '__annotations__': {}})¶
- __doc__ = 'partial(func, *args, **keywords) - new function with partial application\n of the given arguments and keywords.\n'¶
- __getattribute__(name, /)¶
Return getattr(self, name).
- __module__ = 'functools'¶
- __new__(*args, **kwargs)¶
- __reduce__()¶
Helper for pickle.
- __repr__(/)¶
Return repr(self).
- __setattr__(name, value, /)¶
Implement setattr(self, name, value).
- __setstate__()¶
- __vectorcalloffset__¶
- args¶
tuple of arguments to future partial calls
- func¶
function object to use in future partial calls
- keywords¶
dictionary of keyword arguments to future partial calls
- cosmic.evolve.populate_tracks(track_list, is_he=False)¶
Populate Fortran track data structures from a list of Python track dictionaries and pass them to the COSMIC Fortran backend.
- Parameters:
- track_listlist of dict
- Each dictionary must contain the following keys:
‘filename’ : str
‘initial_mass’ : float
‘initial_Y’ : float
‘initial_Z’ : float
‘Fe_div_H’ : float
‘alpha_div_Fe’ : float
‘v_div_vcrit’ : float
‘ntrack’ : int
‘neep’ : int
‘ncol’ : int
‘eep’ : array-like of shape (neep,)
‘tr’ : array-like of shape (ncol, ntrack)
‘cols’ : list of str of length ncol
- is_hebool, default=False
Indicates whether the tracks are helium-enriched.
- Returns:
- None
The function calls the Fortran subroutine _evolvebin.c_m_interface.set_tracks_from_python and populates the Fortran-side track arrays. The Python-side arrays are used only as temporary buffers for the call.
- cosmic.evolve.read_tracks_for_METISSE(path_to_tracks, IBT_Z, z_accuracy_limit, is_he)¶
load in the metallicity, format, and eep files
- Parameters:
- path_to_tracksstr
Direct path to where all single star data and metallicty/format files are stored for hydrogen-rich stars
- IBT_Zfloat
Metallicity from the initialbinarytable
- z_accuracy_limitfloat
Tolerance for match in metallicity value
- is_hebool, default=False
Indicates whether the tracks are helium-enriched.
- Returns
- ——-
None
- cosmic.evolve.set_checkstates(timestep_conditions=[])¶
A function which will detemine different time resolution for different states
- Parameters:
- timestep_conditions(list) default empty (no dynamic dtp setting)
a nested list of the many different time resolutions and conditions for which you would like to apply those time resolution, e.g.,
>>> timestep_conditions = [['20.0<mass_1<25.5', '15.5>mass_2>10.0', 'dtp=1.0'], >>> ['kstar_1=14', 'lum_1>10.0', 'dtp=0.01'], >>> ['2>=binstate>=1', 'dtp=None']]
The first two sets of conditons would be done in a AND fashion. The last condition would end time resolution for the BCM array and it would skip to only printing the final state