Add support for specifying number of CPU cores#12
Merged
Conversation
There was a problem hiding this comment.
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_cpusto 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 onos.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_cpusvalue (e.g., 0 or negative), this branch will trigger but the warning message claimsos.cpu_count()returned an invalid value. Consider validatingn_cpusexplicitly (raise or clamp to 1) and adjusting the warning to reflect whether the invalid value came from user input vsos.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_jobsnow takesn_cpusbut the docstring parameters list doesn’t mention it. Please documentn_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 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.