Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add back n_cpus argument in DeseqDataSet #226

Merged
merged 3 commits into from
Jan 22, 2024
Merged

Add back n_cpus argument in DeseqDataSet #226

merged 3 commits into from
Jan 22, 2024

Conversation

vcabeli
Copy link
Contributor

@vcabeli vcabeli commented Jan 10, 2024

Reference Issue or PRs

Fixes #214

What does your PR implement? Be specific.

Adding back n_cpus as an optional keyword argument in DeseqDataSet, and adding n_cpus as an abstract property in the Inference class, in order to override the cpus of the inference instance passed to DeseqDataSet (let me know if you prefer to not have that and just have a warning instead).

@BorisMuzellec
Copy link
Collaborator

Thanks @vcabeli for this PR!

Regarding the inference, IMO it's better not to require an n_cpus argument and to raise a warning if it is wrongfully provided, as it might not always be relevant (e.g. if a inference backend running on gpus is implemented).

Copy link
Collaborator

@BorisMuzellec BorisMuzellec left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Comment on lines 54 to 64
self._n_processes = utils.get_num_processes(n_cpus)
self._backend = backend

@property
def n_cpus(self) -> int: # noqa: D102
return self._n_processes

@n_cpus.setter
def n_cpus(self, n_cpus: int) -> None:
self._n_processes = n_cpus

Copy link
Collaborator

Choose a reason for hiding this comment

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

I might be missing something but wouldn't it be simpler to just set self.n_cpus = utils.get_num_processes(n_cpus)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, without the abstract property it is indeed simpler to change the default inference's _n_processes to n_cpus

pydeseq2/dds.py Outdated
@@ -270,8 +278,20 @@ def __init__(
self.logmeans = None
self.filtered_genes = None

if n_cpus:
n_cpus = get_num_processes(n_cpus)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we need to call get_num_processes here, because it's already called when the DefaultInference object is initialized. We could expect other inference implementations to handle the n_cpus argument themselves.

Copy link
Contributor Author

@vcabeli vcabeli Jan 18, 2024

Choose a reason for hiding this comment

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

We could expect other inference implementations to handle the n_cpus argument themselves

I think it's reasonable to expect a check during the __init__, but should we expect another check when setting the parameter ? When inference is specified, we would be overriding its n_cpus param without checking it first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could add this check in the setter if we decide to keep it

@BorisMuzellec BorisMuzellec merged commit 4069863 into main Jan 22, 2024
16 checks passed
@BorisMuzellec BorisMuzellec deleted the revert_n_cpus branch January 22, 2024 13:21
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.

Easier access to n_cpus argument in DeseqDataSet
2 participants