-
Notifications
You must be signed in to change notification settings - Fork 30
classy:classy.pyx_cclassy.pxd
As you already know, classy is the python wrapper of CLASS. This means it
serves as interface between python and C codes. In order to acomplish that,
classy is written using
cython. Cython's source
files have .pyx
extension and the C-header equivalent files are the .pxd
files. In them cython declarations are stored.
After this brief introduction, we can dive into classy.pyx
.
First thing to remark is the definition of the two Error classes:
-
CosmoSevereError
which will be used ifinit_input()
fails. -
CosmoComputationError
if the failure comes from any other computational stage.
This distinction is made to work with MontePython. In case first error were raised, MontePython would halt the execution but, in the other case, it would continue running having assigned a low proability value to the specific model that caused the error.
Secondly, the userspace class is Class, that have the following methods defined:
-
set()
. It updates the parameters passed toinput_init()
. -
compute()
. Computes the cosmology (calls allxxx_init()
until specified computational level is arrived (default islensing
)) if it fails at some stage, reaise the corresponding error and callstruct_cleanup()
; elsewise setready = True
. -
struct_cleanup()
. Callxxx_free()
for the computed levels ifready is not False
(freeing a non-allocated memory causes asegementation_fault
). -
empty()
. Remove set parameters and setready = False
. -
get_curent_derived_parameters
. Return the computed value of the parameters given as input (e.g.['h', '100*theta_s', ...]
). This method is used by MontePython to obtain the value of the'derived'
parameters. If you want MontePython to understand a new parameter (e.g. w0_smg()), you must add it to this method. -
get_xxx()
. Returns a dictionary with the computed tables in thexxx
structure, where the keywords are the column titles. - A buch of methods to return different physical values. To see them all look
in
classy.pyx
.
As we said classy.pxd
is the Cython header file with all cython specific
declarations used in classy.pyx
. We will remark just a few things:
-
cdef extern from "class.h":
tells cython that all its member definitions are found inclass.h
. - In its block we declare those C-objects we need (structures, functions e.g.
as
xxx_init()
, constants, ...). - In a lower level we declare their subobjects if any; for example, the structure keywords.
[...]
cdef extern from "class.h":
ctypedef char FileArg[40]
[...]
cdef enum file_format:
class_format
camb_format
[...]
cdef struct background:
ErrorMsg error_message
int bg_size
int index_bg_ang_distance
[...]
void lensing_free(void*)
void spectra_free(void*)
[...]
cdef int _FAILURE_
cdef int _FALSE_
cdef int _TRUE_
[...]
int nonlinear_k_nl_at_z(void* pba, void* pnl, double z, double* k_nl)
int spectra_firstline_and_ic_suffix(void *ppt, int index_ic, char first_line[_LINE_LENGTH_MAX_], FileName ic_suffix)
Home
Installation
Basic usage
classy: the python wrapper
Introducing new models
The code:
- Code 1: Philosophy and structure
- Code 2: Indexing
- Code 3: Errors
- Code 4: input.c
- Code 5: background.c
- Code 6: thermodynamics.c
- Code 7: perturbations.c
- Code 8: primordial.c
- Code 10: output.c
- Other modules
- classy: classy.pyx and classy.pxd
Examples: