Update LICENSE.md (#641)
Pursuant to a directive from UW CoMotion, and as approved by the Rosetta
Commons director (Jeff Gray), the automatic granting of non-academic
licenses has been (temporarily) suspended.
Enable task dictionary updates between PyRosetta protocols in PyRosettaCluster (#631)
This quick PR adds an attribute validator in the `PyRosettaCluster`
class for user-defined task dictionaries, verifying that they don't
contain disallowed or reserved keys/values for proper `PyRosettaCluster`
runtime behavior.
Additionally, this PR adds:
- Validation for task dictionary updates between user-defined PyRosetta
protocols.
- A minor update to the `norm_task_options` attribute functionality to
only normalize task options for the first PyRosetta protocol.
Previously, we presumed users would not update task options at all, so
re-normalizing task options for each protocol was reasonable. This now
allows updating task options between protocols while supporting output
decoy reproducibility.
- Unit tests for decoy reproducibility while updating task dictionaries
between user-defined PyRosetta protocols.
- A patch to the `InitFileSigner` class for HMAC-SHA256 verification of
PyRosetta initialization files. Previously, we used the pickled `Pose`
bytestring for HMAC-SHA256 verification; however, for some `Pose`
objects the ordering of internal C++ containers may differ upon
reconstruction from the original bytestring, sometimes failing roundtrip
HMAC-SHA256 verification. Herein, we implement a new `PackedPoseHasher`
class to instead produce a SHA256 hash digest of what we may call the
scientific state of the `Pose` object, which includes the `Pose`
geometry (i.e., residue numbers, residue names, atom numbers, atom
names, and atom coordinate components in double precision), serialized
`Pose.cache` dictionary keys and values, and raw `Pose` comments keys
and values. The scientific state of the `Pose` object is what matters
for decoy reproducibility, not differences in memory layout from
serialization/deserialization roundtrips.
To be merged after #630 for incremental versioning.
add *.pyi stub generation support for bindings in rosetta.so (#588)
Adds the `--stubs` flag to build.py for building pyrosetta, which uses
[pybind11-stubgen](https://github.com/sizmailov/pybind11-stubgen/) to
inspect the C++ bindings generated by binder/pybind11 and generates
`*.pyi` type annotation stub files in the rosetta directory. This allows
static type checkers to see the members, arguments, and (most of the
time*) parameter types included in pyrosetta. Adding `**/*.pyi` files to
the `setup.py` package_data list means these stubs will be included
automatically with any distribution, meaning it should be plug-and-play
with a new release.
This PR adds a dependence on an external pypa package for stub
generation (it's imported in the generate_stubs method so won't affect
the process if unspecified) and I'm not familiar enough with the
setuptools / ez_setup build pipeline to know how that should be
integrated as a requirement. Thoughts? Should it be included as a
submodule like other dependencies? Currently I just throw an error in
generate_stubs in `build.py` if `--stubs` is specified but the package
isn't included.
I think this will make the experience a lot easier for new users. I've
tested it (installing from the `.whl` file in a fresh environment) in
VSCode, and it should be compatible with static type analyzers and
google colab as well!
*pybind11-stubgen uses the docstrings automatically generated by
pybind11 to infer by-reference parameter types. If a module member is
bound by pybind11 which references a type which has itself not yet been
bound, the docstring can't use the python type name (since where the
type should sit in the python module tree hasn't been specified) so it
defaults to the C++ type instead (see the [pybind11
documentation](https://pybind11.readthedocs.io/en/latest/advanced/misc.html#avoiding-cpp-types-in-docstrings)).
Pybind11-stubgen will still include these C++ docstrings in the `*.pyi`
files, which removes ambiguity for users most of the time [the user
sometimes needs to connect the dots that `std::shared_ptr<class
core::pose::PDBInfo>` corresponds to
`pyrosetta.rosetta.core.pose.PDBInfo`] even if it can't properly
annotate parameter types accordingly. This could *theoretically* be
fixed by updating binder to run in two passes, binding all classes first
and then all functions, but that would require a massive refactor for
only marginal gain.
---------
Co-authored-by: Sergey Lyskov <3302736+lyskov@users.noreply.github.com>
Improving resilience of PyRosettaCluster upon Dask worker preemption (#630)
This PR adds two new features to `PyRosettaCluster` to improve the
resilience of a simulation when using preemptible compute resources
(e.g., cloud spot instances or cluster backfill queues):
**1. Task replication on other Dask workers**: Task replication allows
scattered task input arguments to be recovered if a Dask worker
executing a task is preempted midway through a protocol. The number of
task retries is controlled by the Dask configuration parameter
`distributed.scheduler.allowed-failures`, which may be manually
configured prior to the simulation. Additionally, task replication
requires that Dask's Active Memory Manager first be disabled, since task
replicas consume additional memory per Dask worker. This PR just adds
support for the
[Client.replicate](https://distributed.dask.org/en/stable/api.html#distributed.Client.replicate)
method (controlled via the `max_task_replicas` keyword argument); if
enabled, the Dask scheduler can attempt task retries if task arguments
are recoverable.
**2. Client-side task registry**: As a fallback plan, if scattered task
input arguments cannot be recovered after Dask worker preemption (e.g.,
the task replication factor is set too low), then this PR adds
lightweight infrastructure for a durable task registry on the
client-side head node (controlled via the `task_registry` keyword
argument). If enabled and the Dask scheduler cannot resubmit the task
(detected by catching the raised `concurrent.futures.CancelledError`
exception), then `PyRosettaCluster` will automatically resubmit the task
using the task input arguments cached in the task registry. This PR
supports constructing the task registry in memory
(`task_registry="memory"`) for relatively few tasks, or on disk
(`task_registry="disk"`) for production simulations.
Both of these features require that user-defined PyRosetta protocols are
side effect-free upon preemption, so that tasks can be restarted without
producing inconsistent external states; therefore, they are disabled by
default and can be configured based on Dask worker memory limits and the
expected compute resource preemption frequency. Additionally, the
`retries` keyword argument documentation of the
`PyRosettaCluster.distribute` method is clarified, as well as other
minor documentation changes.
Removing variadic keyword parameters from function signatures in PyRosettaCluster (#626)
This PR fixes a minor UX issue in `PyRosettaCluster`, improving API
usability.
In `PyRosettaCluster`, each user-defined task dictionary is unpacked at
the call site of a few internal API functions, and the keyword arguments
are then collected by variadic keyword parameters during execution.
However, if a user-defined task dictionary contains keys that match the
positional-or-keyword parameters in these function signatures, a
`TypeError` is raised due to the argument receiving multiple values.
These parameters currently include: `protocol`, `packed_pose`,
`datetime_format`, `norm_task_options`, `ignore_errors`,
`protocols_key`, `decoy_ids`, and `serializer`. As a remedy, herein we
remove the variadic keyword parameters from the function signatures, and
add relevant unit tests. Since the internal API was already passing
positional arguments, redefining the variadic keyword parameters to
positional-or-keyword parameters now prevents name clashes when also
defined as keyword arguments by the user.
Update PyRosetta.notebooks submodule (#619)
Point PyRosetta.notebooks submodule at rac_edits. This branch has edits
to the pyrosettacolabsetup options, an updated guide for installing
PyRosetta locally, and a Markdown version of the PyMOL workshop.
Minor change to PackedPose.scores dictionary construction (#612)
Currently in PyRosetta, instantiating a `PackedPose` object triggers
deserialization of the `Pose.cache` dictionary (due to the line
`self.scores = dict(pose_or_pack.cache)`). This is usually fine for
single Python processes where users have already added secure packages
to the unpickle-allowed list (i.e., via the `pyrosetta.secure_unpickle`
module); however, `PyRosettaCluster` spawns new threads using the
`billiard` package on Dask workers, where binary blobs are deserialized
into instantiated `PackedPose` objects, triggering deserialization of
the `Pose.cache` dictionary before users have had a chance to add secure
packages to the unpickle-allowed list in the `billiard` subprocess. This
can raise `UnpickleSecurityError` exceptions if users cache arbitrary
Python types in the `Pose.cache` dictionary, even when users add secure
packages in their PyRosetta protocols, since `PackedPose` instantiation
happens before the user-provided PyRosetta protocols run.
In order to remedy this, this PR updates the `PackedPose` class to
instantiate an empty dictionary on the `PackedPose.scores` attribute,
rather than a detached, flattened copy of the `Pose.cache` dictionary.
Not only does this free up duplicated memory usage from all of the
`Pose.cache` scores copied onto the `PackedPose` object, but I think it
improves the `PackedPose` API intention a bit: the `PackedPose` class
already implements the `PackedPose.update_scores` method, which is
specifically designed to embed new scores into the `Pose` object; and
because the `PackedPose.scores` attribute is currently a detached,
flattened copy of the `Pose.cache` dictionary, this can cause confusion
about what are the ground truth scores in the `PackedPose` object.
Regarding `PyRosettaCluster`, by preventing deserialization of the
`Pose.cache` dictionary upon `PackedPose` instantiation, users can now
programmatically add secure packages in their PyRosetta protocols per
Python process (as the `pyrosetta.secure_unpickle` module was designed),
and the underlying `PyRosettaCluster` infrastructure does not
unintentionally deserialize the `Pose.cache` dictionary just to compress
`PackedPose` objects in transit between the client and Dask workers.
Nonetheless, this minor change has the potential to break scripts in the
wild. Anyone's scripts that call `PackedPose.scores` to access score
values (that were originally embedded in the `Pose` object) now needs to
call `PackedPose.pose.cache` (or the deprecated
`PackedPose.pose.scores`). However, the `PackedPose.scores` attribute
still functions the same way as before as a detached dictionary from the
`Pose.cache` infrastructure, but herein this PR it is just not
pre-populated with the `Pose.cache` dictionary upon `PackedPose`
instantiation; users adding scores to the `PackedPose.scores` dictionary
can still access them there (even though the preferred syntax continues
to use the `PackedPose.update_scores` method).
---------
Co-authored-by: Sergey Lyskov <3302736+lyskov@users.noreply.github.com>
Update SecureUnpickler disallowed packages (#611)
This PR updates the `pyrosetta.secure_unpickle.SecureUnpickler` class to
block some additional callable targets via the `pickle` module,
including `numpy.load` and `pandas.read_pickle` modules. Unit tests
added herein demonstrate that secure `numpy`/`pandas` modules like
`numpy.array` and `pandas.DataFrame` are still deserializable.
Minor updates to uv project export machinery in PyRosettaCluster (#608)
This minor PR addresses:
- Instead of relying on an exported `requirements.txt` file from the uv
project, the `uv.lock` file is cached (similar to Pixi which caches the
`pixi.lock` file). The reason for this change is several-fold:
- The `requirements.txt` file does not pin the Python version being used
to execute the `PyRosettaCluster` simulation. We were relying on the
`pyproject.toml` file to provide this information, however, if the user
doesn't pin the Python version in it, then there's no record of which
Python version is being used (other than inspecting the PyRosetta build
string or another hack).
- The `uv export` command doesn't provide sha256 hashes for custom
registries. Now that `pyrosetta` is shipped quarterly, this disallows
using the `uv pip sync --require-hashes` flag which would match hashes
for each requirement, making reproduction more robust. While `uv pip
compile` does support the `--generate-hashes` flag, again the Python
version is not captured in a `requirements.txt` file.
- Currently, `uv export` doesn't support emitting the `--find-links`
paths into the exported `requirements.txt` file. While `uv pip compile`
does support the `--emit-find-links` flag, again the Python version is
not captured in a `requirements.txt` file.
- Ensures the `self.toml_format` attribute is still set for the edge
case where the uv `pyproject.toml` file cannot be automatically located
via either the `UV_PROJECT` environment variable or the current working
directory (which currently leads to an `AttributeError` upon saving
results). A more helpful warning message is provided herein.
- Disables two `FutureWarning`s regarding the `filter_results` and
`norm_task_options` class attributes being enabled by default, which
were introduced in version `2.1.0` (merged ~8/25) and `3.0.0` (merged
~10/25), respectively.
Updated PARCS applications and IMMS_CCS score function (#609)
This application builds on the existing PARCS (parcs_ccs_calc.cc)
application and the IMMS_CCS energy term originally developed by
smturzo.
I extended PARCS to support multimeric protein complexes, enabling
simulation of PARCS CCS data for input structures containing multiple
chains. In addition, the existing IMMS_CCS energy term, which was
previously limited to monomers, was generalized for complexes through
the introduction of a new IMMS_ComplexCCS_Energy term. I also
implemented a new CCS_IMMS_with_CryoEMEnergy score term that integrates
experimental CCS data with cryo-EM information.
Method: For PARCS multimer support, I introduced a boolean flag
(-multimer) to the existing PARCS application. When enabled, the
algorithm predicts CCS values for multimeric assemblies by
reparameterizing the original CCS calculation.
For the IMMS-based energy terms, I developed on the existing
CCS_IMMSEnergy implementation
(source/src/core/energy_methods/CCS_IMMSEnergy.cc/.hh) by adding new
energy classes:
* CCS_IMMSComplexEnergy, which enables CCS-based scoring for protein complexes
* CCS_IMMS_with_CryoEMEnergy, which incorporates cryo-EM restraints alongside experimental CCS data
Integration test: I did integration just like how it was done for
monomers with additional flag. for multimer The test passed.
Fix dropped settings issues in HighResDocker (#520)
The copy constructor of HighResDocker was not copying over the resfile_
member, which means it was ignoring that setting. Since the copy
constructor is effectively a straight member-by-member copy, we can
simply delete it and rely on the autogenerated copy constructor.
Additionally, I noticed that the initialize_from_options() function was
declaring local variables, rather than changing the member variables.
Fix this.