From 46044f8d4e8944a66cd4e18615cc5f49505823a2 Mon Sep 17 00:00:00 2001 From: Thomas Schmelzer Date: Sun, 25 May 2025 11:46:41 +0400 Subject: [PATCH 1/8] Move Makefile to uv and simplified README --- Makefile | 46 +++++++++++++++++++++++++++++----------------- README.md | 15 ++++++++------- 2 files changed, 37 insertions(+), 24 deletions(-) diff --git a/Makefile b/Makefile index 9826870b..8be917a5 100644 --- a/Makefile +++ b/Makefile @@ -1,36 +1,48 @@ +# This Makefile provides commands for setting up the development environment, +# running formatting tools, and cleaning the repository. + +# Set the default target to 'help' when running make without arguments .DEFAULT_GOAL := help -VENV :=.venv +# Create a Python virtual environment using uv (faster alternative to venv) +venv: + @curl -LsSf https://astral.sh/uv/install.sh | sh # Install uv if not already installed + @uv venv # Create a virtual environment in the current directory +# Mark 'install' as a phony target (not associated with a file) .PHONY: install -install: ## Install a virtual environment - python -m venv ${VENV} - ${VENV}/bin/pip install --upgrade pip - ${VENV}/bin/pip install -r requirements.txt +install: venv ## Install a virtual environment + @uv pip install --upgrade pip # Ensure pip is up to date + @uv pip install --no-cache-dir -r requirements.txt # Install project dependencies from requirements.txt +# Code Quality .PHONY: fmt fmt: install ## Run autoformatting and linting - ${VENV}/bin/pip install pre-commit - ${VENV}/bin/pre-commit install - ${VENV}/bin/pre-commit run --all-files + @uv pip install pre-commit # Install pre-commit hooks + @uv run pre-commit install # Set up pre-commit hooks + @uv run pre-commit run --all-files # Run pre-commit hooks on all files +# Book Building .PHONY: build build: install ## Build the book - ${VENV}/bin/pip install jupyter-book - ${VENV}/bin/jupyter-book clean book - ${VENV}/bin/jupyter-book build book - touch book/_build/html/.nojekyll + @uv pip install jupyter-book # Install jupyter-book + @uv run jupyter-book clean book # Clean previous builds + @uv run jupyter-book build book # Build the book + touch book/_build/html/.nojekyll # Add .nojekyll file for GitHub Pages +# Cleanup .PHONY: clean clean: ## Clean up caches and build artifacts - @git clean -X -d -f + @git clean -X -d -f # Remove files ignored by git +# Help .PHONY: help help: ## Display this help screen - @echo -e "\033[1mAvailable commands:\033[0m" - @grep -E '^[a-z.A-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-18s\033[0m %s\n", $$1, $$2}' | sort + @echo -e "\033[1mAvailable commands:\033[0m" # Print header in bold + @grep -E '^[a-z.A-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-18s\033[0m %s\n", $$1, $$2}' | sort # Extract and format targets with comments +# Jupyter Setup .PHONY: jupyter jupyter: install ## Start jupyterlab - ${VENV}/bin/pip install jupyterlab - ${VENV}/bin/jupyter lab + @uv pip install jupyterlab # Install JupyterLab + @uv run jupyter lab # Start JupyterLab server diff --git a/README.md b/README.md index cb355b24..b3086f87 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,16 @@ -# [CVXPY tutorial](https://cvxgrp.org/cvx_short_course) +# 📊 [CVXPY tutorial](https://cvxgrp.org/cvx_short_course) + +## 📋 Overview CVXPY is an open source Python-embedded modeling language for convex -optimization problems. It lets you express your problem in a natural way that +optimization problems. It lets you express your problem naturally that follows the math, rather than in the restrictive standard form required by -solvers. This tutorial will cover the basics of convex optimization, and how to +solvers. This tutorial will cover the basics of convex optimization and how to use CVXPY to specify and solve convex optimization problems, with an emphasis on real-world applications. No prior knowledge of convex optimization is assumed. -## Getting started +## 🚀 Getting started 1. Clone this repository. -2. Install CVXPY following [these instructions](https://www.cvxpy.org/install/index.html). -We recommend Python 3.10 and CVXPY 1.3. -3. Test your CVXPY installation by running ``test.py`` in the repository. +2. Install CVXPY by running ``make install`` +3. Test your CVXPY installation by running ``make test`` in the repository. From 131cee17c8fdb22dfe6e707c8ee10fb8b2517f5c Mon Sep 17 00:00:00 2001 From: Thomas Schmelzer Date: Sun, 25 May 2025 11:49:49 +0400 Subject: [PATCH 2/8] Update README.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b3086f87..5feecaba 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,8 @@ ## 📋 Overview CVXPY is an open source Python-embedded modeling language for convex -optimization problems. It lets you express your problem naturally that -follows the math, rather than in the restrictive standard form required by +optimization problems. It lets you express your problem naturally, following +the math, rather than in the restrictive standard form required by solvers. This tutorial will cover the basics of convex optimization and how to use CVXPY to specify and solve convex optimization problems, with an emphasis on real-world applications. No prior knowledge of convex optimization is assumed. From 3a8d6de878d568f026e58a3f0bdd3a05c0a62ae0 Mon Sep 17 00:00:00 2001 From: Thomas Schmelzer Date: Sun, 25 May 2025 11:50:58 +0400 Subject: [PATCH 3/8] Update Makefile Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 8be917a5..0db83de4 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,10 @@ # Create a Python virtual environment using uv (faster alternative to venv) venv: - @curl -LsSf https://astral.sh/uv/install.sh | sh # Install uv if not already installed + @if ! command -v uv >/dev/null 2>&1; then \ # Check if uv is installed + echo "uv not found. Installing..."; \ + curl -LsSf https://astral.sh/uv/install.sh | sh; \ + fi @uv venv # Create a virtual environment in the current directory # Mark 'install' as a phony target (not associated with a file) From f457b62a05a422288465ef2084b0c82a05c96de4 Mon Sep 17 00:00:00 2001 From: Thomas Schmelzer Date: Sun, 25 May 2025 11:54:28 +0400 Subject: [PATCH 4/8] Move Makefile to uv and simplified README --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 0db83de4..59fc2c42 100644 --- a/Makefile +++ b/Makefile @@ -5,8 +5,8 @@ .DEFAULT_GOAL := help # Create a Python virtual environment using uv (faster alternative to venv) -venv: - @if ! command -v uv >/dev/null 2>&1; then \ # Check if uv is installed +.PHONY: venv + @if ! command -v uv >/dev/null 2>&1; then \ echo "uv not found. Installing..."; \ curl -LsSf https://astral.sh/uv/install.sh | sh; \ fi From 0f292f1fd808acbcf8a28fa64fb6adeee3f4a77e Mon Sep 17 00:00:00 2001 From: Thomas Schmelzer Date: Sun, 25 May 2025 11:57:43 +0400 Subject: [PATCH 5/8] Move Makefile to uv and simplified README --- Makefile | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 59fc2c42..ccebbb6f 100644 --- a/Makefile +++ b/Makefile @@ -6,10 +6,7 @@ # Create a Python virtual environment using uv (faster alternative to venv) .PHONY: venv - @if ! command -v uv >/dev/null 2>&1; then \ - echo "uv not found. Installing..."; \ - curl -LsSf https://astral.sh/uv/install.sh | sh; \ - fi + curl -LsSf https://astral.sh/uv/install.sh | sh; @uv venv # Create a virtual environment in the current directory # Mark 'install' as a phony target (not associated with a file) From 6c1b4d056803d27be0c7fbc2de310a277a3f89e1 Mon Sep 17 00:00:00 2001 From: Thomas Schmelzer Date: Sun, 25 May 2025 11:58:57 +0400 Subject: [PATCH 6/8] Move Makefile to uv and simplified README --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index ccebbb6f..be7b0481 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,7 @@ # Create a Python virtual environment using uv (faster alternative to venv) .PHONY: venv +venv: curl -LsSf https://astral.sh/uv/install.sh | sh; @uv venv # Create a virtual environment in the current directory From 663d857da2bc271ec835cd15398dcdcbd2b5416d Mon Sep 17 00:00:00 2001 From: Thomas Schmelzer Date: Sun, 25 May 2025 12:12:43 +0400 Subject: [PATCH 7/8] introduce "make test" --- Makefile | 4 ++++ test.py | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index be7b0481..83507fb4 100644 --- a/Makefile +++ b/Makefile @@ -47,3 +47,7 @@ help: ## Display this help screen jupyter: install ## Start jupyterlab @uv pip install jupyterlab # Install JupyterLab @uv run jupyter lab # Start JupyterLab server + +.PHONY: test +test: install ## Run the tests + @uv run python -m test diff --git a/test.py b/test.py index 44eedcb5..16a3f2f6 100644 --- a/test.py +++ b/test.py @@ -2,9 +2,12 @@ import cvxpy as cp import numpy as np +print("Starting optimization problem...") + # Problem data. m = 30 n = 20 +print(f"Problem dimensions: m={m}, n={n}") np.random.seed(1) A = np.random.randn(m, n) b = np.random.randn(m) @@ -16,9 +19,19 @@ prob = cp.Problem(objective, constraints) # The optimal objective value is returned by `prob.solve()`. +print("Solving the optimization problem...") result = prob.solve() +print(f"Optimal objective value: {result}") +print(f"Problem status: {prob.status}") + # The optimal value for x is stored in `x.value`. +print("\nOptimal value for x:") print(x.value) + # The optimal Lagrange multiplier for a constraint is stored in # `constraint.dual_value`. -print(constraints[0].dual_value) +print("\nDual values for constraints:") +print(f"First constraint (0 <= x): {constraints[0].dual_value}") +print(f"Second constraint (x <= 1): {constraints[1].dual_value}") + +print("\nOptimization completed successfully!") From 346be35bebae2960046ecd81c81ce31717ea090d Mon Sep 17 00:00:00 2001 From: Thomas Schmelzer Date: Sun, 25 May 2025 12:13:31 +0400 Subject: [PATCH 8/8] introduce "make test" --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f7200f10..848797af 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v5.0.0 hooks: - id: end-of-file-fixer - id: trailing-whitespace