picslike 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,70 @@
1
+ # Python-generated files
2
+ __pycache__/
3
+ *.py[oc]
4
+ build/
5
+ dist/
6
+ wheels/
7
+ *.egg-info
8
+ htmlcov/
9
+ coverage.xml
10
+ src/graphify-out/
11
+
12
+ # Virtual environments
13
+ .venv
14
+ *inputs/
15
+ *outputs/
16
+ *logs/
17
+ *slurms/
18
+ *plots/
19
+ .coverage
20
+
21
+ # Ignore maps/templates except in test directories
22
+ *maps/
23
+ *templates/
24
+ !**/tests/data/**/maps/
25
+ !**/tests/data/**/templates/
26
+
27
+ # Test intermediate artifacts (regenerated during test runs)
28
+ **/tests/data/**/cov_matrix.dat
29
+ **/tests/data/**/errors.dat
30
+ **/tests/data/**/fisher.dat
31
+ **/tests/data/**/geometry.dat
32
+ **/tests/data/**/invCOV*.bin
33
+ **/tests/data/**/reduced_NCVM*.bin
34
+ # Exception: keep Fortran reference files for validation tests
35
+ !**/tests/data/**/fortran_reference/**
36
+
37
+ run_*.py
38
+ /src/*/.library
39
+ /.claude
40
+ /papers
41
+ /sync_to_cluster.sh
42
+
43
+ # Fortran reference/build directories
44
+ /src/*/.fortran
45
+
46
+ # Generated output files in test data
47
+ **/tests/data/**/output_*.bin
48
+ **/tests/data/**/output_*.dat
49
+ **/tests/data/**/*.png
50
+ *.png
51
+ !logos/*.png
52
+ !docs/source/_static/*.png
53
+ !src/**/logos/*.png
54
+ /src/cosmoforge.picslike/tests/data/nside8/B/fortran_reference/theory_spectra
55
+ /src/cosmoforge.qube/benchmarks/sims/bench_T*
56
+ /src/cosmoforge.qube/benchmarks/sims/bench_QU*
57
+ /src/cosmoforge.qube/benchmarks/sims/bench_mpi*
58
+
59
+ # Heavy benchmark fixtures (kept locally, synced to cluster manually)
60
+ /src/cosmoforge.qube/benchmarks/data/
61
+
62
+ src/cosmoforge.qube/scripts/qml_vs_pcl_results.json
63
+ /src/cosmoforge.qube/benchmarks/results
64
+ /src/cosmoforge.qube/benchmarks/sims
65
+ *.json
66
+
67
+ # Local git worktrees
68
+ .worktrees/
69
+ /src/cosmoforge.qube/benchmarks/results
70
+ /src/cosmoforge.qube/benchmarks/sbatch
@@ -0,0 +1,479 @@
1
+ Metadata-Version: 2.4
2
+ Name: picslike
3
+ Version: 1.0.0
4
+ Summary: PICSLike: Pixel-based Inference with Correlated-Skies Likelihood
5
+ Author-email: Giacomo Galloni <giacomo.galloni@unife.it>
6
+ Classifier: Development Status :: 4 - Beta
7
+ Classifier: Intended Audience :: Science/Research
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Operating System :: MacOS
10
+ Classifier: Operating System :: POSIX :: Linux
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Topic :: Scientific/Engineering :: Astronomy
16
+ Classifier: Topic :: Scientific/Engineering :: Physics
17
+ Requires-Python: <3.14,>=3.11
18
+ Requires-Dist: cosmocore
19
+ Requires-Dist: tqdm>=4.67.1
20
+ Provides-Extra: mpi
21
+ Requires-Dist: cosmocore[mpi]; extra == 'mpi'
22
+ Description-Content-Type: text/markdown
23
+
24
+ <p align="center">
25
+ <img src="https://raw.githubusercontent.com/ggalloni/CosmoForge/master/src/cosmoforge.picslike/logos/logo_picslike_light.png#gh-light-mode-only" alt="PICSLike logo (light)" width="50%"/>
26
+ <img src="https://raw.githubusercontent.com/ggalloni/CosmoForge/master/src/cosmoforge.picslike/logos/logo_picslike_dark.png#gh-dark-mode-only" alt="PICSLike logo (dark)" width="50%"/>
27
+ </p>
28
+
29
+ [![PyPI](https://img.shields.io/pypi/v/picslike?include_prereleases)](https://pypi.org/project/picslike/)
30
+ [![Python](https://img.shields.io/pypi/pyversions/picslike)](https://pypi.org/project/picslike/)
31
+ [![Documentation](https://img.shields.io/badge/docs-picslike-blue.svg)](https://cosmoforge.readthedocs.io/en/latest/api/picslike.html)
32
+ [![Parallelization](https://img.shields.io/badge/MPI-parallel-orange.svg)](https://www.mpi-forum.org/)
33
+ [![Method](https://img.shields.io/badge/method-Pixel--based%20Likelihood-red.svg)](https://en.wikipedia.org/wiki/Likelihood_function)
34
+
35
+ > **[PICSLike Documentation](https://cosmoforge.readthedocs.io/en/latest/api/picslike.html) | [Main Documentation](https://cosmoforge.readthedocs.io/en/latest/)**
36
+
37
+ PICSLike (Pixel-based Inference with Correlated-Skies Likelihood) is the pixel-based likelihood analysis engine of CosmoForge, implementing direct likelihood evaluation in map pixel space for cosmological parameter inference from CMB data.
38
+
39
+ ## Overview
40
+
41
+ PICSLike provides pixel-based likelihood computation as an alternative to harmonic-space methods:
42
+
43
+ - **Pixel-based Likelihood**: Direct likelihood evaluation in map pixel space
44
+ - **Parameter Grid Analysis**: Efficient likelihood computation across parameter grids
45
+
46
+ The approach is particularly useful for handling incomplete sky coverage, non-Gaussian features, and scenarios where pixel-space analysis offers computational or methodological advantages.
47
+
48
+ ## Key Features
49
+
50
+ ### Pixel-based Likelihood Analysis
51
+
52
+ - Direct likelihood evaluation in pixel space
53
+ - Natural handling of masked regions
54
+ - Support for temperature and polarization data
55
+ - Cross-correlation analysis support
56
+ - Chi-squared and log-likelihood computation
57
+
58
+ ### Parameter Grid Management
59
+
60
+ - Flexible parameter range specification
61
+ - Theoretical spectra grid management
62
+ - Efficient MPI distribution across parameter points
63
+ - Best-fit parameter extraction
64
+ - Confidence interval computation
65
+
66
+ ### Technical Features
67
+
68
+ - **MPI Parallelization**: Distributed computation across parameter grids
69
+ - **Memory Optimization**: Efficient covariance matrix handling
70
+ - **Instrumental Effects**: Beam convolution and pixel window functions
71
+ - **Flexible Configuration**: YAML-based parameter specification
72
+
73
+ ## Installation
74
+
75
+ PICSLike is part of CosmoForge and installs automatically:
76
+
77
+ ```bash
78
+ pip install -e /path/to/CosmoForge
79
+ ```
80
+
81
+ For MPI support:
82
+
83
+ ```bash
84
+ pip install mpi4py
85
+ ```
86
+
87
+ ## Documentation
88
+
89
+ For detailed API documentation and examples:
90
+
91
+ - **[PICSLike API](https://cosmoforge.readthedocs.io/en/latest/api/picslike.html)** - Pixel-based likelihood computation
92
+ - **[Parameter Grid](https://cosmoforge.readthedocs.io/en/latest/api/picslike/parameter_grid.html)** - Parameter space management
93
+ - **[Likelihood Results](https://cosmoforge.readthedocs.io/en/latest/api/picslike/likelihood_result.html)** - Result storage and analysis
94
+
95
+ ## Quick Start
96
+
97
+ ### Basic Pixel-based Likelihood Analysis
98
+
99
+ ```python
100
+ from picslike import PICSLike
101
+
102
+ # Initialize likelihood analysis
103
+ picslike = PICSLike("config/pixel_analysis.yaml")
104
+
105
+ # Run full pipeline
106
+ picslike.run()
107
+
108
+ # Get results
109
+ chi_squared = picslike.get_chi_squared()
110
+ best_fit = picslike.get_best_fit()
111
+ log_likelihood = picslike.get_log_likelihood()
112
+ ```
113
+
114
+ ### Step-by-Step Execution
115
+
116
+ ```python
117
+ from picslike import PICSLike
118
+
119
+ # Initialize analysis
120
+ picslike = PICSLike("config/pixel_config.yaml")
121
+
122
+ # Setup pipeline components
123
+ picslike.setup_parameter_grid()
124
+ picslike.setup_fields()
125
+ picslike.setup_geometry()
126
+ picslike.setup_covariance_matrices()
127
+ picslike.setup_cls()
128
+ picslike.setup_beams()
129
+ picslike.setup_maps()
130
+
131
+ # Compute likelihood across parameter grid
132
+ picslike.compute()
133
+
134
+ # Save results
135
+ picslike.save_results("output/likelihood_results.pkl")
136
+ ```
137
+
138
+ ### Accessing Simulation Results
139
+
140
+ ```python
141
+ from picslike import PICSLike
142
+
143
+ # Run analysis
144
+ picslike = PICSLike("config.yaml")
145
+ picslike.run()
146
+
147
+ # Get individual simulation results
148
+ simulation_results = picslike.get_simulation_results()
149
+
150
+ # Get mean likelihood result
151
+ mean_result = picslike.get_mean_likelihood_result()
152
+
153
+ # Extract summary statistics
154
+ summary = mean_result.get_summary_statistics()
155
+ ```
156
+
157
+ ## Configuration
158
+
159
+ PICSLike uses YAML configuration files:
160
+
161
+ ### Basic Configuration
162
+
163
+ ```yaml
164
+ # Data specification
165
+ nside: 32
166
+ lmax: 64
167
+ fields: "TEB" # or "TQU"
168
+
169
+ # Input files
170
+ maskfile: "data/mask.fits"
171
+ inputclfile: "data/fiducial_cls.txt"
172
+ covmatfile1: "data/noise_cov1.bin"
173
+ covmatfile2: "data/noise_cov2.bin" # for cross-correlation
174
+
175
+ # Analysis parameters
176
+ do_cross: false
177
+ calibration: 1.0
178
+ nsims: 100
179
+ ```
180
+
181
+ ### Parameter Grid Configuration
182
+
183
+ ```yaml
184
+ # Parameter ranges for likelihood grid
185
+ parameters:
186
+ amplitude:
187
+ - 0.5 # min
188
+ - 1.5 # max
189
+ - 11 # n_points
190
+ tilt:
191
+ - -0.5 # min
192
+ - 0.5 # max
193
+ - 11 # n_points
194
+
195
+ # Theoretical spectra location
196
+ root_dir: "data/templates"
197
+ root_filename: "dls"
198
+ ```
199
+
200
+ ### Beam Configuration
201
+
202
+ ```yaml
203
+ # Beam parameters
204
+ smoothing_type: gaussian # none, gaussian, cosine_legacy, cosine_npipe, file
205
+ fwhmarcmin: 5.0
206
+ beam_file: "data/beam.fits"
207
+ apply_pixwin: true
208
+ smooth_pol: true
209
+ ```
210
+
211
+ ## MPI Usage
212
+
213
+ Run analyses in parallel:
214
+
215
+ ```bash
216
+ # Pixel-based likelihood analysis
217
+ mpirun -n 4 python -c "
218
+ from picslike import PICSLike
219
+ picslike = PICSLike('config.yaml')
220
+ picslike.run()
221
+ "
222
+
223
+ # Full analysis with result saving
224
+ mpirun -n 8 python main_picslike.py config/pixel_analysis.yaml
225
+ ```
226
+
227
+ ## Analysis Pipeline
228
+
229
+ ### Likelihood Computation Pipeline
230
+
231
+ 1. **Setup**: Read parameters and initialize fields
232
+ 2. **Parameter Grid**: Configure parameter ranges and load theoretical spectra
233
+ 3. **Geometry**: Compute pixel pointing vectors
234
+ 4. **Covariance**: Load noise covariance matrices
235
+ 5. **Maps**: Read input observation maps
236
+ 6. **Broadcast**: Distribute data across MPI processes
237
+ 7. **Compute**: Evaluate likelihood at each parameter point
238
+ 8. **Results**: Gather and store likelihood values
239
+
240
+ ### Likelihood Function
241
+
242
+ The pixel-based likelihood is computed as:
243
+
244
+ ```
245
+ ln L(theta) = -1/2 * (d - s(theta))^T * C^(-1) * (d - s(theta))
246
+ ```
247
+
248
+ where:
249
+ - `d` is the observed data vector
250
+ - `s(theta)` is the theoretical signal for parameters theta
251
+ - `C` is the total covariance matrix (signal + noise)
252
+
253
+ ## API Reference
254
+
255
+ ### PICSLike Class
256
+
257
+ ```python
258
+ class PICSLike(Core):
259
+ """Pixel-based likelihood analysis implementation."""
260
+
261
+ def run(self):
262
+ """Execute complete likelihood analysis."""
263
+
264
+ def compute(self):
265
+ """Compute likelihood across parameter grid."""
266
+
267
+ def get_chi_squared(self):
268
+ """Get chi-squared values."""
269
+
270
+ def get_log_likelihood(self):
271
+ """Get log-likelihood values."""
272
+
273
+ def get_best_fit(self):
274
+ """Get best-fit parameter values."""
275
+
276
+ def save_results(self, output_path):
277
+ """Save results to file."""
278
+ ```
279
+
280
+ ### ParameterGrid Class
281
+
282
+ ```python
283
+ class ParameterGrid:
284
+ """Manager for parameter grids and theoretical spectra."""
285
+
286
+ def get_total_points(self):
287
+ """Get total number of grid points."""
288
+
289
+ def get_points_for_process(self, rank, size):
290
+ """Get parameter points for an MPI process."""
291
+
292
+ def get_spectrum(self, param_point):
293
+ """Get theoretical spectrum for a parameter point."""
294
+ ```
295
+
296
+ ### LikelihoodResult Class
297
+
298
+ ```python
299
+ class LikelihoodResult:
300
+ """Container for likelihood computation results."""
301
+
302
+ def get_best_fit(self):
303
+ """Get best-fit parameter values."""
304
+
305
+ def get_confidence_intervals(self, confidence_level=0.68):
306
+ """Compute confidence intervals."""
307
+
308
+ def get_marginalized_likelihood(self, parameter_name):
309
+ """Get marginalized likelihood for a parameter."""
310
+
311
+ def get_summary_statistics(self):
312
+ """Get comprehensive summary statistics."""
313
+
314
+ def save(self, output_path):
315
+ """Save results to file."""
316
+
317
+ @classmethod
318
+ def load(cls, input_path):
319
+ """Load results from file."""
320
+ ```
321
+
322
+ ## Output Files
323
+
324
+ ### Likelihood Analysis Outputs
325
+
326
+ - `likelihood_results.pkl`: Complete likelihood results
327
+ - `likelihood_results_sim_XX.pkl`: Individual simulation results
328
+
329
+ ### Result Content
330
+
331
+ - Chi-squared values across parameter grid
332
+ - Log-likelihood values
333
+ - Best-fit parameters
334
+ - Confidence intervals (68%, 95%)
335
+ - Marginalized likelihoods
336
+
337
+ ## Performance Optimization
338
+
339
+ ### Memory Management
340
+
341
+ - Efficient covariance matrix handling
342
+ - In-place operations where possible
343
+ - Memory-mapped file I/O for large datasets
344
+
345
+ ### Computational Efficiency
346
+
347
+ - Signal matrix computation optimized with Numba
348
+ - Optimized BLAS/LAPACK operations
349
+ - MPI load balancing across parameter points
350
+
351
+ ### Scaling
352
+
353
+ Typical performance scaling:
354
+
355
+ ```text
356
+ Processes Speed-up
357
+ 1 1.0x
358
+ 2 1.9x
359
+ 4 3.7x
360
+ 8 7.3x
361
+ 16 14.2x
362
+ ```
363
+
364
+ ## Testing
365
+
366
+ Run the test suite (from the repository root):
367
+
368
+ ```bash
369
+ uv run pytest src/cosmoforge.picslike/tests/ -s
370
+ ```
371
+
372
+ Specific tests:
373
+
374
+ ```bash
375
+ uv run pytest src/cosmoforge.picslike/tests/test_likelihood_result.py -s
376
+ uv run pytest src/cosmoforge.picslike/tests/test_parameter_grid.py -s
377
+ uv run pytest src/cosmoforge.picslike/tests/test_picslike.py -s
378
+ ```
379
+
380
+ ## Examples
381
+
382
+ ### Mock Data Generation
383
+
384
+ ```bash
385
+ # Generate mock inputs for temperature-only analysis
386
+ python scripts/produce_mock_inputs.py T /data/mocks config.yaml
387
+
388
+ # Generate with Galactic mask
389
+ python scripts/produce_mock_inputs.py TQU /data/mocks config.yaml --mask
390
+ ```
391
+
392
+ ### Parameter Constraint Analysis
393
+
394
+ ```python
395
+ from picslike import PICSLike, LikelihoodResult
396
+
397
+ # Run likelihood analysis
398
+ picslike = PICSLike("config.yaml")
399
+ picslike.run()
400
+
401
+ # Get likelihood result
402
+ result = picslike.get_mean_likelihood_result()
403
+
404
+ # Get confidence intervals
405
+ intervals_68 = result.get_confidence_intervals(0.68)
406
+ intervals_95 = result.get_confidence_intervals(0.95)
407
+
408
+ # Get marginalized likelihood for specific parameter
409
+ marg_like = result.get_marginalized_likelihood('amplitude')
410
+
411
+ print(f"Best-fit parameters: {result.get_best_fit()}")
412
+ print(f"68% confidence intervals: {intervals_68}")
413
+ ```
414
+
415
+ ## Scientific Context
416
+
417
+ Pixel-based likelihood methods provide several advantages:
418
+
419
+ 1. **Incomplete sky coverage**: Natural handling of masked regions without harmonic-space complications
420
+ 2. **Non-Gaussian features**: Direct treatment of non-Gaussian signals and systematics
421
+ 3. **Cross-correlation analysis**: Efficient computation of cross-correlations between different maps
422
+ 4. **Computational efficiency**: Faster for certain analysis configurations
423
+
424
+ ## Troubleshooting
425
+
426
+ ### Common Issues
427
+
428
+ 1. **Memory errors**: Reduce nside or use more MPI processes
429
+ 2. **Missing spectra errors**: Ensure theoretical spectra exist for all grid points
430
+ 3. **MPI hanging**: Ensure consistent configuration across processes
431
+
432
+ ### Debug Mode
433
+
434
+ Enable detailed logging:
435
+
436
+ ```yaml
437
+ feedback: 4 # Maximum verbosity
438
+ ```
439
+
440
+ ### Performance Profiling
441
+
442
+ ```python
443
+ import cProfile
444
+
445
+ def run_analysis():
446
+ picslike = PICSLike("config.yaml")
447
+ picslike.run()
448
+
449
+ cProfile.run('run_analysis()', 'profile_output.prof')
450
+ ```
451
+
452
+ ## Contributing
453
+
454
+ See the main CosmoForge README for contribution guidelines.
455
+
456
+ ## Citation
457
+
458
+ If you use PICSLike (as part of CosmoForge) in your research, please cite:
459
+
460
+ > Galloni, G. & Pagano, L., *CosmoForge I: A unified framework for QML power spectrum estimation and pixel-based likelihood analysis*, in preparation (2026).
461
+
462
+ ```bibtex
463
+ @article{GalloniPagano_CosmoForgeI,
464
+ author = {Galloni, G. and Pagano, L.},
465
+ title = {{CosmoForge I}: A unified framework for {QML} power spectrum estimation and pixel-based likelihood analysis},
466
+ year = {2026},
467
+ note = {in preparation}
468
+ }
469
+ ```
470
+
471
+ This entry will be updated with the arXiv identifier and journal reference once available.
472
+
473
+ ## References
474
+
475
+ - Wandelt, B.D., Larson, D.L. & Lakshminarayanan, A. "Global, exact cosmic microwave background data analysis using Gibbs sampling" Phys. Rev. D 70, 083511 (2004)
476
+ - Jewell, J., Levin, S. & Anderson, C.H. "Application of Monte Carlo algorithms to the Bayesian analysis of the cosmic microwave background" Astrophys. J. 609, 1-14 (2004)
477
+ - Eriksen, H.K. et al. "Power Spectrum Estimation from High-Resolution Maps by Gibbs Sampling" Astrophys. J. Suppl. 155, 227-241 (2004)
478
+ - Planck Collaboration "Planck 2018 results. V. CMB power spectra and likelihoods" Astron. Astrophys. 641, A5 (2020)
479
+ - Tegmark, M. "How to measure CMB power spectra without losing information" Phys. Rev. D 55, 5895 (1997)