Supporting task retries in PyRosettaCluster (#605)
`PyRosettaCluster` supports running tasks on available compute
resources; however, often it's more economical to run tasks on
preemptible compute resources, such as cloud spot instances or backfill
queues. This PR exposes Dask's task retry API via the
`PyRosettaCluster.distribute` method, allowing configuration of the
number of automatic retries for each submitted task. When the `retries`
keyword argument parameter is set, `PyRosettaCluster` will reschedule
failed tasks up to the specified number of times if compute resources
are reclaimed midway through a protocol.
This PR also adds a logging warning if using the `resources` keyword
argument with `dask` version `<2.1.0`.
Preserve Pose bitwise representation when accessing Pose.cache SimpleMetrics data (#595)
This PR aims to make a minor change to the `Pose.cache` infrastructure.
Currently, accessing SimpleMetrics data in the `Pose.cache` dictionary
via the `get_sm_data` method lazily initializes a `SimpleMetricData`
entry in the `Pose.data` cache. If a `Pose` does not already contain
SimpleMetrics data, then merely accessing this getter method bitwise
mutates the `Pose` (albeit harmlessly, since it only instantiates an
empty container). However, in principle, a getter ought not to modify
the underlying state or binary representation of the `Pose`.
Herein, we instead conditionally check for
`Pose.data().has(CacheableDataType.SIMPLE_METRIC_DATA)`, performing the
same test at the PyRosetta layer that the `get_sm_data` method performs
at the C++ interface. If `False`, then we return an empty dictionary
without lazily initializing a `SimpleMetricData` entry in the
`Pose.data` cache. This minor update enables deterministic behavior when
instantiating `PackedPose` objects, during which the `Pose.cache`
dictionary is accessed to define the `PackedPose.scores` attribute. By
preventing lazy initialization of the SimpleMetrics data cache, the new
behavior is consistent regardless of whether input `Pose` objects
contain SimpleMetrics data. Unit tests are also added herein to ensure
consistency of the underlying bitwise representations of `Pose` objects
with and without SimpleMetrics data.
Add beta_jan25 energy function (#548)
The aim of this PR is to add `beta_jan25` to the `rosetta` source code. This is an updated version of `beta_nov16`.
We will shortly post a manuscript describing how we developed `beta_jan25`. They key updates are to the LJ potential. We identified steric clashing in proteins that were relaxed or designed using `beta_nov16`. We identified examples of this problem in a high-quality benchmark from the `dualoptE` protocol used to train the energy function. We then used this benchmark, and the others in `dualoptE`, to refit a small number of LJ parameters. The refitting largely eliminated the clashing problem, and `beta_jan25` is as good or better than `beta_nov16` when assessed on multiple benchmarks using validation data.
Frank also advised me that -gen_potential should stay the same (on top of beta_nov16), and we decided to have plain -beta invoke beta_jan25.
Restoring the RandomGenerator state with PyRosetta initialization files (#576)
This quick PR supports:
1. Caching Rosetta's `RandomGenerator` Mersenne Twister (MT19937)
internal state in a PyRosetta initialization file
2. Optionally restoring the MT19937 internal state when initializing
from a PyRosetta initialization file
This enables continuity of the PyRosetta session's MT19937 internal
state from the point at which the PyRosetta initialization file was
written, independent of whether the `RandomGenerator` seed was
explicitly configured.
Support task scheduling priorities in PyRosettaCluster (#571)
This PR adds support for finer control of task execution orchestration
in PyRosettaCluster by exposing Dask's work priority API controlling
Dask schedulers. There are two major task execution patterns that the
user may wish to follow when setting up a PyRosettaCluster simulation:
1. _Breadth-first task execution:_ Currently, tasks are always run
generally following a first-in, first-out (FIFO-like) task chain
behavior. This means that when the Dask worker resources are saturated
(which is a typical scenario), all submitted tasks have equal priority
and are front-loaded to the upstream user-defined PyRosetta protocols,
delaying execution of the downstream protocols until all tasks finish
the upstream protocols.
2. _Depth-first task execution:_ This PR enables task chains to run to
completion, by allowing the user to explicitly increase the priority of
tasks submitted to downstream user-defined PyRosetta protocols. This
means that when the Dask worker resources are saturated, once a task
finishes an upstream protocol, it is submitted to the next downstream
protocol with a higher priority than tasks still queued for the upstream
protocols, so task chains may run through all protocols to completion.
For example, to run user-defined PyRosetta protocols with depth-first
task execution, the `priorities` keyword argument is implemented in this
PR where higher priorities take precedence:
```
PyRosettaCluster(...).distribute(
protocols=[protocol_1, protocol_2],
priorities=[0, 10],
)
```
Say the user has 10,000 tasks and only 10 Dask worker threads to run on,
then with depth-first task execution, the process is as follows:
1. All 10,000 tasks are queued to run `protocol_1`
2. 10 tasks immediately are scheduled to run `protocol_1` on available
Dask worker resources
3. As the 10 tasks complete `protocol_1`, they immediately are scheduled
to run `protocol_2` before the other 9,990 tasks queued to run
`protocol_1` are scheduled
4. As those 10 tasks complete `protocol_2`, they are saved to disk, and
the next 10 tasks immediately are scheduled to run `protocol_1`
5. _Etc._
Note that in distributed cluster scenarios, tasks are scheduled on the
remote cluster _asynchronously_ from task submissions from the client,
so due to normal cluster-specific network latencies, even if a task's
priority is higher, there may be short delays in the Dask worker
receiving the task, leading to slightly nondeterministic behavior in
practice, but in general the task execution pattern follows the user's
priority specifications.
Moving the TestEnvironmentReproducibility unit test, and updating environment export commands (#567)
The aim of this PR is to:
- Update the pixi environment export command to save the `pixi.lock`
file, rather than the generic YAML file export which does not pin
package versions necessary for environment reproducibility.
- Add support for the pixi `--manifest-path` flag and the uv `--project`
flag, so that `PyRosettaCluster` simulations can be run from outside of
the pixi manifest or uv project directories.
- Add support to cache the pixi manifest file and uv `pyproject.toml`
file to PyRosettaCluster results, which are necessary to reproduce the
pixi/uv project in conjunction with the cached `pixi.lock` file or
`requirements.txt` file.
- Sanitize conda channels of username/password credentials instead of
stripping out the entire URL from the exported environment file, since
PyRosetta no longer requires a username/password for installatioin,
making the simulation reproduction lifecycle simpler by obviating the
need to reconfigure the conda channel when recreating a virtual
environment.
- Update warning/exception messages for pixi, uv, and mamba, instead of
just expecting conda.
- Move the `pyrosetta.distributed.cluster.recreate_environment` function
to the
[RosettaCommons/pyrosetta-extras](https://github.com/RosettaCommons/pyrosetta-extras)
GitHub repository. The reason is that we encountered the "chicken or the
egg" problem, where the user must install PyRosetta (typically through
an environment manager like pixi, uv, conda, or mamba) in order to gain
access to the `recreate_environment` function, but then the
`recreate_environment` function cannot be run from inside a virtual
environment, since inside the function it calls `pixi install ...` and
`uv venv ...` which can implement global interpreter locks that hang
indefinitely because the outer environment is already activated.
Therefore, the code needs to be run from the system python interpreter,
which requires the `recreate_environment` function to exist in a
separate repository, as it is not functional in the current state.
- Move the
`pyrosetta.tests.distributed.cluster.test_reproducibility.TestEnvironmentReproducibility`
unit tests (and supporting modules) into the
[RosettaCommons/pyrosetta-extras](https://github.com/RosettaCommons/pyrosetta-extras)
GitHub repository. These unit tests do not currently run on the
Benchmark server (due to its implementation of a pure virtual
environment that does not install `conda`, `mamba`, `uv`, or `pixi`) and
were originally added to test the `recreate_environment` function from
the
[RosettaCommons/pyrosetta-extras](https://github.com/RosettaCommons/pyrosetta-extras)
GitHub repository (however that presented a second "chicken or the egg"
problem which will be solved in a separate PR for that repository).
The following is unrelated, but updated while here:
- Add a more helpful exception when using `LocalCluster(security=True)`
and the `cryptography` package is not installed.
Updating pyrosetta.tests.distributed.cluster.test_reproducibility.TestEnvironmentReproducibility unit test (#562)
This PR updates the following:
- Prints log file contents from `PyRosettaCluster` in the original and
reproduced simulation
- Runs unbuffered python subprocesses for better runtime diagnostics in
GitHub Actions
- Enables live output streaming for better runtime diagnostics in GitHub
Actions
- Installs `pip` as a required dependency for the `pyrosetta-installer`
package into the `uv` environment
- Adds a warning to the `recreate_environment` docstring
- Reduces unit test runtime
Add uv/conda/mamba unit tests for PyRosettaCluster virtual environment recreation (#560)
This PR is a follow-up to PR #536 to add unit tests for `uv`, `conda`,
and `mamba` workflows in the PyRosettaCluster simulation reproduction
lifecycle. In particular, this PR changes the
`pyrosetta.distributed.cluster.recreate_environment` function to support
recreating a `conda`/`mamba` virtual environment in a local prefix
directory rather than via a provided environment name to the global
`conda`/`mamba` environment context, which mimics the `uv` and `pixi`
workflows more closely.
Supporting mamba, uv, and pixi environment managers in PyRosettaCluster (#536)
`PyRosettaCluster` currently uses the `conda` environment manager for
simulation reproduction life cycles. Herein this PR, we add support for
`mamba`, `uv`, and `pixi` as well. Upon instantiation of
`PyRosettaCluster`, we now look for the operating system environment
variable `PYROSETTACLUSTER_ENVIRONMENT_MANAGER` to determine if the user
wants to use a certain environment manager, or otherwise fallback on
detecting whether `pixi`, `uv`, `mamba`, or `conda` is an executable to
determine which environment manager to use. A second party reproducing a
simulation may then use the same or a different environment manager,
since the raw YAML file string is universal across environment managers
and is cached in the `PyRosettaCluster` decoy output file and/or
scorefile. Note that unit tests are not added herein because the
Benchmark server implements virtual environments (i.e., using `pip`),
and therefore these new functionalities are not testable at the moment
(and so they may be considered experimental until thoroughly tested).
This PR also cleans up some module-level import side effects (e.g.,
running `distributed.get_worker()` upon importing
`pyrosetta.distributed.cluster`) which were subtly affecting the
PyRosetta documentation builds with `sphinx`.