Skip to content

Commit

Permalink
Update installation (#113)
Browse files Browse the repository at this point in the history
* update explicit packages to work with cosmopower

* update installation instructions

* compressed parameters tutorial update

* update hierarchy

* update hierarchy

* update hierarchy

* Update README.md

LaCE instead of Cup1d for notebooks

* remove conda-forge

* add metric information

---------

Co-authored-by: Laura Cabayol Garcia <[email protected]>
Co-authored-by: Andreu Font-Ribera <[email protected]>
Co-authored-by: Laura Cabayol Garcia <[email protected]>
  • Loading branch information
4 people authored Nov 22, 2024
1 parent ba12de5 commit 8d043dd
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 50 deletions.
47 changes: 30 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ LaCE contains a set of emulators for the one-dimensional flux power spectrum of

Please cite at least https://arxiv.org/abs/2305.19064 if you use this emulator in your research.

There is a documentation website with installation instructions and relevant descriptions at [here](https://igmhub.github.io/LaCE/

## Installation
(Last updated: Jan 19 2024)
(Last updated: Nov 19 2024)

LaCE contains a submodule to estimate compressed parameters from the power spectrum that uses cosmopower. The LaCE installation is slightly different depending on whether you want to use cosmopower or not.

#### LaCE without cosmopower

- Create a new conda environment. It is usually better to follow python version one or two behind. In January 2024, the latest is 3.12, so we recommend 3.11. If you want to use LaCE with cosmopower, as of November 2024 you need to install python 3.10. Please look at the cosmopower installation before proceeding with the LaCE installation.

```
conda create -n lace -c conda-forge python=3.11 camb fdasrsf
conda create -n lace -c conda-forge python=3.11 pip
conda activate lace
pip install --upgrade pip
```
Expand All @@ -30,28 +36,36 @@ pip install -e .
- If you find problems, please install LaCE as follows:

```
pip install -e .[explicit]
pip install -e ".[explicit]"
```

- If you want to use cosmopower, you need to use python 3.10 and install the cosmopower package. You must install cosmopower before installing LaCE. You can do this by running:
#### LaCE with cosmopower

- Create a new conda environment.

```
pip install cosmopower
conda create -n lace python=3.11 pip
conda activate lace
pip install --upgrade pip
```
and install:

- Install cosmopower:
```
pip install -e .
pip install pyDOE2
pip install git+https://github.com/igmhub/cup1d.git
pip install cosmopower pyDOE
```

#### Tests

Please run the following script to check that the package is working properly.
- Clone the repo into your machine and perform an *editable* installation:
```
git clone https://github.com/igmhub/LaCE.git
cd LacE
```

- Install LaCE using the installation with explicit dependencies:
```
pip install -e ".[explicit]"
```
=======
#### Tests

## Tests

Please run the following script to check that the package is working properly.

Expand Down Expand Up @@ -82,7 +96,6 @@ python scripts/save_nyx_emu_cosmo.py
python scripts/save_nyx_IGM.py
```

## Emulator parameters:

These are the parameters that describe each individual P1D(k) power spectrum. We have detached these from redshift and traditional cosmology parameters.
Expand Down Expand Up @@ -110,7 +123,7 @@ The current version of the emulator, relased in this repo, does not emulate `alp
`kF_Mpc` is the filtering length (or pressure smoothing scale) in inverse comoving units


### Notebooks / tutorials
## Notebooks / tutorials


- All notebooks in the repository are in .py format. To generate the .ipynb version, run:
Expand All @@ -123,7 +136,7 @@ jupytext --to ipynb notebooks/*.py

```
pip install ipykernel
python -m ipykernel install --user --name cup1d --display-name lace
python -m ipykernel install --user --name lace --display-name lace
```
In the `Notebooks` folder, there are several tutorials one can run to learn how to use the archives and emulators.

Expand Down
45 changes: 38 additions & 7 deletions docs/docs/installation.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# Installation
(Last updated: Nov 19 2024)

## Installation
LaCE contains a submodule to estimate compressed parameters from the power spectrum that uses cosmopower. The LaCE installation is slightly different depending on whether you want to use cosmopower or not.

We recommend using conda environment to install LaCE. To create a conda environment, one needs to specify the python version.
In January 2024, the latest is 3.12. To use the emulators, there are no strong requirements on the python version. LaCE also contains a cosmology module to estimate compressed cosmological parameters using cosmopower, and this module requires python 3.10.
### LaCE without cosmopower

The following instructions are for python 3.10 to ensure that all modules in the repository can run.

To create a conda environment with python 3.10, run:
- Create a new conda environment. It is usually better to follow python version one or two behind. In January 2024, the latest is 3.12, so we recommend 3.11. If you want to use LaCE with cosmopower, as of November 2025 you need to install python 3.10. Please look at the cosmopower installation before proceeding with the LaCE installation.

```
conda create -n lace -c conda-forge python=3.10 camb fdasrsf cosmopower, pyDOE2
conda create -n lace -c conda-forge python=3.11 pip
conda activate lace
pip install --upgrade pip
```
Expand All @@ -21,3 +20,35 @@ git clone https://github.com/igmhub/LaCE.git
cd LacE
pip install -e .
```

- If you find problems, please install LaCE as follows:

```
pip install -e ".[explicit]"
```

### LaCE with cosmopower

- Create a new conda environment.

```
conda create -n lace -c conda-forge python=3.11 pip
conda activate lace
pip install --upgrade pip
```
- Install cosmopower:

```
pip install cosmopower pyDOE
```

- Clone the repo into your machine and perform an *editable* installation:

```
git clone https://github.com/igmhub/LaCE.git
cd LacE
```
- Install LaCE using the installation with explicit dependencies:
```
pip install -e ".[explicit]"
```
11 changes: 4 additions & 7 deletions notebooks/Tutorial_compressedParams.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
# ##### DESCLAIMER: Cosmopower is not installed by default in the LaCE package. You can install it as pip install cosmopower.
#

# Additional documentation on how to use cosmopower can be found [here](https://igmhub.github.io/LaCE/compressedParameters/)

# +
import numpy as np
import cosmopower as cp
Expand All @@ -37,9 +39,6 @@

# -

# ## TRAIN COSMOPOWER
#

# ## 1. ESTIMATE THE COMPRESSED PARAMETERS OF THE GADGET TEST SIMULATIONS

# ### 1.1. LOAD THE GADGET TEST SIMULATION
Expand Down Expand Up @@ -122,7 +121,7 @@
'mnu': [0, 2],}

create_LH_sample(dict_params_ranges = dict_params_ranges,
nsamples = 10_000,
nsamples = 10,
filename = "LHS_params_test.npz")

# ### 2.2 GENERATE THE TRAINING SPECTRA
Expand Down Expand Up @@ -155,7 +154,7 @@
param_mapping = {
'h': 'h',
'm_ncdm': 'm_ncdm',
'omega_cdm': 'omega_cdm',
'omega_cdm': 'omega_c',
'Omega_m': 'Omega_m',
'ln_A_s_1e10': 'ln_A_s_1e10',
'n_s': 'n_s'
Expand All @@ -165,8 +164,6 @@
linP_cosmology_results = fitter_compressed_params.fit_linP_cosmology(chains_df = df,
param_mapping = param_mapping)

#

linP_cosmology_results


9 changes: 7 additions & 2 deletions notebooks/nyx_central_z3.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

# ## Extract parameters

z_test=3.4
z_test=3

take_pars = ['Delta2_p', 'n_p','alpha_p','mF', 'sigT_Mpc', 'gamma', 'kF_Mpc']
nelem = len(training_data)
Expand Down Expand Up @@ -152,6 +152,8 @@

# ## FIND NEAREST NEIGHBOURS TO CENTRAL AT z=3

# The nearest neighbours are calculated using the minkowsky distance.

# +
from sklearn.neighbors import NearestNeighbors

Expand Down Expand Up @@ -182,7 +184,10 @@
logger.info(f"Parameters: {dict(zip(take_pars, central_params))}")
logger.info("\nNearest neighbors:")
for neighbor_idx, neighbor_dist in zip(idx, dist):
logger.info(f"Simulation: {training_data[neighbor_idx]['sim_label']} at z={np.round(training_data[neighbor_idx]['z'],2)}, Distance: {neighbor_dist:.3f}, Parameters: {dict(zip(take_pars, pars_all_nyx[neighbor_idx]))}")
logger.info(f"Simulation: {training_data[neighbor_idx]['sim_label']} at z={np.round(training_data[neighbor_idx]['z'],2)}, Distance: {neighbor_dist:.3f}, Scalings: {training_data[neighbor_idx]['val_scaling']}")

# -



# +
Expand Down
33 changes: 16 additions & 17 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ dependencies = [
"matplotlib",
"configobj",
"camb",
"torch",
"scikit-fda",
"jupyterlab",
"jupytext",
"torch==2.0",
"scikit-fda==0.4",
"fdasrsf==2.3.10",
"strenum",
"pathlib"
]
Expand All @@ -58,19 +57,19 @@ gpy = [
"GPy==1.13.1",
]
explicit = [
"numpy==1.24.4",
"pandas==2.1.4",
"scipy==1.11.4",
"h5py==3.10.0",
"scikit-learn==1.3.2",
"matplotlib==3.8.2",
"configobj==5.0.8",
"camb==1.5.4",
"torch==2.1.2",
"scikit-fda==0.9",
"GPy==1.13.1",
"jupyterlab"
]
"numpy==1.24.3",
"pandas==2.2.3",
"scipy==1.12",
"h5py==3.12.1",
"scikit-learn==1.5.2",
"matplotlib==3.9.2",
"configobj==5.0.9",
"camb==1.5.8",
"torch==2.0",
"scikit-fda==0.4",
"fdasrsf==2.3.10",
"GPy==1.13.2"
]

[tool.setuptools.packages.find]
include = ["lace","lace.*"]
Expand Down

0 comments on commit 8d043dd

Please sign in to comment.