Skip to content

Unify and extend parallel configuration#307

Open
xiesl97 wants to merge 3 commits intowcxve:mainfrom
xiesl97:parall_set
Open

Unify and extend parallel configuration#307
xiesl97 wants to merge 3 commits intowcxve:mainfrom
xiesl97:parall_set

Conversation

@xiesl97
Copy link
Copy Markdown
Collaborator

@xiesl97 xiesl97 commented Mar 12, 2026

No description provided.

xiesl97 added 2 commits March 12, 2026 12:37
…xecution-in-functions

Unify and extend parallel configuration for samplers and posterior evaluations
Copilot AI review requested due to automatic review settings March 12, 2026 04:40
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 12, 2026

Summary by CodeRabbit

  • New Features

    • Flexible parallelization configuration: parallel parameter now accepts boolean values, integers, or device sequences across fitting methods.
    • Parallelization control added to result computation methods (flux, luminosity, covariance).
  • Refactor

    • Parameter names updated: n_parallelparallel_chains (AIES, ESS); n_parallelparallel (emcee, zeus, nautilus).

Walkthrough

The changes refactor parallel execution configuration across multiple sampler classes by renaming n_parallel to parallel_chains (AIES, ESS) or parallel (emcee, zeus, nautilus), introducing a centralized _parse_parallel_setting static method to normalize bool/int/Device sequence inputs into worker counts. Result methods are updated with optional parallel and n_parallel parameters to enable dynamic control over parallelization during evaluation.

Changes

Cohort / File(s) Summary
Sampler parameter refactoring (AIES/ESS)
src/elisa/infer/fit.py (AIES, ESS classes)
Renamed n_parallel parameter to parallel_chains across AIES and ESS fit methods; updated docstrings and internal logic to reference new parameter name.
Sampler parameter refactoring (emcee/zeus)
src/elisa/infer/fit.py (emcee, zeus methods/wrappers)
Replaced `n_parallel: int
Nautilus sampler updates
src/elisa/infer/fit.py (nautilus method/wrapper)
Added new `parallel: bool
Parallel parsing utility
src/elisa/infer/fit.py
Introduced static `_parse_parallel_setting(parallel: bool
Result evaluation parameter expansion
src/elisa/infer/results.py (MLEResult, PosteriorResult classes)
Added optional parallel: bool and `n_parallel: int
Test file removal
tests/test_fit.py
Deleted entire test module containing parametrized tests for MaxLikeFit and BayesFit across multiple sampler backends; removed seed/state integrity checks and analytic validation logic.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive No pull request description was provided by the author, making it impossible to assess whether any description content is related to the changeset. Add a description explaining the motivation, implementation details, and impact of the parallelization configuration refactoring.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Unify and extend parallel configuration' directly describes the main changes: refactoring parallelization parameters across multiple fit methods and introducing a centralized _parse_parallel_setting utility.
Docstring Coverage ✅ Passed Docstring coverage is 85.71% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR standardizes and expands how parallelism is configured across inference backends and posterior-intensity utilities.

Changes:

  • Introduces a unified parallel setting (bool/int/device sequence) for some samplers and adds a parser to convert it to a worker count.
  • Extends posterior intensity CI evaluation (flux, lumin, eiso) to accept parallel / n_parallel controls.
  • Removes the existing end-to-end fit tests that exercised multiple backends and parallel options.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
tests/test_fit.py Deletes broad integration tests that covered multiple fitting methods and parallel settings.
src/elisa/infer/results.py Adds parallel / n_parallel plumbing to posterior intensity CI computations (flux/lumin/eiso).
src/elisa/infer/fit.py Renames/reshapes parallel configuration for multiple samplers and adds a _parse_parallel_setting helper.
Comments suppressed due to low confidence (2)

src/elisa/infer/fit.py:1

  • The public API now accepts parallel as a Sequence[Device], but the implementation only uses len(parallel) and discards which devices were provided. This can surprise callers who pass an explicit device list expecting sampling to be pinned to those devices. Consider either (a) narrowing the accepted type to bool | int (and updating docs accordingly), or (b) honoring the provided device list by passing it through to the sampler/backend (or introducing a separate devices= argument) instead of treating it as only a count.
"""Model fit in a maximum likelihood or Bayesian way."""

src/elisa/infer/results.py:1

  • The docstring says n_parallel defaults to jax.local_device_count(), but the implementation routes through get_parallel_number(self._n_parallel if n_parallel is None else n_parallel), which may resolve to a configured self._n_parallel value rather than local_device_count(). Also, the wording 'parallel processes' is potentially misleading here since JAX parallelism is typically device-based; consider updating the docs to reflect the actual default resolution and whether this is device-count vs process-count parallelism.
"""Subsequent analysis of maximum likelihood or Bayesian fit."""

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread src/elisa/infer/fit.py
Comment thread src/elisa/infer/fit.py
Comment thread src/elisa/infer/results.py
Comment thread src/elisa/infer/results.py
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/elisa/infer/fit.py (1)

1549-1570: Move this parser into a shared utility.

Keeping the normalization private to BayesFit means results.py still has to hand-roll the same fallback logic, and that copy has already drifted into a runtime bug. Extracting this into a common helper would actually unify the parallel API surface.

♻️ Suggested direction
-from elisa.util.config import get_parallel_number
+from elisa.util.config import get_parallel_number, parse_parallel_setting

-    `@staticmethod`
-    def _parse_parallel_setting(
-        parallel: bool | int | Sequence[Device],
-    ) -> int:
-        ...
+    # Reuse parse_parallel_setting() here and from results.py.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/elisa/infer/fit.py` around lines 1549 - 1570, Extract the
parallel-normalization logic from BayesFit._parse_parallel_setting into a shared
helper (e.g., parse_parallel_setting) in a common utils module and update
callers to use it: implement the helper to accept parallel:
bool|int|Sequence[Device] and reproduce the exact behavior (bool ->
get_parallel_number(None) or 1, int -> get_parallel_number(int), non-empty
Sequence -> get_parallel_number(len(sequence)), raise ValueError on empty
sequence and TypeError otherwise), replace the private
BayesFit._parse_parallel_setting to call/delegate to this new helper, and update
results.py (and any other callers) to use the new parse_parallel_setting so the
logic is unified and no duplicated fallback remains.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/elisa/infer/results.py`:
- Around line 1535-1537: PosteriorResult.covar raises NameError because it
references n_parallel which isn't defined; add an explicit parameter n_parallel:
int | None = None to the PosteriorResult.covar public signature and update its
docstring to document this override, then use the existing expression
get_parallel_number(self._n_parallel if n_parallel is None else n_parallel) (as
in the diff) so the method falls back to self._n_parallel when not provided.

---

Nitpick comments:
In `@src/elisa/infer/fit.py`:
- Around line 1549-1570: Extract the parallel-normalization logic from
BayesFit._parse_parallel_setting into a shared helper (e.g.,
parse_parallel_setting) in a common utils module and update callers to use it:
implement the helper to accept parallel: bool|int|Sequence[Device] and reproduce
the exact behavior (bool -> get_parallel_number(None) or 1, int ->
get_parallel_number(int), non-empty Sequence ->
get_parallel_number(len(sequence)), raise ValueError on empty sequence and
TypeError otherwise), replace the private BayesFit._parse_parallel_setting to
call/delegate to this new helper, and update results.py (and any other callers)
to use the new parse_parallel_setting so the logic is unified and no duplicated
fallback remains.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1a30c5bd-5e41-477f-848e-335bcb7ae59f

📥 Commits

Reviewing files that changed from the base of the PR and between cc1e3fd and 74428f0.

📒 Files selected for processing (3)
  • src/elisa/infer/fit.py
  • src/elisa/infer/results.py
  • tests/test_fit.py
💤 Files with no reviewable changes (1)
  • tests/test_fit.py

Comment thread src/elisa/infer/results.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants