Skip to content

Portable BGMN threading/parallelism + fit-aware intensity-order pruning - #35

Merged
Andrea-gm merged 2 commits into
CederGroupHub:mainfrom
lauren-walters:phase-weight-rework-3
Jul 31, 2026
Merged

Portable BGMN threading/parallelism + fit-aware intensity-order pruning#35
Andrea-gm merged 2 commits into
CederGroupHub:mainfrom
lauren-walters:phase-weight-rework-3

Conversation

@lauren-walters

Copy link
Copy Markdown
Collaborator

Change 1 — Bound BGMN threads, keep worker parallelism (portable):

  • New src/dara/hardware.py detects usable cores (SLURM env vars → os.sched_getaffinity → os.cpu_count).
  • settings.py adds BGMN_N_THREADS (default 1, env DARA_BGMN_N_THREADS) and RAY_NUM_CPUS (default = detected cores, env DARA_RAY_NUM_CPUS).
  • BGMN now runs 1 thread per refinement instead of 8, avoiding cores×8 OS-thread oversubscription. ray.init pins num_cpus=RAY_NUM_CPUS (SLURM-safe); the inner BGMN task uses .options(num_cpus=BGMN_N_THREADS); the outer orchestration task uses num_cpus=0 so it no longer pins a core while blocked, freeing all cores for BGMN refinements (concurrency ≈ cores/threads).
  • generate_control_file default n_threads now sourced from BGMN_N_THREADS.

Change 2 — Don't discard a better-fitting branch on the intensity-order heuristic:

  • Existing intensity-order / low-weight-fraction detection is unchanged.
  • A flagged branch is now pruned only if it did NOT improve Rwp by at least 8% vs its parent (MATERIAL_RWP_IMPROVEMENT = 0.08), via the pure helper keep_branch_despite_intensity_order, guarded against missing/zero parent Rwp.
  • New tests/test_search_tree.py covers the helper and integration paths.

Summary

Major changes:

  • feature 1: ...
  • fix 1: ...

Todos

If this is work in progress, what else needs to be done?

  • feature 2: ...
  • fix 2:

Checklist

  • All existing tests pass.
  • Tests have been added for any new features/fixes.
  • Docstrings have been added in the Google docstring format.

Tip: Install pre-commit hooks to auto-check types and linting before every commit:

pip install -U pre-commit
pre-commit install

Change 1 — Bound BGMN threads, keep worker parallelism (portable):
- New src/dara/hardware.py detects usable cores (SLURM env vars →
  os.sched_getaffinity → os.cpu_count).
- settings.py adds BGMN_N_THREADS (default 1, env DARA_BGMN_N_THREADS) and
  RAY_NUM_CPUS (default = detected cores, env DARA_RAY_NUM_CPUS).
- BGMN now runs 1 thread per refinement instead of 8, avoiding cores×8
  OS-thread oversubscription. ray.init pins num_cpus=RAY_NUM_CPUS (SLURM-safe);
  the inner BGMN task uses .options(num_cpus=BGMN_N_THREADS); the outer
  orchestration task uses num_cpus=0 so it no longer pins a core while blocked,
  freeing all cores for BGMN refinements (concurrency ≈ cores/threads).
- generate_control_file default n_threads now sourced from BGMN_N_THREADS.

Change 2 — Don't discard a better-fitting branch on the intensity-order heuristic:
- Existing intensity-order / low-weight-fraction detection is unchanged.
- A flagged branch is now pruned only if it did NOT improve Rwp by at least 8%
  vs its parent (MATERIAL_RWP_IMPROVEMENT = 0.08), via the pure helper
  keep_branch_despite_intensity_order, guarded against missing/zero parent Rwp.
- New tests/test_search_tree.py covers the helper and integration paths.
Reorders type-union members in result.py (parse_values) and utils.py
(get_number) so None comes last, resolving the RUF036 errors flagged by
CI's ruff. Purely a lint fix — no behavior change.
@Andrea-gm
Andrea-gm merged commit 1fd9bed into CederGroupHub:main Jul 31, 2026
2 of 4 checks passed
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