Esc
Ask AIAnswers may be inaccurate; check the linked pages.Esc
Ask anything about these docs, like how to get started or what a function does.

CondaEnvManager

envs.CondaEnvManager

Manages conda environments for isolated model execution.

The CondaEnvManager creates conda environments with specific Python versions, installs the tempus_bench package, and installs model-specific dependencies from requirements.txt files. It can verify existing environments or create new ones.

Attributes: * env_name (str): Name of the conda environment. * python_version (str): Python version used in the environment. * requirements_path (str): Path to requirements.txt file.

__init__(self, name: str, python: str, requirements_path: str, reinstall: bool = False)

Initialize conda environment manager and verify or create environment.

This method checks if the conda environment exists and is healthy. If it doesn't exist, is unhealthy, or reinstall is True, it creates a new environment and installs dependencies.

Parameter Type Default Description
name str - Name of the conda environment.
python str - Python version (e.g., '3.11' or '3.11.13').
requirements_path str - Path to requirements.txt file for model dependencies.
reinstall bool False If True, removes existing environment before creating new one.

Raises: * RuntimeError: If environment creation or package installation fails.

__enter__(self)

Enter the context manager.

Returns: CondaEnvManager (Returns self for use in with statements.)

__exit__(self, exc_type, exc_val, exc_tb)

Exit the context manager, cleaning up the conda environment.

Parameter Type Default Description
exc_type - - Exception type if an exception occurred.
exc_val - - Exception value if an exception occurred.
exc_tb - - Exception traceback if an exception occurred.

Returns: None (Deletes the conda environment if it was created in this session.)

create_env(self)

Create the conda environment and install tempus_bench package.

This method creates a new conda environment with the specified Python version and installs the tempus_bench package in editable mode.

Raises: * RuntimeError: If environment creation or package installation fails.

install(self, requirements_path: str)

Install dependencies from requirements.txt file in the conda environment.

Parameter Type Default Description
requirements_path str - Path to requirements.txt file.

Raises: * ValueError: If requirements_path does not end with ".txt". * RuntimeError: If dependency installation fails.

run(self, script: str | None = None, args: str = '', command: str | None = None, verbose: bool = False)

Run a Python script or command inside the conda environment.

This method executes a Python script or arbitrary command within the conda environment and returns the result with stdout and stderr.

Parameter Type Default Description
script str \| None None Path to script to run, or module name (e.g., "-m tempus_bench.pipeline.model_executor"). Mutually exclusive with command.
args str "" Arguments string to pass to python script. Arguments are split by whitespace. Defaults to empty string.
command str \| None None Full command string to run. Mutually exclusive with script.
verbose bool False If True, stream stdout/stderr to the console in real time.

Returns: subprocess.CompletedProcess (Result object with stdout, stderr, and returncode attributes.) Raises: * ValueError: If both script and command are provided, or neither is provided. * RuntimeError: If command execution fails.

delete(self)

Delete the conda environment if it was created in this session.

This method removes the conda environment only if it was created during this session (not if it existed beforehand). This allows reuse of existing environments across runs.

Raises: * subprocess.CalledProcessError: If conda environment removal fails.