Skip to content

disable jax if PYMBAR_DISABLE_JAX is set#569

Merged
mikemhenry merged 15 commits intochoderalab:mainfrom
mikemhenry:feat/add-disable-jax-at-runtime-option
Oct 16, 2025
Merged

disable jax if PYMBAR_DISABLE_JAX is set#569
mikemhenry merged 15 commits intochoderalab:mainfrom
mikemhenry:feat/add-disable-jax-at-runtime-option

Conversation

@mikemhenry
Copy link
Copy Markdown
Contributor

@mikemhenry mikemhenry commented Oct 10, 2025

This will let a user disable jax at runtime. A larger refactor is needed to test this since at import time the PYMBAR_DISABLE_JAX variable is checked, so even if monkey patched the module has already been imported. This also means that once pymbar has been imported, setting PYMBAR_DISABLE_JAX will do nothing.

TODO: add docs

Comment thread pymbar/mbar_solvers.py Outdated
Comment thread pymbar/mbar_solvers.py Outdated
Comment thread pymbar/tests/test_mbar_solvers.py Outdated
def test_env_values(self, monkeypatch, env_value, expected):
"""Test various environment variable values."""
monkeypatch.setenv("PYMBAR_DISABLE_JAX", env_value)
assert _setup_jax_accleration() is expected
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we want to specify an error message in case the assertion fails? Something like "received X but expected Y"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

pytest will do that for us

Copy link
Copy Markdown
Contributor

@ijpulidos ijpulidos left a comment

Choose a reason for hiding this comment

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

This is looking great, I think this works for our purposes. Just some minor changes/comments.

In the long term I wonder if we want to make the MBAR object itself specify the backend via an argument.

mikemhenry and others added 4 commits October 15, 2025 11:20
Co-authored-by: Iván Pulido <2949729+ijpulidos@users.noreply.github.com>
Co-authored-by: Iván Pulido <2949729+ijpulidos@users.noreply.github.com>
…x-at-runtime-option' into feat/add-disable-jax-at-runtime-option
@mikemhenry
Copy link
Copy Markdown
Contributor Author

#509 is how we will fix this long term, but this should work for now.

@mikemhenry mikemhenry requested a review from ijpulidos October 15, 2025 18:23
Comment thread docs/moving_from_pymbar3.rst Outdated
Comment thread pymbar/tests/test_mbar_solvers.py Outdated
("yes", True),
("YES", True),
("YeS", True),
("0", True),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would expect 0=False and 1=True, no?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

duh! I was thinking about 0 being the "good" exit code and that was "true" to be BUT as soon as you mention that, it is the opposite of the convention

mikemhenry and others added 2 commits October 16, 2025 07:44
Co-authored-by: Alyssa Travitz <31974495+atravitz@users.noreply.github.com>
@mikemhenry mikemhenry requested a review from atravitz October 16, 2025 16:07
Copy link
Copy Markdown
Contributor

@ijpulidos ijpulidos left a comment

Choose a reason for hiding this comment

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

Looking great. One minor comment, but otherwise LGTM.

Comment thread README.md Outdated

However, many packages released on conda-forge specify `pymbar` as a dependency, making it impossible to install the non-jax accelerated of PyMbar.
In `pymbar >= 4.2.0` JAX acceleration can be controlled with the environmental variable `PYMBAR_DISABLE_JAX`.
Setting `PYMBAR_DISABLE_JAX` to a truth-y value (`TRUE`, `YES`, `0`) will disable JAX acceleration even if the `jax` package is installed.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess we mean here 1 instead of 0 as a truth-y value?

@mikemhenry mikemhenry enabled auto-merge (squash) October 16, 2025 19:45
@mikemhenry mikemhenry merged commit 1a89280 into choderalab:main Oct 16, 2025
17 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.

3 participants