Pyflation - Cosmological simulations in Python
Pyflation is a python package to simulate cosmological perturbations in the early universe. Using the Klein-Gordon equations for both first and second order perturbations, the evolution and behaviour of these perturbations can be studied.
The main entry point to this package is the cosmomodels module, which contains the main simulation classes. Configuration of the simulation runs can be changed in the configuration.py and run_config.py files.
For more information please visit http://pyflation.ianhuston.net.
cmpotentials.py - Cosmological potentials for cosmomodels.py
Provides functions which can be used with cosmomodels.py. Default parameter values are included but can also be specified as a dictionary.
Return (V, dV/dphi, d2V/dphi2, d3V/dphi3) for V=1/2 m^2 phi^2 ( 1 + c*sech((phi-phi_b) / d) where m is the mass of the inflaton field and c, d and phi_b are provided. Form is taken from Chen etal. arxiv:0801.3295.
Parameters : | y : array
params : dict
|
---|---|
Returns : | U, dUdphi, d2Udphi2, d3Udphi3 : tuple of arrays
|
Notes
m can be specified in the dictionary params or otherwise it defaults to the mass as normalized with the WMAP spectrum Pr = 2.457e-9 at the WMAP pivot scale of 0.002 Mpc^-1.
Return (V, dV/dphi, d2V/dphi2, d3V/dphi3) for V=1/2 m^2 phi^2 ( 1 + c*sech((phi-phi_b) / d) where m is the mass of the inflaton field and c, d and phi_b are provided. Form is taken from Chen etal. arxiv:0801.3295.
Parameters : | y : array
params : dict
|
---|---|
Returns : | U, dUdphi, d2Udphi2, d3Udphi3 : tuple of arrays
|
Notes
m can be specified in the dictionary params or otherwise it defaults to the mass as normalized with the WMAP spectrum Pr = 2.457e-9 at the WMAP pivot scale of 0.002 Mpc^-1.
Return the potential and its first three derivatives for a hilltop axion model.
The potential is given by
where the parameters are Lambda, m, and f . Needs nfields=2.
Parameters : | y: array :
params: dict :
|
---|---|
Returns : | U, dUdphi, d2Udphi2, d3Udphi3: tuple of arrays :
|
Return (V, dV/dphi, d2V/dphi2, d3V/dphi3) for hybrid potential V = -m^2/2 phi^2 +lambda/4 phi^4
Parameters : | y : array
params : dict
|
---|---|
Returns : | U, dUdphi, d2Udphi2, d3Udphi3 : tuple of arrays
|
Notes
lambda can be specified in the dictionary params or otherwise it defaults to the value as normalized with the WMAP spectrum Pr = 2.457e-9 at the WMAP pivot scale of 0.002 Mpc^-1.
mass can be specified in the dictionary params or otherwise it defaults to the mass as normalized with the WMAP spectrum Pr = 2.457e-9 at the WMAP pivot scale of 0.002 Mpc^-1.
Return (V, dV/dphi, d2V/dphi2, d3V/dphi3) for V = 1/2 m1^2 phi^2 + 1/2 m2^2 chi^2 where m1 and m2 are the masses of the fields. Needs nfields=2.
Parameters : | y : array
params : dict
|
---|---|
Returns : | U, dUdphi, d2Udphi2, d3Udphi3 : tuple of arrays
|
Return the potential and its first three derivatives for the hybrid quartic model.
The potential is given by
where the parameter are . Needs nfields=2.
Parameters : | y : array
params : dict
|
---|---|
Returns : | U, dUdphi, d2Udphi2, d3Udphi3 : tuple of arrays
|
Return the potential and its first three derivatives for an inflection point model.
The potential is given by
where and the parameters are . Needs nfields=2.
Parameters : | y : array
params : dict
|
---|---|
Returns : | U, dUdphi, d2Udphi2, d3Udphi3 : tuple of arrays
|
Return (V, dV/dphi, d2V/dphi2, d3V/dphi3) for V=1/4 lambda phi^4 for a specified lambda.
Parameters : | y : array
params : dict
|
---|---|
Returns : | U, dUdphi, d2Udphi2, d3Udphi3 : tuple of arrays
|
Notes
lambda can be specified in the dictionary params or otherwise it defaults to the value as normalized with the WMAP spectrum Pr = 2.457e-9 at the WMAP pivot scale of 0.002 Mpc^-1.
Return (V, dV/dphi, d2V/dphi2, d3V/dphi3) for Linde potential V = -m^2/2 phi^2 +lambda/4 phi^4 + m^4/4lambda
Parameters : | y : array
params : dict
|
---|---|
Returns : | U, dUdphi, d2Udphi2, d3Udphi3 : tuple of arrays
|
Notes
lambda can be specified in the dictionary params or otherwise it defaults to the value as normalized with the WMAP spectrum Pr = 2.457e-9 at the WMAP pivot scale of 0.002 Mpc^-1.
mass can be specified in the dictionary params or otherwise it defaults to the mass as normalized with the WMAP spectrum Pr = 2.457e-9 at the WMAP pivot scale of 0.002 Mpc^-1.
Return (V, dV/dphi, d2V/dphi2, d3V/dphi3) for V=1/2 m^2 phi^2 where m is the mass of the inflaton field.
Parameters : | y : array
params : dict
Returns : ——- : U, dUdphi, d2Udphi2, d3Udphi3 : tuple of arrays
|
---|
Notes
m can be specified in the dictionary params or otherwise it defaults to the mass as normalized with the WMAP spectrum Pr = 2.457e-9 at the WMAP pivot scale of 0.002 Mpc^-1.
Return (V, dV/dphi, d2V/dphi2, d3V/dphi3) for V=1/2 m^2 phi^2 + V0 where m is the mass of the inflaton field.
Parameters : | y : array
params : dict
|
---|---|
Returns : | U, dUdphi, d2Udphi2, d3Udphi3 : tuple of arrays
|
Notes
m can be specified in the dictionary params or otherwise it defaults to the mass as normalized with the WMAP spectrum Pr = 2.457e-9 at the WMAP pivot scale of 0.002 Mpc^-1.
Return (V, dV/dphi, d2V/dphi2, d3V/dphi3) for V = sum_lpha 1/2 m^2 phi_lpha^2 where m is the mass of each of the fields.
Parameters : | y : array
params : dict
|
---|---|
Returns : | U, dUdphi, d2Udphi2, d3Udphi3 : tuple of arrays
|
Notes
m can be specified in the dictionary params or otherwise it defaults to the mass as normalized with the WMAP spectrum Pr = 2.457e-9 at the WMAP pivot scale of 0.002 Mpc^-1.
Return (V, dV/dphi, d2V/dphi2, d3V/dphi3) for V= sigma phi^(2/3) for a specified sigma.
Parameters : | y : array
params : dict
|
---|---|
Returns : | U, dUdphi, d2Udphi2, d3Udphi3 : tuple of arrays
|
Notes
sigma can be specified in the dictionary params or otherwise it defaults to the value as normalized with the WMAP spectrum Pr = 2.457e-9 at the WMAP pivot scale of 0.002 Mpc^-1.
Return the potential and its first three derivatives for a product exponential potential.
The potential is given by
where the parameters are . Needs nfields=2.
Parameters : | y: array :
params: dict :
|
---|---|
Returns : | U, dUdphi, d2Udphi2, d3Udphi3: tuple of arrays :
|
Return (V, dV/dphi, d2V/dphi2, d3V/dphi3) for V= 1/2(m1^2 phi^2 + 1/2 l1 phi^4 + m2^2 chi^2 + 1/2 l2 chi^4) where m1, m2, l1, l2 are parameters. Needs nfields=2.
Parameters : | y : array
params : dict
|
---|---|
Returns : | U, dUdphi, d2Udphi2, d3Udphi3 : tuple of arrays
|
Return (V, dV/dphi, d2V/dphi2, d3V/dphi3) for V=1/2 m^2 phi^2 ( 1 + c*sin(phi / d) ) where m is the mass of the inflaton field and c, d and phi_b are provided. Form is taken from Chen etal. arxiv:0801.3295.
Parameters : | y : array
params : dict
|
---|---|
Returns : | U, dUdphi, d2Udphi2, d3Udphi3 : tuple of arrays
|
Notes
m can be specified in the dictionary params or otherwise it defaults to the mass as normalized with the WMAP spectrum Pr = 2.457e-9 at the WMAP pivot scale of 0.002 Mpc^-1.
Return (V, dV/dphi, d2V/dphi2, d3V/dphi3) for V=V0 - g phi - 1/2 m^2 chi^2 where g is a parameter and m is the mass of the chi field. Needs nfields=2.
Parameters : | y : array
params : dict
|
---|---|
Returns : | U, dUdphi, d2Udphi2, d3Udphi3 : tuple of arrays
|
Return (V, dV/dphi, d2V/dphi2, d3V/dphi3) for V=1/2 m^2 phi^2 ( 1 + c*tanh((phi-phi_s) / d) where m is the mass of the inflaton field and c, d and phi_s are provided. Form is taken from Chen etal. arxiv:0801.3295.
Parameters : | y : array
params : dict
|
---|---|
Returns : | U, dUdphi, d2Udphi2, d3Udphi3 : tuple of arrays
|
Notes
m can be specified in the dictionary params or otherwise it defaults to the mass as normalized with the WMAP spectrum Pr = 2.457e-9 at the WMAP pivot scale of 0.002 Mpc^-1.
Configuration file
The main configuration options are for logging. By changing _debug to 1 (default is 0) much more debugging information will be added to the log files. The overall logging level can also be set using the LOGLEVEL variable. This level can be overridden using command line options to the scripts.
cosmographs.py - Graphing functions for pyflation package
This module provides helper functions for graphing the results of pyflation simulations using the Matplotlib package (http://matplotlib.sf.net).
Especially useful is the multi_format_save function which saves the specified figure to different formats as requested.
Bases: exceptions.StandardError
Generic error for graphing facilities.
Bases: matplotlib.ticker.LogFormatter, object
Extends pyplot.LogFormatter to use tex notation for tick labels.
Create a figure using mathcal{N} on the x-axis.
Parameters : | ts: list of arrays :
ys: list of arrays :
fig: Pylab figure instance, optional :
plot_fn: function, optional :
models_legends: list, optional :
ylabel: string, optional :
size: string, optional :
ls: list, optional :
halfticks: boolean, optional :
Returns : ——- : fig: the figure instance : |
---|
Create a generic figure with standard x-axis.
Parameters : | xs: list of arrays :
ys: list of arrays :
fig: Pylab figure instance, optional :
plot_fn: function, optional :
models_legends: list, optional :
xlabel: string, optional :
ylabel: string, optional :
size: string, optional :
ls: list, optional :
halfticks: boolean, optional :
|
---|---|
Returns : | fig: the figure instance : |
Attach a legend to the figure specified outlining the k modes used.
Save figure in multiple formats at once.
Parameters : | filenamestub: String :
fig: Matplotlib figure object, optional :
formats: list-like, optional :
Other kwargs: These are provided to matplotlib.pylab.savefig. :
|
---|---|
Returns : | filenames: list :
|
cosmomodels.py - Cosmological Model simulations
Provides classes for modelling cosmological inflationary scenarios. Especially important classes are:
The make_wrapper_model() function takes a filename and returns a model instance corresponding to the one stored in the file. This allows easier access to the results than through a direct inspection of the HDF5 results file.
Bases: pyflation.cosmomodels.CosmologicalModel
y[0] - phi_0 : Background inflaton y[1] - dphi_0/deta : First deriv of phi y[2] - a : Scale Factor
Bases: pyflation.cosmomodels.PhiModels
y[0] - phi_0 : Background inflaton y[1] - dphi_0/dn : First deriv of phi y[2] - H: Hubble parameter
Bases: pyflation.cosmomodels.PhiModels
First order model using efold as time variable with multiple fields.
nfields holds the number of fields and the yresult variable is then laid out as follows:
yresult[0:nfields*2] : background fields and derivatives yresult[nfields*2] : Hubble variable H yresult[nfields*2 + 1:] : perturbation fields and derivatives
Bases: pyflation.cosmomodels.PhiModels
Second order homogeneous model using efold as time variable. y[0] - deltaarphi_2 : Second order perturbation [Real Part] y[1] - deltaarphi_2^prime : Derivative of second order perturbation [Real Part] y[2] - deltaarphi_2 : Second order perturbation [Imag Part] y[3] - deltaarphi_2^prime : Derivative of second order perturbation [Imag Part]
Bases: pyflation.cosmomodels.PhiModels
Second order model using efold as time variable. y[0] - deltaarphi_2 : Second order perturbation [Real Part] y[1] - deltaarphi_2^prime : Derivative of second order perturbation [Real Part] y[2] - deltaarphi_2 : Second order perturbation [Imag Part] y[3] - deltaarphi_2^prime : Derivative of second order perturbation [Imag Part]
Bases: pyflation.cosmomodels.PhiModels
Second order model using efold as time variable. y[0] - deltaarphi_2 : Second order perturbation [Real Part] y[1] - deltaarphi_2^prime : Derivative of second order perturbation [Real Part] y[2] - deltaarphi_2 : Second order perturbation [Imag Part] y[3] - deltaarphi_2^prime : Derivative of second order perturbation [Imag Part]
Bases: pyflation.cosmomodels.MultiStageDriver
Model class for combined first and second order data, assumed to be used with a file wrapper.
Return the calculated values of $deltaphi$ for all times and modes.
The result is stored as the instance variable self.deltaphi but will be recomputed if recompute is True.
Parameters : | recompute : boolean, optional
|
---|---|
Returns : | deltaphi : array_like
|
Bases: object
Generic class for cosmological model simulations. Contains run() method which chooses a solver and runs the simulation.
All cosmological model classes are subclassed from this one.
Create a new hdf5 file with the structure capable of holding results.
Parameters : | filename : string
grpname : string, optional
yresultshape : tuple, optional
hdf5complevel : integer, optional
hdf5complib : string, optional
|
---|---|
Returns : | rf : file handle
|
Return an array of derivatives of the dependent variables yarray at timestep t
Return a 4-tuple of potential, 1st, 2nd and 3rd derivs given y.
Saves results already calculated into a file.
Save simulation results in a HDF5 format file with filename.
Parameters : | rf : filelike
grpname : string, optional
|
---|
Bases: pyflation.cosmomodels.MultiStageDriver
Uses a background and firstorder class to run a full (first-order) simulation. Main additional functionality is in determining initial conditions. Variables finally stored are as in first order class.
Return the calculated values of $deltaphi$ for all times, fields and modes. For multifield systems this is the quantum matrix of solutions:
hat{deltaphi} = Sum_{lpha, I} xi_{lpha I} hat{a}_I
The result is stored as the instance variable m.deltaphi but will be recomputed if recompute is True.
Parameters : | recompute : boolean, optional
|
---|---|
Returns : | deltaphi : array_like, dtype: complex128
|
Run the full model.
The background model is first run to establish the end time of inflation and the start times for the k modes. Then the initial conditions are set for the first order variables. Finally the first order model is run and the results are saved if required.
Parameters : | saveresults : boolean, optional
|
---|---|
Returns : | filename : string
|
Bases: pyflation.cosmomodels.FOCanonicalTwoStage
First order two stage class which does not include a phase in the initial conditions for the first order field.
Bases: pyflation.cosmomodels.FOCanonicalTwoStage
First order two stage class which does not include a phase in the initial conditions for the first order field.
Bases: pyflation.cosmomodels.FOCanonicalTwoStage
First order driver class with ainit fixed to a specified value. This is useful for comparing models which have different H behaviour and therefore different ainit values.
It should be remembered that these models with fixed ainit are equivalent to changing the number of efoldings from the end of inflation until today.
Bases: exceptions.StandardError
Generic error for model simulating. Attributes include current results stack.
Bases: pyflation.cosmomodels.CosmologicalModel
Parent of all multi (2 or 3) stage models. Contains methods to determine ns, k crossing and outlines methods to find Pr that are implemented in children.
The power spectrum of comoving curvature perturbation. This is the unscaled spectrum P_R calculated for all timesteps and ks. Calculated using the pyflation.analysis package.
The power spectrum of the curvature perturbation on uniform energy density hypersurfaces.
Calculated using the pyflation.analysis package.
Find horizon crossing time indices and efolds for all ks
Parameters : | factor : float
|
---|---|
Returns : | hcrossings : array
|
Calculate the number of efolds after inflation given the reheating temperature and assuming standard calculation of radiation and matter phases.
Parameters : | Hend : scalar, value of Hubble parameter at end of inflation Hreh : scalar (default=Hend), value of Hubble parameter at end of reheating |
---|---|
Returns : | N : scalar, number of efolds after the end of inflation until today.
|
References
See Huston, arXiv: 1006.5321, Liddle and Lyth, Cambridge University Press 2000, or Peiris and Easther, JCAP 0807 (2008) 024, arXiv:0805.2154, for more details on calculation of post-inflation expansion.
Given the Hubble parameter at the end of inflation and at the end of reheating, and the scale factor at the end of inflation, calculate the scale factor today.
Parameters : | Hend : scalar
Hreh : scalar, optional
a_end : scalar, optional
|
---|---|
Returns : | a_0 : scalar
|
Given the Hubble parameter at the end of inflation and at the end of reheating calculate the scale factor at the end of inflation.
This function assumes by default that the scale factor = 1 today and should be used with caution. A more correct approach is to call find_efolds_after_inflation directly and to use the result as required.
Parameters : | Hend : scalar
Hreh : scalar, optional
a_0 : scalar, optional
|
---|---|
Returns : | a_end : scalar
|
Iterate over findkcrossing to get full list
Parameters : | t : array
H : array
|
---|---|
Returns : | kcrossings : array
|
Given k, time variable and Hubble parameter, find when mode k crosses the horizon.
Parameters : | k : float
t : array
H : array
factor : float, optional
|
---|---|
Returns : | kcrindex, kcrefold : tuple
|
Bases: pyflation.cosmomodels.CosmologicalModel
Parent class for models implementing the scheme in Malik 06[astro-ph/0610864]
Bases: pyflation.cosmomodels.MultiStageDriver
Runs third stage calculation (typically second order perturbations) using a two stage model instance which could be wrapped from a file.
Return the calculated values of $deltaphi$ for all times and modes.
The result is stored as the instance variable self.deltaphi but will be recomputed if recompute is True.
Parameters : | recompute : boolean, optional
|
---|---|
Returns : | deltaphi : array_like
|
Bases: pyflation.cosmomodels.SOCanonicalThreeStage
Runs third stage calculation (typically second order perturbations) using a two stage model instance which could be wrapped from a file.
Second order calculation starts at horizon crossing.
Bases: pyflation.cosmomodels.CosmologicalModel
Test class defining a very simple function
helpers.py - Helper functions
Provides helper functions for use by the package elsewhere.
Generate a cartesian product of input arrays.
Parameters : | arrays : list of array-like
out : ndarray
|
---|---|
Returns : | out : ndarray
|
Examples
>>> cartesian(([1, 2, 3], [4, 5], [6, 7]))
array([[1, 4, 6],
[1, 4, 7],
[1, 5, 6],
[1, 5, 7],
[2, 4, 6],
[2, 4, 7],
[2, 5, 6],
[2, 5, 7],
[3, 4, 6],
[3, 4, 7],
[3, 5, 6],
[3, 5, 7]])
Generator of cartesian products of lists.
Check that the path for given directory exists and create it if not.
Convert scientific notation e.g. 1e-5 to 1x10^{-5} for use in LaTeX, converting to string.
Find the index of the number in array which is nearest to value.
Find the index of the number in array which is nearest to value.
Return the correct function to integrate with.
Checks the given set of values and returns either scipy.integrate.romb or scipy.integrate.simps. This depends on whether the number of values is a power of 2 + 1 as required by romb.
Parameters : | x: array_like :
|
---|---|
Returns : | intfunc: function object :
fnargs: dictionary :
|
Correct kend value given the values of kinit, deltak and numsoks.
Parameters : | kinit: float :
deltak: float :
numsoks: integer :
|
---|---|
Returns : | kend: float :
|
Returns the log base 2 of n if n is a power of 2, zero otherwise.
Note the potential ambiguity if n==1: 2**0==1, interpret accordingly.
Return list of string representations of k modes for legend.
Return an array of length l by appending array a to end of block of NaNs along axis 0.
Parameters : | a: numpy array :
l: integer :
|
---|---|
Returns : | c: numpy_array :
|
Return an array with duplicates removed but order retained.
An array is returned no matter what the input type. The first of each duplicate is retained.
Parameters : | l: array_like :
|
---|---|
Returns : | retlist: ndarray :
|
Generate numbers from min to (and including!) max, with increment of inc. Safe alternative to arange. The return_type string governs the type of the returned sequence of numbers (‘NumPyArray’, ‘list’, or ‘tuple’).
rk4.py - Runge-Kutta ODE solver
Provides Runge-Kutta based ODE solvers for use with pyflation models.
Bases: exceptions.StandardError
Generic error for model simulating run. Attributes include current results stack.
sohelpers.py - Second order helper functions
Provides helper functions for second order data from cosmomodels.py.
Copy source term to first order file in preparation for second order run.
Parameters : | sourcefile: String :
fofile: String :
newfile: String, optional :
|
---|---|
Returns : | newfile: String :
|