Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@

import logging
import os
import re
import shlex
import shutil
import subprocess
import sys
import warnings

Expand Down Expand Up @@ -71,13 +74,42 @@ def __init__(self) -> None:
else:
self.environment_manager = "conda"
warnings.warn(
f"Warning: could not configure an environment manager for `PyRosettaCluster`. "
"Could not configure an environment manager for `PyRosettaCluster`. "
+ "Please ensure that either of 'pixi', 'uv', 'mamba', or 'conda' is installed. "
+ "Using 'conda' as the default environment manager.",
UserWarning,
stacklevel=7,
)

@property
def environment_manager_version(self) -> str:
"""Return the version of the given environment manager."""

cmd = [self.environment_manager, "--version"]
try:
output = subprocess.check_output(
cmd,
text=True,
stderr=subprocess.STDOUT,
).strip()
except (FileNotFoundError, subprocess.CalledProcessError):
version = ""
else:
found = re.search(r"v?(\d+(?:\.\d+)+)", output)
version = found.group(1) if found else ""

if not version:
cmd_str = shlex.join(cmd)
warnings.warn(
f"Could not determine the {self.environment_manager!r} environment manager version "
+ f"for `PyRosettaCluster` from running `{cmd_str}`. Please ensure that the environment "
"manager version is saved for environment reproducibility.",
UserWarning,
stacklevel=7,
)

return version

@property
def env_export_cmd(self) -> str:
"""
Expand Down Expand Up @@ -131,6 +163,11 @@ def get_environment_manager() -> str:
return get_environment_config().environment_manager


def get_environment_manager_version() -> str:
"""Get the configured environment manager version."""
return get_environment_config().environment_manager_version


def get_environment_cmd() -> str:
"""Get the configured environment export command."""
return get_environment_config().env_export_cmd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,10 @@
TaskBase,
_get_residue_type_set,
)
from pyrosetta.distributed.cluster.config import get_environment_manager
from pyrosetta.distributed.cluster.config import (
get_environment_manager,
get_environment_manager_version,
)
from pyrosetta.distributed.cluster.converters import (
is_empty as _is_empty,
_maybe_issue_environment_warnings,
Expand Down Expand Up @@ -979,6 +982,14 @@ class PyRosettaCluster(IO, LoggingSupport, SchedulerManager, SecurityIO, TaskBas
init=False,
validator=attr.validators.instance_of(str),
)
environment_manager_version: str = attr.field(
default=attr.Factory(
get_environment_manager_version,
takes_self=False,
),
init=False,
validator=attr.validators.instance_of(str),
)
environment_file: str = attr.field(
default=attr.Factory(
lambda self: os.path.join(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ def _save_results(self, results: Optional[bytes], kwargs: Dict[str, Any]) -> Non
"PyRosettaCluster_output_file": output_file,
}
extra_kwargs["PyRosettaCluster_environment_manager"] = self.environment_manager
extra_kwargs["PyRosettaCluster_environment_manager_version"] = self.environment_manager_version
if self.toml:
extra_kwargs["PyRosettaCluster_toml"] = self.toml
if self.toml_format:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ def test_io(self):
self.assertIn("instance", entry.keys())
self.assertIn("metadata", entry.keys())
self.assertIn("scores", entry.keys())
self.assertIn("environment_manager", entry["metadata"])
self.assertIn("environment_manager_version", entry["metadata"])
self.assertIn("my_string_score", entry["scores"])
self.assertEqual(entry["scores"]["my_string_score"], IOTest._my_string_value)
self.assertIn("my_real_score", entry["scores"])
Expand All @@ -202,8 +204,11 @@ def test_io(self):
self.assertIn("instance", df.columns)
self.assertIn("metadata", df.columns)
self.assertIn("scores", df.columns)
metadata = df["metadata"]
scores = df["scores"]
for index in scores.index:
self.assertIn("environment_manager", metadata.loc[index].keys())
self.assertIn("environment_manager_version", metadata.loc[index].keys())
self.assertIn("my_string_score", scores.loc[index].keys())
self.assertEqual(scores.loc[index]["my_string_score"], IOTest._my_string_value)
self.assertIn("my_real_score", scores.loc[index].keys())
Expand Down
1 change: 1 addition & 0 deletions tests/benchmark/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"cryptography": ">=2.8",
"dask": ">=2.16.0",
"dask-jobqueue": ">=0.7.0",
"decorator": ">=4.3.0",
"distributed": ">=2.16.0",
"gitpython": ">=3.1.1",
"jupyter": ">=1.0.0",
Expand Down