Coverage for src/cvxmarkowitz/cvxerror.py: 100%
4 statements
« prev ^ index » next coverage.py v7.16.1, created at 2026-09-15 05:21 +0000
« prev ^ index » next coverage.py v7.16.1, created at 2026-09-15 05:21 +0000
1# Copyright 2023 Stanford University Convex Optimization Group
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14"""Custom exceptions used by the Markowitz package."""
17class CvxError(Exception):
18 """Base error for the package.
20 Every error raised by cvxmarkowitz derives from this, so
21 ``except CvxError`` continues to catch all of them. Prefer catching one
22 of the subclasses below when the handling differs by failure mode.
23 """
26class CvxDataError(CvxError):
27 """Input data is missing, or its shape disagrees with the model.
29 Raised when required keyword data is absent, or when arrays that must
30 agree in length or shape do not. Recoverable by supplying corrected
31 input and retrying.
32 """
35class CvxSolverError(CvxError):
36 """The solver returned a non-optimal status.
38 Raised when a problem is infeasible, unbounded, or otherwise did not
39 solve to optimality. Retrying with the same input will not help;
40 another solver or a relaxed formulation might.
41 """
44class CvxBuildError(CvxError):
45 """The assembled problem does not satisfy the package's construction rules.
47 Raised by :meth:`Builder.build` when the problem it assembled is not
48 :abbr:`DPP (disciplined parametrized programming)`-compliant. The whole
49 point of building a parametrized problem here is that cvxpy caches the
50 canonicalization and reuses it on later solves, and only DPP-compliant
51 problems get that treatment -- so a non-DPP problem is a formulation bug,
52 not a data problem. Retrying will not help; the objective or the
53 constraints have to change.
54 """