Skip to content

refactor(py)!: make phylo2vec.opt importable without the GradME extras - #1

Closed
Neclow wants to merge 1 commit into
mainfrom
refactor/optional-gradme
Closed

Neclow wants to merge 1 commit into
mainfrom
refactor/optional-gradme

Conversation

@Neclow

@Neclow Neclow commented Nov 6, 2026

Copy link
Copy Markdown
Owner

Summary

phylo2vec.opt imported GradME eagerly, so importing anything from it required jax, optax, tqdm and rpy2. This prepares phylo2vec.opt for the upcoming BME functions, which need none of them.

  • opt/__init__.py imports GradME and gradme_loss in a try block. Without the extras, the rest of phylo2vec.opt imports normally, and from phylo2vec.opt import GradME raises an ImportError that names the extras to install (chained to the original error). __all__ and list_methods() only include GradME when it can be imported.
  • The [opt] extras are renamed [gradme], since only GradME needs them. joblib is dropped from them, as it is already a core dependency.
  • pixi run test now runs the docstring examples in phylo2vec.opt, except in the modules that need the extras or numba (_gradme.py, _gradme_losses.py, utils.py, _beagle_losses.py).
  • README, installation page, API reference, optimisation notebook and comments now point to [gradme].
  • New tests/test_opt.py checks the import behaviour with jax hidden, in a separate interpreter.

Locally, the new tests and the package doctests pass; the doctest run now includes the list_methods example.

Breaking change

pip install phylo2vec[opt] no longer installs the GradME dependencies: pip warns that the extra does not exist and installs phylo2vec alone. Use pip install phylo2vec[gradme] instead.

Not in this PR

numba, imported by opt/_beagle_losses.py, is not declared in any dependency list.

phylo2vec.opt imported GradME eagerly, so any import from it needed jax,
optax, tqdm and rpy2. GradME is now imported in a try block: without
these, the rest of phylo2vec.opt imports, and asking for GradME raises
an ImportError that says what to install.

Since only GradME needs them, the [opt] extras are renamed [gradme].
joblib is dropped from them, as it is already a core dependency.

The test task now runs the docstring examples of the phylo2vec.opt
modules that need no extras, instead of skipping the whole package.

BREAKING CHANGE: the [opt] extras are now [gradme].
`pip install phylo2vec[opt]` only warns that the extra does not exist
and installs phylo2vec without the GradME dependencies.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@deepsource-io

deepsource-io Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in 5317cd2...5fc24bf on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
Rust Nov 6, 2026 2:14p.m. Review ↗
Python Nov 6, 2026 2:14p.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

@Neclow

Neclow commented Nov 6, 2026

Copy link
Copy Markdown
Owner Author

Moved to sbhattlab#228

@Neclow Neclow closed this Nov 6, 2026
@Neclow
Neclow deleted the refactor/optional-gradme branch November 6, 2026 14:27
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.

1 participant