Skip to content

Commit ce9aa53

Browse files
authored
Merge branch 'main' into issue/616/scipy_simps_rename
2 parents 9cdfb72 + 13b7c8a commit ce9aa53

8 files changed

+73
-88
lines changed

INSTALL.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
## Basic procedure <a name="basic_install"></a>
1414

1515
Here we provide a quick guide for a basic instalation, this will install all the packages in your current environment.
16-
To create a specific conda environment for CLMM, we recommend you to check the begining of section
16+
To create a specific conda environment for CLMM, we recommend you to check the begining of section
1717
[Access to the proper environment on cori.nersc.gov](#access_to_the_proper_environment_on_cori).
1818

1919
### Theory backend installation
2020
First, choose and install a theory backend for CLMM.
2121
This can be CCL (versions between 2.7.1.dev10+gf81b59a4 and 3),
22-
NumCosmo (v0.15 or later),
22+
NumCosmo (v0.19 or later),
2323
or cluster_toolkit and they are installable as follows.
2424

2525
To install CCL as the theory/cosmology backend, run
@@ -60,7 +60,7 @@ Now, you can install CLMM and its dependencies as
6060
pip install pytest sphinx sphinx_rtd_theme
6161
pip install jupyter # need to have jupyter notebook tied to this environment, you can then see the environment in jupyter.nersc.gov
6262
git clone https://github.com/LSSTDESC/CLMM.git # If you'd like to contribute but don't have edit permissions to the CLMM repo, see below how to fork the repo instead.
63-
cd CLMM
63+
cd CLMM
6464
python setup.py install # build from source
6565
```
6666

@@ -72,9 +72,9 @@ If you have access to NERSC, this will likely be the easiest to make sure you ha
7272
module load python # Also loads anaconda
7373
conda create --name clmmenv # Create an anaconda environment for clmm
7474
source activate clmmenv # switch to your newly created environment
75-
conda install pip # need pip to install everything else necessary for clmm
75+
conda install pip # need pip to install everything else necessary for clmm
7676
conda install ipython # need to have the ipython tied to this environment
77-
conda install -c conda-forge firefox # Need a browser to view jupyter notebooks
77+
conda install -c conda-forge firefox # Need a browser to view jupyter notebooks
7878
```
7979

8080
Note, for regular contributions and use, we recommend adding `module load python` to your `~/.bashrc` so you have anaconda installed every time you log in. You will subseqeuntly also want to be in the correct environment whenever working with `clmm`, which means running `source activate clmmenv` at the start of each session.

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ CLMM requires Python version 3.8 or later. CLMM has the following dependencies:
2424

2525
- [NumPy](https://www.numpy.org/) (v1.17 or later)
2626
- [SciPy](https://scipy.org/) (v1.6 or later)
27-
- [Astropy](https://www.astropy.org/) (v4.0 or later for units and cosmology dependence)
27+
- [Astropy](https://www.astropy.org/) (v4.0 or later for units and cosmology dependence)
2828
(Please avoid Astropy v5.0 since there is bug breaking CCL backend. It has been fixed in Astropy v5.0.1.)
2929
- [Matplotlib](https://matplotlib.org/) (for plotting and going through tutorials)
3030

@@ -36,7 +36,7 @@ For the theoretical predictions of the signal, CLMM relies on existing libraries
3636

3737
- [cluster-toolkit](https://cluster-toolkit.readthedocs.io/en/latest/)
3838
- [CCL](https://ccl.readthedocs.io/en/latest/) (versions between 2.7.1.dev10+gf81b59a4 and 3)
39-
- [NumCosmo](https://numcosmo.github.io/) (v0.15 or later)
39+
- [NumCosmo](https://numcosmo.github.io/) (v0.19 or later)
4040

4141

4242
(See the [INSTALL documentation](INSTALL.md) for more detailed installation instructions.)
@@ -91,8 +91,8 @@ non-DESC project concept and progress to be presented to the working group,
9191
so working group members can help co-identify tools and/or ongoing development
9292
that might mutually benefit your non-DESC project and ongoing DESC projects.
9393

94-
**External Projects by Non-DESC members**: If you are not from the DESC
95-
community, you are also welcome to contact CLMM Topical Team leads to introduce
94+
**External Projects by Non-DESC members**: If you are not from the DESC
95+
community, you are also welcome to contact CLMM Topical Team leads to introduce
9696
your project and share feedback.
9797

9898

clmm/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@
2626
)
2727
from . import support
2828

29-
__version__ = "1.10.0"
29+
__version__ = "1.11.0"

clmm/cosmology/numcosmo.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class NumCosmoCosmology(CLMMCosmology):
3333

3434
def __init__(self, dist=None, dist_zmax=15.0, **kwargs):
3535
self.dist = None
36+
self.smd = None
3637

3738
super().__init__(**kwargs)
3839

@@ -54,6 +55,7 @@ def __init__(self, dist=None, dist_zmax=15.0, **kwargs):
5455
self.smd = Nc.WLSurfaceMassDensity.new(self.dist)
5556
self.smd.prepare_if_needed(self.be_cosmo)
5657

58+
5759
def _init_from_cosmo(self, be_cosmo):
5860
assert isinstance(be_cosmo, Nc.HICosmo)
5961
assert isinstance(be_cosmo, Nc.HICosmoDECpl)
@@ -63,7 +65,7 @@ def _init_from_cosmo(self, be_cosmo):
6365

6466
def _init_from_params(self, H0, Omega_b0, Omega_dm0, Omega_k0):
6567
# pylint: disable=arguments-differ
66-
self.be_cosmo = Nc.HICosmo.new_from_name(Nc.HICosmo, "NcHICosmoDECpl{'massnu-length':<1>}")
68+
self.be_cosmo = Nc.HICosmoDECpl(massnu_length=1)
6769
self.be_cosmo.omega_x2omega_k()
6870
self.be_cosmo.param_set_by_name("w0", -1.0)
6971
self.be_cosmo.param_set_by_name("w1", 0.0)
@@ -136,6 +138,10 @@ def _update_vec_funcs(self):
136138
self._eval_sigma_crit_core = np.vectorize(
137139
lambda z_len, z_src: (self.smd.sigma_critical(self.be_cosmo, z_src, z_len, z_len))
138140
)
141+
if self.dist is not None:
142+
self.dist.prepare_if_needed(self.be_cosmo)
143+
if self.smd is not None:
144+
self.smd.prepare_if_needed(self.be_cosmo)
139145

140146
def _get_rho_c(self, z):
141147
return (

clmm/theory/numcosmo.py

+1
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ def set_mset(self, mset):
193193

194194
self.hdpm = mset.get(Nc.HaloDensityProfile.id())
195195
self.cosmo.smd = mset.get(Nc.WLSurfaceMassDensity.id())
196+
self.cosmo.smd.prepare_if_needed(self.cosmo.be_cosmo)
196197

197198

198199
Cosmology = NumCosmoCosmology

examples/NumCosmo/Example1_Fit_Halo_Mass_to_Shear_Catalog_NC.ipynb

+6-6
Original file line numberDiff line numberDiff line change
@@ -585,20 +585,20 @@
585585
" self.props.z_src = Ncm.Vector.new_array(z_src)\n",
586586
" self.props.r_source = Ncm.Vector.new_array(r_source)\n",
587587
"\n",
588-
" self.y.set_array(gt_profile)\n",
588+
" self.peek_mean().set_array(gt_profile)\n",
589589
"\n",
590-
" self.sigma.set_all(\n",
590+
" self.peek_std().set_all(\n",
591591
" 1.0e-2\n",
592592
" ) # Diagonal covariance matrix: all points have the same standard deviation value\n",
593593
"\n",
594594
" self.set_init(True)\n",
595595
"\n",
596596
" # Once the NcmDataGaussDiag is initialized, its parent class variable np is set with the n_points value.\n",
597597
" def do_get_length(self):\n",
598-
" return self.np\n",
598+
" return self.get_size()\n",
599599
"\n",
600600
" def do_get_dof(self):\n",
601-
" return self.np\n",
601+
" return self.get_size()\n",
602602
"\n",
603603
" def do_begin(self):\n",
604604
" pass\n",
@@ -686,8 +686,8 @@
686686
"metadata": {},
687687
"outputs": [],
688688
"source": [
689-
"fit1 = Ncm.Fit.new(Ncm.FitType.NLOPT, \"ln-neldermead\", lh1, mset1, Ncm.FitGradType.NUMDIFF_FORWARD)\n",
690-
"fit2 = Ncm.Fit.new(Ncm.FitType.NLOPT, \"ln-neldermead\", lh2, mset2, Ncm.FitGradType.NUMDIFF_FORWARD)\n",
689+
"fit1 = Ncm.Fit.factory(Ncm.FitType.NLOPT, \"ln-neldermead\", lh1, mset1, Ncm.FitGradType.NUMDIFF_FORWARD)\n",
690+
"fit2 = Ncm.Fit.factory(Ncm.FitType.NLOPT, \"ln-neldermead\", lh2, mset2, Ncm.FitGradType.NUMDIFF_FORWARD)\n",
691691
"\n",
692692
"fit1.run(Ncm.FitRunMsgs.SIMPLE)\n",
693693
"fit1.fisher()\n",

examples/NumCosmo/Example2_Fit_Halo_Mass_to_Shear_Catalog_NC.ipynb

+13-13
Original file line numberDiff line numberDiff line change
@@ -468,20 +468,20 @@
468468
" if z_err:\n",
469469
" self.props.r_source = Ncm.Vector.new_array(z_err)\n",
470470
"\n",
471-
" self.y.set_array(gt_profile)\n",
471+
" self.peek_mean().set_array(gt_profile)\n",
472472
"\n",
473-
" self.sigma.set_array(\n",
473+
" self.peek_std().set_array(\n",
474474
" gt_err\n",
475475
" ) # Diagonal covariance matrix: standard deviation values in gt_err.\n",
476476
"\n",
477477
" self.set_init(True)\n",
478478
"\n",
479479
" # Once the NcmDataGaussDiag is initialized, its parent class variable np is set with the n_points value.\n",
480480
" def do_get_length(self):\n",
481-
" return self.np\n",
481+
" return self.get_size()\n",
482482
"\n",
483483
" def do_get_dof(self):\n",
484-
" return self.np\n",
484+
" return self.get_size()\n",
485485
"\n",
486486
" def do_begin(self):\n",
487487
" pass\n",
@@ -605,9 +605,9 @@
605605
"metadata": {},
606606
"outputs": [],
607607
"source": [
608-
"fit1 = Ncm.Fit.new(Ncm.FitType.NLOPT, \"ln-neldermead\", lh1, mset1, Ncm.FitGradType.NUMDIFF_FORWARD)\n",
609-
"fit2 = Ncm.Fit.new(Ncm.FitType.NLOPT, \"ln-neldermead\", lh2, mset2, Ncm.FitGradType.NUMDIFF_FORWARD)\n",
610-
"fit3 = Ncm.Fit.new(Ncm.FitType.NLOPT, \"ln-neldermead\", lh3, mset3, Ncm.FitGradType.NUMDIFF_FORWARD)\n",
608+
"fit1 = Ncm.Fit.factory(Ncm.FitType.NLOPT, \"ln-neldermead\", lh1, mset1, Ncm.FitGradType.NUMDIFF_FORWARD)\n",
609+
"fit2 = Ncm.Fit.factory(Ncm.FitType.NLOPT, \"ln-neldermead\", lh2, mset2, Ncm.FitGradType.NUMDIFF_FORWARD)\n",
610+
"fit3 = Ncm.Fit.factory(Ncm.FitType.NLOPT, \"ln-neldermead\", lh3, mset3, Ncm.FitGradType.NUMDIFF_FORWARD)\n",
611611
"\n",
612612
"fit1.run(Ncm.FitRunMsgs.SIMPLE)\n",
613613
"fit1.fisher()\n",
@@ -768,7 +768,7 @@
768768
"init_sampler.set_cov_from_rescale(1.0e-1)\n",
769769
"\n",
770770
"nwalkers = 100 # Number of walkers\n",
771-
"walker = Ncm.FitESMCMCWalkerAPS.new(nwalkers, mset3.fparams_len())\n",
771+
"walker = Ncm.FitESMCMCWalkerAPES.new(nwalkers, mset3.fparams_len())\n",
772772
"\n",
773773
"# Ensemble Sampler MCMC\n",
774774
"esmcmc = Ncm.FitESMCMC.new(fit3, nwalkers, init_sampler, walker, Ncm.FitRunMsgs.SIMPLE)\n",
@@ -792,7 +792,7 @@
792792
"\n",
793793
"Here, instead of building an object directly on top of NcmDataGauss*, we use NumCosmo's framework to build non-binned likelihood for weak-lensing cluster analysis.\n",
794794
"\n",
795-
"For that we need two objects: a NcGalaxyWLReducedShearGauss that model a Gaussian distributed reduced shear likelihood, here the observables matrix is simply $(r, \\gamma_t, \\sigma_{\\gamma_t})$ for each galaxy. If the data has spectroscopic redshifts then we use NcGalaxyRedshiftSpec with an array of real redshifts. When photometric errors are included we use the NcGalaxyRedshiftGauss object that receives $(z, \\sigma_z)$ for each galaxy. \n",
795+
"For that we need two objects: a NcGalaxyWLEllipticityGauss that model a Gaussian distributed reduced shear likelihood, here the observables matrix is simply $(r, \\gamma_t, \\sigma_{\\gamma_t})$ for each galaxy. If the data has spectroscopic redshifts then we use NcGalaxyRedshiftSpec with an array of real redshifts. When photometric errors are included we use the NcGalaxyRedshiftGauss object that receives $(z, \\sigma_z)$ for each galaxy. \n",
796796
"\n",
797797
"Once we have the data objects ready we can proceed as in the previous examples.\n"
798798
]
@@ -812,7 +812,7 @@
812812
" sigma_g = 1.0e-4 if not sigma_g else sigma_g\n",
813813
" m_obs = np.column_stack((r, g_t, np.repeat(sigma_g, len(r))))\n",
814814
"\n",
815-
" grsg = Nc.GalaxyWLReducedShearGauss(pos=Nc.GalaxyWLReducedShearGaussPos.R)\n",
815+
" grsg = Nc.GalaxyWLEllipticityGauss(pos=Nc.GalaxyWLEllipticityGaussPos.R)\n",
816816
" grsg.set_obs(Ncm.Matrix.new_array(m_obs.flatten(), 3))\n",
817817
"\n",
818818
" if sigma_z:\n",
@@ -837,7 +837,7 @@
837837
" for data in data_array:\n",
838838
" dset.append_data(data)\n",
839839
" lh = Ncm.Likelihood.new(dset)\n",
840-
" fit = Ncm.Fit.new(Ncm.FitType.NLOPT, \"ln-neldermead\", lh, mset, Ncm.FitGradType.NUMDIFF_FORWARD)\n",
840+
" fit = Ncm.Fit.factory(Ncm.FitType.NLOPT, \"ln-neldermead\", lh, mset, Ncm.FitGradType.NUMDIFF_FORWARD)\n",
841841
" # fit.set_params_reltol (1.0e-8)\n",
842842
" # fit.set_m2lnL_reltol (1.0e-11)\n",
843843
"\n",
@@ -948,7 +948,7 @@
948948
"init_sampler.set_cov_from_rescale(1.0e-1)\n",
949949
"\n",
950950
"nwalkers = 100\n",
951-
"stretch = Ncm.FitESMCMCWalkerAPS.new(nwalkers, mset3.fparams_len())\n",
951+
"stretch = Ncm.FitESMCMCWalkerAPES.new(nwalkers, mset3.fparams_len())\n",
952952
"\n",
953953
"esmcmc = Ncm.FitESMCMC.new(fit3, nwalkers, init_sampler, stretch, Ncm.FitRunMsgs.SIMPLE)\n",
954954
"esmcmc.set_data_file(\"example2_fit3_esmcmc_out_aps.fits\")\n",
@@ -1026,7 +1026,7 @@
10261026
"outputs": [],
10271027
"source": [
10281028
"ser = Ncm.Serialize.new(0)\n",
1029-
"data = fit3.lh.dset.get_data(0)\n",
1029+
"data = fit3.peek_likelihood().peek_dataset().get_data(0)\n",
10301030
"ser.to_file(data, \"example2_fit3_data.obj\")"
10311031
]
10321032
}

examples/NumCosmo/modeling_cmp_numcosmo.ipynb

+36-58
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)