Skip to content

Commit 59a6c79

Browse files
authored
Merge pull request #15 from NVIDIA-AI-Blueprints/features/uv-lock_sequence_diagram
Migrate to uv package manager
2 parents 3e6414a + 0831fda commit 59a6c79

6 files changed

Lines changed: 67 additions & 49 deletions

File tree

.github/workflows/main.yml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,18 @@ jobs:
5050
python --version
5151
nvidia-smi
5252
53-
echo "===================== Create Virtual Environment ====================="
54-
python -m venv .venv
55-
source .venv/bin/activate
53+
echo "===================== Install uv ====================="
54+
curl -LsSf https://astral.sh/uv/install.sh | sh
55+
export PATH="/root/.cargo/bin:$PATH"
5656
57-
echo "===================== Install Dependencies ====================="
58-
python -m pip install --upgrade pip
59-
pip install .
60-
61-
echo "===================== Install Development Tools ====================="
62-
pip install ".[dev]"
57+
echo "===================== Install Dependencies with uv ====================="
58+
uv sync --extra dev
6359
6460
echo "===================== Install Jupyter ====================="
65-
pip install jupyter jupyterlab ipykernel papermill nbconvert
61+
uv pip install jupyter jupyterlab ipykernel papermill nbconvert
6662
6763
echo "===================== Create Jupyter Kernel ====================="
68-
python -m ipykernel install --user --name=portfolio-opt --display-name "Portfolio Optimization"
64+
uv run python -m ipykernel install --user --name=portfolio-opt --display-name "Portfolio Optimization"
6965
7066
echo "===================== List Jupyter Kernel ====================="
7167
jupyter kernelspec list

.github/workflows/release-2512.yml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,18 @@ jobs:
5151
python --version
5252
nvidia-smi
5353
54-
echo "===================== Create Virtual Environment ====================="
55-
python -m venv .venv
56-
source .venv/bin/activate
54+
echo "===================== Install uv ====================="
55+
curl -LsSf https://astral.sh/uv/install.sh | sh
56+
export PATH="/root/.cargo/bin:$PATH"
5757
58-
echo "===================== Install Dependencies ====================="
59-
python -m pip install --upgrade pip
60-
pip install .
61-
62-
echo "===================== Install Development Tools ====================="
63-
pip install ".[dev]"
58+
echo "===================== Install Dependencies with uv ====================="
59+
uv sync --extra dev
6460
6561
echo "===================== Install Jupyter ====================="
66-
pip install jupyter jupyterlab ipykernel papermill nbconvert
62+
uv pip install jupyter jupyterlab ipykernel papermill nbconvert
6763
6864
echo "===================== Create Jupyter Kernel ====================="
69-
python -m ipykernel install --user --name=portfolio-opt --display-name "Portfolio Optimization"
65+
uv run python -m ipykernel install --user --name=portfolio-opt --display-name "Portfolio Optimization"
7066
7167
echo "===================== List Jupyter Kernel ====================="
7268
jupyter kernelspec list

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,14 @@ wheels/
2626

2727
# Virtual environments
2828
venv/
29+
.venv/
2930
env/
3031
ENV/
3132
cufolio_venv/
3233

34+
# uv cache
35+
.uv/
36+
3337
# Jupyter Notebook
3438
.ipynb_checkpoints
3539

CONTRIBUTING.md

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,29 @@ There are many ways to contribute to Quantitative Portfolio Optimization develop
4444
cd cufolio
4545
```
4646

47-
2. **Create a Virtual Environment**
47+
2. **Install uv (if not already installed)**
4848

4949
```bash
50-
python -m venv .venv
51-
source .venv/bin/activate # On Windows: .venv\Scripts\activate
50+
curl -LsSf https://astral.sh/uv/install.sh | sh
51+
```
52+
53+
For Windows, use:
54+
```powershell
55+
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
5256
```
5357

5458
3. **Install Development Dependencies**
5559

5660
```bash
57-
pip install -e ".[dev]"
61+
uv sync --extra dev
5862
```
5963

60-
This installs NVIDIA GPU-Accelerated Portfolio Optimization in editable mode along with development tools like `black`, `isort`, `flake8`, and `pre-commit`.
64+
This automatically creates a virtual environment and installs the project in editable mode along with development tools like `black`, `isort`, `flake8`, and `pre-commit`.
6165

6266
4. **Set Up Pre-commit Hooks**
6367

6468
```bash
65-
pre-commit install
69+
uv run pre-commit install
6670
```
6771

6872
This will automatically run code formatting and linting checks before each commit.
@@ -74,7 +78,8 @@ For a consistent development environment with all GPU dependencies:
7478
```bash
7579
docker run --gpus all -it --rm -v $(pwd):/workspace nvcr.io/nvidia/pytorch:25.08-py3
7680
cd /workspace
77-
pip install -e ".[dev]"
81+
curl -LsSf https://astral.sh/uv/install.sh | sh
82+
uv sync --extra dev
7883
```
7984

8085
## Coding Standards
@@ -97,8 +102,8 @@ All code must be formatted with:
97102
Run formatters before committing:
98103

99104
```bash
100-
black .
101-
isort .
105+
uv run black .
106+
uv run isort .
102107
```
103108

104109
Or let pre-commit hooks handle it automatically.
@@ -108,7 +113,7 @@ Or let pre-commit hooks handle it automatically.
108113
We use `flake8` for linting. Run it with:
109114

110115
```bash
111-
flake8 src/
116+
uv run flake8 src/
112117
```
113118

114119
### Documentation
@@ -151,13 +156,13 @@ We encourage comprehensive testing of all new features and bug fixes.
151156

152157
```bash
153158
# Run all tests
154-
pytest
159+
uv run pytest
155160

156161
# Run specific test file
157-
pytest tests/test_cvar_optimizer.py
162+
uv run pytest tests/test_cvar_optimizer.py
158163

159164
# Run with coverage
160-
pytest --cov=src --cov-report=html
165+
uv run pytest --cov=src --cov-report=html
161166
```
162167

163168
### Writing Tests
@@ -220,10 +225,10 @@ Explain what changes were made and why.
220225
2. **Run all checks** before submitting:
221226

222227
```bash
223-
black .
224-
isort .
225-
flake8 src/
226-
pytest
228+
uv run black .
229+
uv run isort .
230+
uv run flake8 src/
231+
uv run pytest
227232
```
228233

229234
3. **Create a Pull Request** with:

README.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,27 +110,26 @@ docker run --gpus all -it --rm nvcr.io/nvidia/pytorch:25.08-py3
110110
git clone https://github.com/NVIDIA-AI-Blueprints/quantitative-portfolio-optimization.git
111111
cd quantitative-portfolio-optimization
112112

113-
# Create and activate virtual environment
114-
python -m venv .venv
115-
source .venv/bin/activate
113+
# Install uv (if not already installed)
114+
curl -LsSf https://astral.sh/uv/install.sh | sh
116115

117-
# Install with all dependencies
118-
pip install .
116+
# Install with all dependencies using uv
117+
uv sync
119118

120119
# Optional: Install development tools
121-
pip install ".[dev]"
120+
uv sync --extra dev
122121

123122
# Install Jupyter and create kernel
124-
pip install jupyter jupyterlab ipykernel
123+
uv pip install jupyter jupyterlab ipykernel
125124

126125
# Create a Jupyter kernel for this environment
127-
python -m ipykernel install --user --name=portfolio-opt --display-name "Portfolio Optimization"
126+
uv run python -m ipykernel install --user --name=portfolio-opt --display-name "Portfolio Optimization"
128127

129128
# Launch Jupyter Lab
130-
jupyter lab
129+
uv run jupyter lab
131130
```
132131

133-
**Note:** The PyTorch container already includes CUDA and other GPU dependencies. This installation adds the optimization and ML libraries (cuOpt, cuML).
132+
**Note:** The PyTorch container already includes CUDA and other GPU dependencies. This installation adds the optimization and ML libraries (cuOpt, cuML). The `uv sync` command automatically creates a virtual environment and installs all dependencies from `uv.lock`.
134133

135134
#### Using the Jupyter Kernel
136135

pyproject.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,24 @@ cufolio = "src"
4141
[tool.setuptools.package-data]
4242
"*" = ["*.csv", "*.pkl", "*.parquet"]
4343

44+
[tool.uv]
45+
managed = true
46+
index-url = "https://pypi.org/simple"
47+
48+
[[tool.uv.index]]
49+
name = "nvidia"
50+
url = "https://pypi.nvidia.com/cuopt-cu13/"
51+
explicit = true
52+
53+
[[tool.uv.index]]
54+
name = "nvidia-ml"
55+
url = "https://pypi.nvidia.com/cuml-cu13/"
56+
explicit = true
57+
58+
[tool.uv.sources]
59+
cuopt-cu13 = { index = "nvidia" }
60+
cuml-cu13 = { index = "nvidia-ml" }
61+
4462
[build-system]
4563
requires = ["setuptools>=64", "wheel"]
4664
build-backend = "setuptools.build_meta"

0 commit comments

Comments
 (0)