Commit e85e88b1 authored by Gaetano Scandariato's avatar Gaetano Scandariato
Browse files

tide up of theancillary file structure

parent 16d9c66e
Loading
Loading
Loading
Loading
Loading
+0 −3
Changes for .gitignore: 0 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -53,8 +53,5 @@ examples/


PyAETNA/TOI5572.code-workspace
COMPARISON.md
builds/3c-Rr9_if/0/gitlab/gaetano.scandariato/detached-head-20260426T145445Z-8e72ba51450c.bundle
builds/3c-Rr9_if/0/gitlab/gaetano.scandariato/detached-head-20260426T145445Z-8e72ba51450c.patch
docs/07_FRESH_MACHINE_SETUP_GUIDE_DEBIAN_v2.md
docs/08_QUICK_COMMAND_CARD_FINAL.md

.kilo/code_review_plan.md

deleted100644 → 0
+0 −163
Changes for .kilo/code_review_plan.md: 0 added lines, 163 removed lines.
Original line number Diff line number Diff line
# PyAETNA Code Review Plan

This plan outlines a systematic approach to reviewing the PyAETNA codebase for performance optimization, JAX/JIT compatibility, and code quality.

## 1. Group the Modules by Functionality

### Group 1: Core Sampling and Modeling
- `PyAETNA/sampling/engine/runner.py`
- `PyAETNA/sampling/engine/numpyro_model.py`
- `PyAETNA/sampling/model/core.py`
- `PyAETNA/sampling/model/detrending.py`
- `PyAETNA/sampling/model/gp_models.py`

### Group 2: Kernel and GP-related Modules
- `PyAETNA/gp.py`
- `PyAETNA/kernels/factory.py`
- `PyAETNA/kernels/spectral_mixture.py`

### Group 3: Data Loading and Processing
- `PyAETNA/sampling/engine/data_loader.py`
- `PyAETNA/sampling/data.py`
- `PyAETNA/sampling/engine/checkpoint.py`

### Group 4: Reporting and Visualization
- `PyAETNA/reporting/confidence_bands.py`
- `PyAETNA/reporting/lightcurve_plots.py`
- `PyAETNA/reporting/model_components.py`
- `PyAETNA/reporting/pdf_report.py`
- `PyAETNA/reporting/periodogram_plots.py`
- `PyAETNA/reporting/plot_models.py`
- `PyAETNA/reporting/plot_styling.py`
- `PyAETNA/reporting/panel_detrended.py`
- `PyAETNA/reporting/panel_nontime_residuals.py`
- `PyAETNA/reporting/panel_overlay.py`
- `PyAETNA/reporting/panel_raw.py`
- `PyAETNA/reporting/panel_residuals.py`
- `PyAETNA/reporting/title_formatting.py`
- `PyAETNA/reporting/ttv_plots.py`

### Group 5: Configuration and Parsing
- `PyAETNA/sampling/config/parser/__init__.py`
- `PyAETNA/sampling/config/parser/detrending.py`
- `PyAETNA/sampling/config/parser/gp.py`
- `PyAETNA/sampling/config/parser/planets.py`
- `PyAETNA/sampling/config/parser/prior_refs.py`
- `PyAETNA/sampling/config/parser/scoping.py`
- `PyAETNA/sampling/config/parser/star.py`
- `PyAETNA/sampling/config/priors.py`

### Group 6: Utilities and Helpers
- `PyAETNA/sampling/utils.py`
- `PyAETNA/sampling/precision.py`
- `PyAETNA/sampling/engine/sampler_utils.py`
- `PyAETNA/sampling/engine/utils/logging_utils.py`

### Group 7: Logging and Error Handling
- `PyAETNA/sampling/engine/logging.py`
- `PyAETNA/reporting/logger.py`

### Group 8: Tests and Examples
- `tests/test_gap_detection.py`
- `tests/test_gap_plots.py`
- `tests/test_gp_per_visit.py`
- `tests/test_lc_gp_rv.yaml`
- `tests/test_lc_only.yaml`
- `tests/test_phase_curve.yaml`
- `tests/test_prior_refs.py`
- `tests/test_rv_only.yaml`
- `tests/test_spectral_mixture.py`
- `tests/test_spectral_mixture.yaml`
- `tests/test_spectral_mixture_mcmc.py`

## 2. Checklist for Each Module

For each module, perform the following checks:

### Code Structure and Organization
- [ ] Check for consistent naming conventions
- [ ] Ensure proper module documentation and docstrings
- [ ] Verify that functions and classes are organized logically
- [ ] Check for unnecessary nested functions or classes

### Performance Optimization
- [ ] Look for opportunities to use JAX/JIT compilation
- [ ] Identify and optimize performance bottlenecks
- [ ] Check for inefficient data structures or algorithms
- [ ] Ensure that vectorized operations are used where possible

### Code Quality
- [ ] Remove dead code and unused variables
- [ ] Update or remove outdated comments
- [ ] Check for redundant or unnecessary imports
- [ ] Ensure consistent coding style (PEP 8 compliance)
- [ ] Verify that all functions have proper type hints

### JAX/JIT Compatibility
- [ ] Check for JAX-compatible data types and operations
- [ ] Ensure that all functions can be JIT-compiled
- [ ] Verify that random number generation is handled correctly for JAX
- [ ] Check for any Python features not supported by JAX

### Error Handling and Logging
- [ ] Ensure proper error handling and logging
- [ ] Check for consistent logging levels and formats
- [ ] Verify that all exceptions are caught and handled appropriately

### Testing
- [ ] Ensure that all functions are covered by tests
- [ ] Verify that tests are comprehensive and cover edge cases
- [ ] Check for any test files that need to be updated

## 3. Review Process

1. **Start with Core Modules**: Begin with Group 1 (Core Sampling and Modeling) as these are fundamental to the library's functionality.
2. **Move to Dependencies**: Review Group 2 (Kernel and GP-related Modules) next, as they are closely tied to the core functionality.
3. **Data Processing**: Then move to Group 3 (Data Loading and Processing) to ensure data handling is efficient and correct.
4. **Reporting**: Review Group 4 (Reporting and Visualization) to ensure all visualizations are accurate and performant.
5. **Configuration**: Check Group 5 (Configuration and Parsing) to ensure all configuration options are properly handled.
6. **Utilities**: Review Group 6 (Utilities and Helpers) for any general-purpose functions that might need optimization.
7. **Logging**: Check Group 7 (Logging and Error Handling) to ensure consistent and helpful logging.
8. **Tests**: Finally, review Group 8 (Tests and Examples) to ensure all functionality is properly tested.

**Recommendation**: For each group, follow the checklist provided in the corresponding group-specific plan file. The agent should systematically go through each checklist item to ensure comprehensive review coverage.

## 4. Testing After Each Group

After reviewing each group, run only the relevant tests that pertain to the changes made. Avoid running the entire test suite unless specifically needed, as this can be time-consuming and may not provide targeted feedback on the reviewed code:

- For Groups 1-3: Run core functionality tests only
- For Group 4: Run reporting and visualization tests only
- For Group 5: Run configuration and parsing tests only
- For Groups 6-7: Run utility and logging tests only
- For Group 8: Run the specific tests related to the reviewed examples

## 5. Final Review

After all groups have been reviewed and tested:
- [ ] Perform a final code review for any remaining issues
- [ ] Run a full test suite to ensure everything works as expected
- [ ] Check for any performance regressions

This plan should help you systematically review the codebase while maintaining functionality and improving performance.

## 2. Python Environment Requirements

All Python code in the PyAETNA codebase must be executed using the following interpreter to ensure compatibility with the project's dependencies and configurations:

```bash
/dati/pyenvs/pyaetnaEnv/bin/python
```

This interpreter has been configured with the specific Python version and dependencies required for PyAETNA. Using any other interpreter may result in compatibility issues or missing dependencies.



### Running Tests and Scripts

When running tests or scripts, always use the full path to the interpreter:

```bash
/dati/pyenvs/pyaetnaEnv/bin/python -m pytest tests/
/dati/pyenvs/pyaetnaEnv/bin/python runPyAETNA.py
```
 No newline at end of file

.kilo/code_review_plan_group1.md

deleted100644 → 0
+0 −119
Changes for .kilo/code_review_plan_group1.md: 0 added lines, 119 removed lines.
Original line number Diff line number Diff line
# PyAETNA Code Review Plan: Group 1 - Core Sampling and Modeling

## 1. Context

This group contains the core modules that handle sampling, modeling, and the overall functionality of PyAETNA. These modules are fundamental to the library's operation and require careful review to ensure optimal performance and correctness.

### Criticalities

1. **Performance**: These modules handle computationally intensive tasks like sampling and model fitting. Any inefficiencies here can significantly impact overall performance.
2. **JAX/JIT Compatibility**: Ensuring that these modules are compatible with JAX/JIT compilation is crucial for achieving optimal performance.
3. **Code Quality**: Maintaining clean, well-documented, and well-structured code is essential for future maintainability.

### Suggestions for Improvements

1. **JAX/JIT Optimization**: Look for opportunities to use JAX/JIT compilation to speed up computations.
2. **Vectorization**: Ensure that operations are vectorized where possible to take advantage of JAX's capabilities.
3. **Code Refactoring**: Refactor any complex or poorly structured code to improve readability and maintainability.
4. **Documentation**: Ensure that all functions and classes have proper docstrings and documentation.

### Recommendation

The agent should systematically go through each checklist item to ensure comprehensive review coverage. This will help identify potential improvements and maintain code quality.

## 2. Checklist

### Code Structure and Organization
- [x] Check for consistent naming conventions — consistent overall; found and removed a misleading `@staticmethod` decorator on two module-level functions in `detrending.py` (not inside a class, so it did nothing)
- [x] Ensure proper module documentation and docstrings — added missing docstrings to `get_planet_model`, `_compute_planet_model`, and the `get_polynomial_model`/`get_fourier_model` wrappers in `core.py`
- [x] Verify that functions and classes are organized logically — reviewed, no issues
- [x] Check for unnecessary nested functions or classes — refactored `runSampler_NumPyro` in `runner.py` by decomposing the god-function into a responsibility-based structure: `context.py` (state), `execution.py` (flow), `phases.py` (algorithmic stages), and `sampling_utils.py` (stateless helpers). Verified via fast tests and full `auto`-mode pipeline runs.

### Performance Optimization
- [x] Look for opportunities to use JAX/JIT compilation — implemented batched scatter optimization in `core.py._compute_planet_model` to reduce array updates.
- [x] Identify and optimize performance bottlenecks — optimized `_compute_planet_model` by accumulating contributions locally per instrument.
- [x] Check for inefficient data structures or algorithms — refactored sequential `.at[idx].add` calls to a single update per instrument.
- [x] Ensure that vectorized operations are used where possible — reviewed `core.py`/`detrending.py`; per-visit/per-instrument Python loops are intentional and correct (static, config-determined counts, unrolled at JAX trace time)

### Code Quality
- [x] Remove dead code and unused variables — deleted fully-unused `gp_models.py`; removed 5 dead `PlModel` GP wrapper methods and 3 unused cache attributes from `core.py` (confirmed zero references anywhere in the repo)
- [x] Update or remove outdated comments — fixed a stale comment/logic in `runner.py` referencing a `sampler.py` path that no longer exists (see Open Points: `PyAETNA/sampler.py` was already superseded by `runner.py`); no full comment audit beyond that
- [x] Check for redundant or unnecessary imports — removed unused imports from `core.py`, `detrending.py`, and `runner.py`

### JAX/JIT Compatibility
- [x] Check for JAX-compatible data types and operations — reviewed `core.py`, `detrending.py`, `numpyro_model.py`; no incompatible operations found
- [x] Ensure that all functions can be JIT-compiled — verified via `tests/verify_jit_compatibility.py`
- [x] Verify that random number generation is handled correctly for JAX — confirmed via static analysis of `PyAETNA/sampling/`
- [x] Check for any Python features not supported by JAX — none observed in the reviewed modules

### Error Handling and Logging
- [x] Ensure proper error handling and logging — reviewed all `try/except` blocks in `runner.py`; all degrade gracefully and log the caught exception (no silent swallowing, no bare `except:`)
- [x] Check for consistent logging levels and formats — fixed a real bug: `_build_numpyro_model`'s `log_func` defaulted to plain `print`, but call sites use the `(model_or_path, msg)` two-arg convention from `logging_utils._log`, so unconfigured logging printed the `PlModel` object's repr before every message. Fixed to default to printing just `msg`.
- [x] Verify that all exceptions are caught and handled appropriately — reviewed, appropriate

### Testing
- [x] Ensure that all functions are covered by tests — ran the fast, relevant tests with `/dati/pyenvs/pyaetnaEnv/bin/python`: `test_behavioral_ties.py`, `test_eiv.py`, `test_gp_per_visit.py` (all pass); long MCMC-pipeline tests (`test_rm_effect.py`, `test_spectral_mixture.py`, `test_ttv.py`) were intentionally skipped per instructions
- [x] Verify that tests are comprehensive and cover edge cases — implemented targeted regression tests for normalization scopes and audited `core.py` for edge cases (single instrument/visit, empty param groups, mixed data types).
- [x] Check for any test files that need to be updated — fixed a stale, pre-existing import in `tests/test_gp_per_visit.py` (`from PyAETNA.sampling import ..., _parse_yaml_config` → `from PyAETNA.sampling.config.parser import parse_config`) that was silently breaking `test_config_parsing`

## 3. Modules to Review

- `PyAETNA/sampling/engine/runner.py`
- `PyAETNA/sampling/engine/numpyro_model.py`
- `PyAETNA/sampling/model/core.py`
- `PyAETNA/sampling/model/detrending.py`
- `PyAETNA/sampling/model/gp_models.py`

## 4. Testing After Review

After reviewing these modules, run only the relevant tests that pertain to core sampling and modeling functionality. Avoid running the entire test suite unless specifically needed, as this can be time-consuming and may not provide targeted feedback on the reviewed code.

## 5. Python Environment Requirements

All Python code in the PyAETNA codebase must be executed using the following interpreter to ensure compatibility with the project's dependencies and configurations:

```bash
/dati/pyenvs/pyaetnaEnv/bin/python
```

This interpreter has been configured with the specific Python version and dependencies required for PyAETNA. Using any other interpreter may result in compatibility issues or missing dependencies.



### Running Tests and Scripts

When running tests or scripts, always use the full path to the interpreter:

```bash
/dati/pyenvs/pyaetnaEnv/bin/python -m pytest tests/
/dati/pyenvs/pyaetnaEnv/bin/python runPyAETNA.py tests/test_rv_only.yaml
```

In the latter case, catch the output fom both the terminal and in `tests/PyAETNAouts/test_rv_only.log` for any errors or warnings that may arise during execution.

## 6. Findings and Open Points

### Summary of changes made

- **Deleted** `PyAETNA/sampling/model/gp_models.py` \u2014 confirmed fully unused (no callers anywhere in the repo).
- **`core.py`**: removed 5 dead `PlModel` GP wrapper methods (`prebuild_gp_models`, `get_gp_model_cached`, `get_gp_marginal_logprob`, `get_gp_posterior_prediction`, `get_gp_model`) and 3 unused cache attributes (`gp_models_cached`, `gp_data_cached`, `gp_config_cached`); removed unused `import jax`; fixed a real bug where `get_normalization_model`/`_compute_normalization_model` didn't receive `uniqueInstruments`/`instrument_masks`, breaking `normalization` scope `per_instrument`; added missing docstrings to `get_planet_model`, `_compute_planet_model`, `get_polynomial_model`, `get_fourier_model`.
- **`detrending.py`**: removed unused `import jax`; removed a misleading `@staticmethod` decorator on two module-level functions (`_compute_polynomial_model`, `_compute_fourier_model`) \u2014 they aren't inside a class, so the decorator was a no-op (only "worked" because Python \u2265 3.10 made `staticmethod` objects directly callable).
- **`runner.py`**: removed several unused imports (`numpyro.distributions`, `PlData`/`_validate_and_prepare_columns`, `parse_config`, `_configure_jax_precision`/`_cast_warmup_state_dtype`, `linearizeRollAngle`/`relabel_array`, `sys`); fixed stale repo-root path resolution; fully decomposed the `runSampler_NumPyro` god-function into a modular architecture: `context.py` for state management, `execution.py` for high-level flow, `phases.py` for MCMC stages (warmup, convergence, production), and `sampling_utils.py` for stateless helpers.
- **`sampling_utils.py`**: added a conditional check to the `internal_warmup_if_nuts` warning so it only prints when the NUTS sampler is actually activated (`production_sampler` is `'nuts'` or `'auto'`).
- **`numpyro_model.py`** (reviewed in full for the first time this session): fixed `_build_numpyro_model`'s `log_func` default fallback \u2014 it fell back to plain `print`, but every call site uses the `(model_or_path, msg)` two-arg convention from `engine.utils.logging_utils._log`; unconfigured logging therefore printed the `PlModel` object's repr before every message (visible in test output). Now defaults to a lambda that prints just `msg`.
- **`pdf_report.py`** (outside this group's module list, touched incidentally): changed a log message to include a `WARNING:` prefix for consistency with other warning-level log lines nearby.
- **`tests/`**: added `test_normalization_scopes.py`, `test_core_edge_cases.py`, and `verify_jit_compatibility.py` to verify normalization scopes, core model robustness, and JAX JIT-compilability.
- **JIT/RNG Audit**: verified via `tests/verify_jit_compatibility.py` that core modeling functions trace correctly under `jax.jit()`; static analysis confirmed no stateful RNG calls in sampling modules.
- **`tests/test_gp_per_visit.py`**: fixed a stale import (`from PyAETNA.sampling import PlModel, PlData, _parse_yaml_config`) that no longer exists; replaced with `from PyAETNA.sampling.config.parser import parse_config`, which was silently breaking `test_config_parsing`.
- **`core.py`**: optimized `_compute_planet_model` by replacing sequential `.at[idx].add` calls with local accumulation per instrument, reducing the number of JAX array updates and improving JIT trace efficiency. Verified via core model tests.

### Verification performed

- Import/instantiation smoke test of `core.PlModel`, `detrending`, and `runner` via `/dati/pyenvs/pyaetnaEnv/bin/python`; confirmed removed attributes/methods are gone and the repo-root path fix resolves correctly.
- Ran `test_behavioral_ties.py` (2/2 pass), `test_eiv.py` (5/5 pass), `test_gp_per_visit.py` (5/5 pass) with `/dati/pyenvs/pyaetnaEnv/bin/python`.
- Skipped `test_rm_effect.py`, `test_spectral_mixture.py`, `test_ttv.py` \u2014 these run full MCMC pipelines and were excluded as "long tests" per instructions.
- `git grep` confirmed zero remaining references to all removed dead-code symbols anywhere in the repo (source or tests) before deleting them.

### Open points (not implemented — need a decision before proceeding)

*(None)*
 No newline at end of file

.kilo/code_review_plan_group2.md

deleted100644 → 0
+0 −90
Changes for .kilo/code_review_plan_group2.md: 0 added lines, 90 removed lines.
Original line number Diff line number Diff line
# PyAETNA Code Review Plan: Group 2 - Kernel and GP-related Modules

## Context

This group contains modules that handle Gaussian Processes (GPs) and kernel functions, which are essential for modeling and prediction in PyAETNA. These modules are closely tied to the core functionality and require careful review to ensure correctness and performance.

### Criticalities

1. **Mathematical Correctness**: Ensuring that the GP and kernel implementations are mathematically correct is crucial for accurate modeling.
2. **Performance**: These modules handle computationally intensive tasks like kernel matrix computations. Any inefficiencies here can significantly impact overall performance.
3. **JAX/JIT Compatibility**: Ensuring that these modules are compatible with JAX/JIT compilation is crucial for achieving optimal performance.

### Suggestions for Improvements

1. **JAX/JIT Optimization**: Look for opportunities to use JAX/JIT compilation to speed up kernel matrix computations.
2. **Vectorization**: Ensure that operations are vectorized where possible to take advantage of JAX's capabilities.
3. **Code Refactoring**: Refactor any complex or poorly structured code to improve readability and maintainability.
4. **Documentation**: Ensure that all functions and classes have proper docstrings and documentation.

### Recommendation

The agent should systematically go through each checklist item to ensure comprehensive review coverage. This will help identify potential improvements and maintain code quality.

## Checklist

### Code Structure and Organization
- [ ] Check for consistent naming conventions
- [ ] Ensure proper module documentation and docstrings
- [ ] Verify that functions and classes are organized logically
- [ ] Check for unnecessary nested functions or classes

### Performance Optimization
- [ ] Look for opportunities to use JAX/JIT compilation
- [ ] Identify and optimize performance bottlenecks
- [ ] Check for inefficient data structures or algorithms
- [ ] Ensure that vectorized operations are used where possible

### Code Quality
- [ ] Remove dead code and unused variables
- [ ] Update or remove outdated comments
- [ ] Check for redundant or unnecessary imports
- [ ] Ensure consistent coding style (PEP 8 compliance)
- [ ] Verify that all functions have proper type hints

### JAX/JIT Compatibility
- [ ] Check for JAX-compatible data types and operations
- [ ] Ensure that all functions can be JIT-compiled
- [ ] Verify that random number generation is handled correctly for JAX
- [ ] Check for any Python features not supported by JAX

### Error Handling and Logging
- [ ] Ensure proper error handling and logging
- [ ] Check for consistent logging levels and formats
- [ ] Verify that all exceptions are caught and handled appropriately

### Testing
- [ ] Ensure that all functions are covered by tests
- [ ] Verify that tests are comprehensive and cover edge cases
- [ ] Check for any test files that need to be updated

## Modules to Review

- `PyAETNA/gp.py`
- `PyAETNA/kernels/factory.py`
- `PyAETNA/kernels/spectral_mixture.py`

## Testing After Review

After reviewing these modules, run only the relevant tests that pertain to kernel and GP functionality. Avoid running the entire test suite unless specifically needed, as this can be time-consuming and may not provide targeted feedback on the reviewed code.

## 2. Python Environment Requirements

All Python code in the PyAETNA codebase must be executed using the following interpreter to ensure compatibility with the project's dependencies and configurations:

```bash
/dati/pyenvs/pyaetnaEnv/bin/python
```

This interpreter has been configured with the specific Python version and dependencies required for PyAETNA. Using any other interpreter may result in compatibility issues or missing dependencies.



### Running Tests and Scripts

When running tests or scripts, always use the full path to the interpreter:

```bash
/dati/pyenvs/pyaetnaEnv/bin/python -m pytest tests/
/dati/pyenvs/pyaetnaEnv/bin/python runPyAETNA.py
```
 No newline at end of file

.kilo/code_review_plan_group3.md

deleted100644 → 0
+0 −84

File deleted.

Preview size limit exceeded, changes collapsed.

Loading