Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a08dd2a
Accuracy tweaks for check_accuracy stability
cmbant May 1, 2026
d66939b
gitignore
cmbant May 1, 2026
4eb09fc
check_accuracy more relaxed on mpk if transfer_high_precision not set.
cmbant May 6, 2026
f3d0b6b
Relax BB tolerance for AccurateBB false
cmbant May 8, 2026
42dc1e9
Tweaks for reionization, photon switch, high-l log sampling, check_ac…
cmbant May 11, 2026
cee0a35
gauss-legendre lensing in fortran
cmbant May 7, 2026
bf162de
merge
cmbant May 11, 2026
5352cb4
Gauss-legendre in fortran
cmbant May 7, 2026
9a3d676
Tweak apodization and weights
cmbant May 8, 2026
62ecb50
doc tidy
cmbant May 11, 2026
c910213
docker
cmbant May 11, 2026
b8ea439
ruff
cmbant May 11, 2026
d981577
lens_output_margin input parameter; ketamax set to 2.5* default when …
cmbant May 11, 2026
99ebb28
Improved C2 lensing taper, and parameter tweaks for AccuracyTarget>0
cmbant May 12, 2026
873a702
minujl for tensors
cmbant May 12, 2026
255e878
Non-flat using numerov and code more analogous to flat. (InterpolateS…
cmbant May 13, 2026
76a3e49
Merge branch 'nonflat' into devel_acc
cmbant May 13, 2026
7cd08cd
Split slow tests
cmbant May 13, 2026
c1ab921
Add back DoRangeInt rejection when very oscillatory
cmbant May 13, 2026
67ea174
agents/docker
cmbant May 13, 2026
62d547d
Merge branch 'nonflat' into devel_acc
cmbant May 13, 2026
0f80980
Refactor and rename chi0 -> DMt0
cmbant May 13, 2026
614c3e0
agents.md
cmbant May 13, 2026
50ca720
container doc
cmbant May 15, 2026
662bc8b
Near-flat shifted bessel approximation for faster chi<<1 non-flat cases
cmbant May 15, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ RUN apt-get update \
libgsl-dev \
make \
pkg-config \
ripgrep \
tar \
unzip \
xz-utils \
Expand All @@ -42,6 +43,7 @@ RUN mkdir -p \
wheel \
findent \
fortls \
matplotlib \
numpy \
scipy \
sympy \
Expand Down
3 changes: 3 additions & 0 deletions .devcontainer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,6 @@ devcontainer's selected interpreter may need to be pointed explicitly at
`/home/vscode/.local/share/camb-devcontainer/.venv/bin/python3`.

If you explicitly want a standards-based editable install after the container is up, you can still run `python -m pip install --no-build-isolation --no-deps -e .`, but that setuptools metadata phase is the part that remains slow on this bind-mounted checkout.


The container includes CosmoRec and HyRec. If not needed, you can speed builds by doing `export RECOMBINATION_FILES=recfast`
3 changes: 3 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"runArgs": [
"--cpus=8"
],
"features": {
"ghcr.io/anthropics/devcontainer-features/claude-code:1.0": {}
},
"workspaceMount": "source=${localWorkspaceFolder}/..,target=/workspaces/camb-parent,type=bind",
"workspaceFolder": "/workspaces/camb-parent/${localWorkspaceFolderBasename}",
"mounts": [
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
- name: Run tests
run: |
python -c "import camb; print(camb.__version__)"
python -m unittest camb.tests.camb_test
python -c "import os, subprocess, sys; modules=['camb.tests.camb_test']; modules += [] if os.getenv('CAMB_TEST_FAST') else ['camb.tests.camb_test_slow']; print('Running', ', '.join(modules)); subprocess.run([sys.executable, '-m', 'unittest', *modules], check=True)"

- name: HM code tests
if: matrix.os == 'ubuntu-latest'
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ testfile*
.vs
*.mp4
*.exe
*_tmp*

# Ignore all .dat and .ini files except those already tracked in git
*.dat
Expand Down Expand Up @@ -89,3 +90,4 @@ external/
!.devcontainer/
!.devcontainer/**
.claude
devcontainer-lock.json
72 changes: 52 additions & 20 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,52 @@
# Project instructions
- This is the CAMB python cosmology code source, wrapping fortran 2003 for numerics
- Follow the rules in this file.
- If `AGENTS.local.md` exists, read it after this file and let it override local environment details.

# Project rules and guidance
- Python uses python 3.10+ with modern type hint syntax
- Use double-quotes for strings; line length 120
- Code is auto-formatted by ruff, including import reordering.
- Fortran uses modern Fortran 2003, compiled with gfortran or ifort
- Install and run pre-commit hooks as needed for checking
- /forutils is a git submodule with shared fortran utilities and classes
- For fortran/wrapped fortran code modifications see /docs/modifying_code.rst
- When updating version, update both python __version__ and version defined near the top of fortran/config.f90
- Use pip -e for editable first install. After that use "python setup.py make" to quickly rebuild fortran for use with python.
- Default test: python -m unittest camb.tests.camb_test (do not run hmcode_test unless specifically relevant)
- Long test against precomputed results: fortran/tests/run_tests.py which calls CAMB_test_files.py (only if asked)
- Installation/clone/modification/contributing/pre-commit/vscode config: see /CONTRIBUTING.md
- When plotting fractional differences for cross-spectra, use e.g. Delta TE/sqrt(TT*EE)
- High accuracy lensing needs lens_potential_accuracy = 8 or so (mainly increases kmax)
# Project Overview

This is the CAMB Python cosmology code, wrapping Fortran 2003 for numerics.

---

# Coding Standards

## Python
- Use Python 3.10+ with modern type-hint syntax.
- Use double-quotes for strings; maximum line length is 120.
- Code is auto-formatted by **ruff**, including import reordering.
- Use the **pre-commit** command line to run ruff check/format (e.g., `pre-commit run --all-files`); do not invoke `ruff` directly.
- Ruff/pyupgrade hooks and their configuration live in `.pre-commit-config.yaml`
- All code must be Python or Fortran only—no bash scripts except for devcontainer setup and GitHub Actions.

## Fortran
- Use modern Fortran 2003, compiled with **gfortran** or **ifort**.
- `/forutils` is a git submodule containing shared Fortran utilities and classes.
- For guidance on modifying Fortran or wrapped Fortran code, see `/docs/modifying_code.rst`.

---

# Development Workflow

## Installation & Build
- Use `pip install -e .` for the initial editable install.
- After the first install, use `python setup.py make` to quickly rebuild the Fortran for use with Python after any fortran changes.
- If `python setup.py make` produces stale `.mod` type-mismatch errors, run `python setup.py clean` first (not normally needed).

## Testing
- **Default test:** `python -m unittest camb.tests.camb_test`.
- Do **not** run `camb.tests.hmcode_test` unless specifically relevant.
- **Long test** against precomputed results: `python fortran/tests/run_tests.py`, which calls `CAMB_test_files.py`. Only run this if explicitly asked.

## Configuration
- See `CONTRIBUTING.md` for installation, cloning, modification guidelines, contribution instructions, pre-commit setup, and VS Code configuration.

---

# Maintenance & Versioning
- When updating the version, update **both**:
- the Python `__version__`, and
- the version defined near the top of `fortran/config.f90`.
- When adding new `.ini` file parameters, also add the corresponding `.ini` write logic in `camb/_ini.py`.

---

# Physics & Numerical Guidance
- When plotting fractional differences for cross-spectra, use e.g. $\Delta TE / \sqrt{TT \cdot EE}$.
- High-accuracy lensing requires `lens_potential_accuracy = 8` or so (this mainly increases `kmax`).
- Use `camb/check_accuracy.py` to assess numerical stability by comparing a default run to a high-accuracy run.
8 changes: 8 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ Run the test suite to ensure your changes don't break anything:
python -m unittest camb.tests.camb_test
```

To run the full suite including the slower symbolic and emission-angle tests:

```bash
python -m unittest camb.tests.camb_test camb.tests.camb_test_slow
```

The GitHub workflows include `camb.tests.camb_test_slow` by default, and skip it when `CAMB_TEST_FAST` is set.

For HMcode tests (Linux only):

```bash
Expand Down
11 changes: 9 additions & 2 deletions camb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,20 @@
__author__ = "Antony Lewis"
__contact__ = "antony at cosmologist dot info"
__url__ = "https://camb.readthedocs.io"
__version__ = "1.6.7"
__version__ = "1.6.8"

from . import baseconfig

baseconfig.check_fortran_version(__version__)
from . import dark_energy, initialpower, model, nonlinear, reionization
from ._config import config
from ._config import (
config,
lensing_method_curv_corr,
lensing_method_curv_corr_direct,
lensing_method_flat_corr,
lensing_method_harmonic,
lensing_method_optimized,
)
from .baseconfig import (
Array1D,
CAMBError,
Expand Down
13 changes: 13 additions & 0 deletions camb/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,25 @@
lensing_method_curv_corr = 1
lensing_method_flat_corr = 2
lensing_method_harmonic = 3
lensing_method_curv_corr_direct = 4
lensing_method_optimized = 5


class _config:
# print feedback if > 0 (note in Jupyter notebook this will appear in the terminal, not the notebook)
FeedbackLevel = import_property(c_int, "config", "FeedbackLevel")

# enable targeted accuracy improvements if > 0, AccuracyTarget being SO-like.
AccuracyTarget = import_property(c_int, "config", "AccuracyTarget")

near_flat_approx_chi_limit = import_property(c_double, "config", "near_flat_approx_chi_limit")

near_flat_approx_chidisp_limit = import_property(c_double, "config", "near_flat_approx_chidisp_limit")

enable_do_near_flat_integration = import_property(c_bool, "config", "enable_do_near_flat_integration")

enable_shifted_q_scalar_approx = import_property(c_bool, "config", "enable_shifted_q_scalar_approx")

# print additional timing and progress (when FeedbackLevel>0)
DebugMsgs = import_property(c_bool, "config", "DebugMsgs")

Expand Down
1 change: 1 addition & 0 deletions camb/_ini.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ def _update_ini_state_from_params(params: model.CAMBparams, state: CambIniFile)
if params.WantCls and (params.WantScalars or params.WantVectors):
set_param(state, "l_max_scalar", params.max_l)
set_param(state, "k_eta_max_scalar", params.max_eta_k)
set_param(state, "lens_output_margin", params.lens_output_margin)
if params.WantScalars:
set_param(state, "do_lensing", params.DoLensing)
if params.WantCls and params.WantTensors:
Expand Down
Loading
Loading