Skip to content

Add support for specifying number of CPU cores#12

Merged
AsymmetryChou merged 3 commits into
deepmodeling:mainfrom
AsymmetryChou:n_cpus_parallel
May 25, 2026
Merged

Add support for specifying number of CPU cores#12
AsymmetryChou merged 3 commits into
deepmodeling:mainfrom
AsymmetryChou:n_cpus_parallel

Conversation

@AsymmetryChou
Copy link
Copy Markdown
Collaborator

Introduce an option to specify the number of CPU cores for parallel self-energy calculations. Update the relevant functions and examples to utilize this new parameter, enhancing performance and flexibility.

Copy link
Copy Markdown

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 adds a new n_cpus option to control how many CPU cores are used for parallel lead self-energy calculations in the NEGF runner, and updates the atomic chain CLI example to demonstrate its usage.

Changes:

  • Add n_cpus to NEGF task options validation and pass it through the NEGF runner into the self-energy parallelization logic.
  • Update self-energy worker selection to use n_cpus (when provided) instead of always relying on os.cpu_count().
  • Update the atomic chain CLI example input (and notebook outputs) to use n_cpus=2.

Reviewed changes

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

Show a summary per file
File Description
dpnegf/utils/argcheck.py Adds n_cpus to NEGF task option schema.
dpnegf/runner/NEGF.py Accepts/stores n_cpus and forwards it into self-energy computation.
dpnegf/negf/lead_property.py Uses n_cpus to cap worker count and threads it through self-energy computation helpers.
examples/atomic_chain_cli/input_files/negf_chain_new.json Demonstrates n_cpus: 2 in example configuration.
examples/atomic_chain_cli/run.ipynb Updates example run outputs reflecting the new parallel self-energy behavior.
Comments suppressed due to low confidence (2)

dpnegf/negf/lead_property.py:546

  • If the user passes an invalid n_cpus value (e.g., 0 or negative), this branch will trigger but the warning message claims os.cpu_count() returned an invalid value. Consider validating n_cpus explicitly (raise or clamp to 1) and adjusting the warning to reflect whether the invalid value came from user input vs os.cpu_count().
    cpu_count = n_cpus if n_cpus is not None else os.cpu_count()
    if cpu_count is None or cpu_count < 1:
        cpu_count = 1
        log.warning("os.cpu_count() returned None or invalid value. Defaulting to 1 CPU core.")

dpnegf/negf/lead_property.py:524

  • _get_safe_n_jobs now takes n_cpus but the docstring parameters list doesn’t mention it. Please document n_cpus (and expected values, e.g., positive int) so callers understand the override behavior.
def _get_safe_n_jobs(lead_L, lead_R, requested_n_jobs=-1, max_memory_fraction=0.7, min_workers=1, kpoint=None, n_cpus=None):
    """
    Calculate safe number of parallel workers based on available system memory.

    Parameters

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

Comment thread dpnegf/utils/argcheck.py
Comment on lines 594 to 598
def compute_all_self_energy(eta, lead_L, lead_R, kpoints_grid, energy_grid,
self_energy_save_path=None, n_jobs=-1, batch_size=200):
self_energy_save_path=None, n_jobs=-1, batch_size=200, n_cpus=None):
"""
Computes and saves self-energy matrices for all combinations of k-points and energy values
for left and right leads.
Comment thread dpnegf/runner/NEGF.py
Comment thread examples/atomic_chain_cli/run.ipynb
@AsymmetryChou AsymmetryChou merged commit 4263a44 into deepmodeling:main May 25, 2026
1 check 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