From bc45315cd77d3bd51cbd3c939dcb6d22ff76550f Mon Sep 17 00:00:00 2001 From: Thomas Schmelzer Date: Tue, 31 Dec 2024 09:35:21 +0400 Subject: [PATCH] fmt --- .pre-commit-config.yaml | 2 +- cvx/markowitz/builder.py | 2 +- cvx/markowitz/types.py | 2 +- experiments/playground.ipynb | 56 +++++------------------------------- 4 files changed, 10 insertions(+), 52 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f1425398..12757235 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,7 +24,7 @@ repos: - id: pyupgrade - repo: 'https://github.com/pre-commit/mirrors-mypy' - rev: v1.4.1 + rev: v1.14.0 hooks: - id: mypy files: cvx diff --git a/cvx/markowitz/builder.py b/cvx/markowitz/builder.py index 76105b12..fe9c2082 100644 --- a/cvx/markowitz/builder.py +++ b/cvx/markowitz/builder.py @@ -80,7 +80,7 @@ def is_dpp(self) -> bool: return bool(self.problem.is_dpp()) @property - def data(self) -> Generator[tuple[tuple[str, str], Matrix], None, None]: + def data(self) -> Generator[tuple[tuple[str, str], Matrix]]: for name, model in self.model.items(): for key, value in model.data.items(): yield (name, key), value diff --git a/cvx/markowitz/types.py b/cvx/markowitz/types.py index a0b875ab..c4763b04 100644 --- a/cvx/markowitz/types.py +++ b/cvx/markowitz/types.py @@ -19,7 +19,7 @@ import numpy.typing as npt from typing_extensions import TypeAlias -File = Union[str, bytes, PathLike] +File = Union[str, bytes, PathLike[str]] Parameter = Dict[str, cp.Parameter] Variables = Dict[str, cp.Variable] Expressions = Dict[str, cp.Expression] diff --git a/experiments/playground.ipynb b/experiments/playground.ipynb index 4c4cdba3..c7b5e0e7 100644 --- a/experiments/playground.ipynb +++ b/experiments/playground.ipynb @@ -48,38 +48,16 @@ "evalue": "Invalid dimensions (2,) for Parameter value.", "output_type": "error", "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[25], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43ma\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mvalue\u001b[49m \u001b[38;5;241m=\u001b[39m np\u001b[38;5;241m.\u001b[39mzeros(\u001b[38;5;241m2\u001b[39m)\n", - "File \u001b[0;32m~/Documents/Stanford/Research/My papers/markowitz/code/cvxmarkowitz/.venv/lib/python3.9/site-packages/cvxpy/expressions/constants/parameter.py:87\u001b[0m, in \u001b[0;36mParameter.value\u001b[0;34m(self, val)\u001b[0m\n\u001b[1;32m 85\u001b[0m \u001b[39m@value\u001b[39m\u001b[39m.\u001b[39msetter\n\u001b[1;32m 86\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mvalue\u001b[39m(\u001b[39mself\u001b[39m, val):\n\u001b[0;32m---> 87\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_value \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_validate_value(val)\n", - "File \u001b[0;32m~/Documents/Stanford/Research/My papers/markowitz/code/cvxmarkowitz/.venv/lib/python3.9/site-packages/cvxpy/expressions/leaf.py:394\u001b[0m, in \u001b[0;36mLeaf._validate_value\u001b[0;34m(self, val)\u001b[0m\n\u001b[1;32m 392\u001b[0m val \u001b[39m=\u001b[39m intf\u001b[39m.\u001b[39mconvert(val)\n\u001b[1;32m 393\u001b[0m \u001b[39mif\u001b[39;00m intf\u001b[39m.\u001b[39mshape(val) \u001b[39m!=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mshape:\n\u001b[0;32m--> 394\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mValueError\u001b[39;00m(\n\u001b[1;32m 395\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mInvalid dimensions \u001b[39m\u001b[39m%s\u001b[39;00m\u001b[39m for \u001b[39m\u001b[39m%s\u001b[39;00m\u001b[39m value.\u001b[39m\u001b[39m\"\u001b[39m \u001b[39m%\u001b[39m\n\u001b[1;32m 396\u001b[0m (intf\u001b[39m.\u001b[39mshape(val), \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m\u001b[39m__class__\u001b[39m\u001b[39m.\u001b[39m\u001b[39m__name__\u001b[39m)\n\u001b[1;32m 397\u001b[0m )\n\u001b[1;32m 398\u001b[0m projection \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mproject(val)\n\u001b[1;32m 399\u001b[0m \u001b[39m# ^ might be a numpy array, or sparse scipy matrix.\u001b[39;00m\n", - "\u001b[0;31mValueError\u001b[0m: Invalid dimensions (2,) for Parameter value." + "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m", + "\u001B[0;31mValueError\u001B[0m Traceback (most recent call last)", + "Cell \u001B[0;32mIn[25], line 1\u001B[0m\n\u001B[0;32m----> 1\u001B[0m \u001B[43ma\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mvalue\u001B[49m \u001B[38;5;241m=\u001B[39m np\u001B[38;5;241m.\u001B[39mzeros(\u001B[38;5;241m2\u001B[39m)\n", + "File \u001B[0;32m~/Documents/Stanford/Research/My papers/markowitz/code/cvxmarkowitz/.venv/lib/python3.9/site-packages/cvxpy/expressions/constants/parameter.py:87\u001B[0m, in \u001B[0;36mParameter.value\u001B[0;34m(self, val)\u001B[0m\n\u001B[1;32m 85\u001B[0m \u001B[39m@value\u001B[39m\u001B[39m.\u001B[39msetter\n\u001B[1;32m 86\u001B[0m \u001B[39mdef\u001B[39;00m \u001B[39mvalue\u001B[39m(\u001B[39mself\u001B[39m, val):\n\u001B[0;32m---> 87\u001B[0m \u001B[39mself\u001B[39m\u001B[39m.\u001B[39m_value \u001B[39m=\u001B[39m \u001B[39mself\u001B[39;49m\u001B[39m.\u001B[39;49m_validate_value(val)\n", + "File \u001B[0;32m~/Documents/Stanford/Research/My papers/markowitz/code/cvxmarkowitz/.venv/lib/python3.9/site-packages/cvxpy/expressions/leaf.py:394\u001B[0m, in \u001B[0;36mLeaf._validate_value\u001B[0;34m(self, val)\u001B[0m\n\u001B[1;32m 392\u001B[0m val \u001B[39m=\u001B[39m intf\u001B[39m.\u001B[39mconvert(val)\n\u001B[1;32m 393\u001B[0m \u001B[39mif\u001B[39;00m intf\u001B[39m.\u001B[39mshape(val) \u001B[39m!=\u001B[39m \u001B[39mself\u001B[39m\u001B[39m.\u001B[39mshape:\n\u001B[0;32m--> 394\u001B[0m \u001B[39mraise\u001B[39;00m \u001B[39mValueError\u001B[39;00m(\n\u001B[1;32m 395\u001B[0m \u001B[39m\"\u001B[39m\u001B[39mInvalid dimensions \u001B[39m\u001B[39m%s\u001B[39;00m\u001B[39m for \u001B[39m\u001B[39m%s\u001B[39;00m\u001B[39m value.\u001B[39m\u001B[39m\"\u001B[39m \u001B[39m%\u001B[39m\n\u001B[1;32m 396\u001B[0m (intf\u001B[39m.\u001B[39mshape(val), \u001B[39mself\u001B[39m\u001B[39m.\u001B[39m\u001B[39m__class__\u001B[39m\u001B[39m.\u001B[39m\u001B[39m__name__\u001B[39m)\n\u001B[1;32m 397\u001B[0m )\n\u001B[1;32m 398\u001B[0m projection \u001B[39m=\u001B[39m \u001B[39mself\u001B[39m\u001B[39m.\u001B[39mproject(val)\n\u001B[1;32m 399\u001B[0m \u001B[39m# ^ might be a numpy array, or sparse scipy matrix.\u001B[39;00m\n", + "\u001B[0;31mValueError\u001B[0m: Invalid dimensions (2,) for Parameter value." ] } ], - "source": [ - "a.value = np.zeros(2)" - ] - }, - { - "cell_type": "code", - "execution_count": 20, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 20, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "argument[1].is_incr(0)" - ] + "source": "a.value = np.zeros(1)" }, { "cell_type": "code", @@ -275,26 +253,6 @@ "np.array([[1.0, 0.5], [0.5, 2.0]])" ] }, - { - "cell_type": "code", - "execution_count": 16, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 16, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "obj.is_dcp()" - ] - }, { "cell_type": "code", "execution_count": 2,