Contributing
Contributions to cosmoprimo are more than welcome! Please follow these guidelines before filing a pull request:
Please abide by PEP8 [1] as much as possible in your code writing, add docstrings and tests for each new functionality.
Check documentation compiles, with the expected result; see Documentation.
Submit your pull request.
Adding a new engine
cosmoprimo delegates the actual cosmological calculations to engine, such as class, camb, etc.
To add another engine (e.g. for a modified camb version), just add a new file called yourengine.py.
This module should define YourEngine (inheriting from cosmoprimo.cosmology.BaseEngine), and
the BaseSection “sections” (which take a YourEngine instance and to which cosmology attributes / methods are attached)
Background, Thermodynamics, Primordial, Transfer, Harmonic and Fourier.
Take a look at cosmoprimo.camb, and the engine for the modified camb isitgr.
For modified class versions, it is best to implement the corresponding cython wrapper yourengine in pyclass
(following the guidelines in its README),
and extend the engine and sections of classy.py in yourengine.py as e.g.:
from pyclass import yourengine
from .cosmology import BaseEngine
from . import classy
class YourEngine(classy.ClassEngine):
name = 'yourengine'
def _set_classy(self, params):
class _ClassEngine(base.ClassEngine):
def compute(self, tasks):
try:
return super(_ClassEngine, self).compute(tasks)
except base.ClassInputError as exc:
raise CosmologyInputError from exc
except base.ClassComputationError as exc:
raise CosmologyComputationError from exc
self.classy = _ClassEngine(params=params)
class Background(classy.BaseClassBackground, yourengine.Background):
"""Your modifications, if any."""
class Thermodynamics(classy.BaseClassThermodynamics, yourengine.Thermodynamics):
"""Your modifications, if any."""
"""Same for :class:`Primordial`, :class:`Perturbations`, :class:`Transfer`, :class:`Harmonic` and :class:`Fourier`."""
Finally, this new engine can be trivially added to cosmology.get_engine(),
and one will be able to invoke it as:
from cosmoprimo import Cosmology
cosmo = Comology(engine='yourengine')