Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
tschm committed Dec 31, 2024
1 parent 05fbfc8 commit bc45315
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cvx/markowitz/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cvx/markowitz/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
56 changes: 7 additions & 49 deletions experiments/playground.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit bc45315

Please sign in to comment.