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