Returns the problem data used in the call to the solver. When a problem is solved, CVXPY creates a chain of reductions enclosed in a :class:`~cvxpy.reductions.solvers.solving_chain.SolvingChain`, and compiles it to some low-level representation that is compatible wit
(
self, solver,
gp: bool = False,
enforce_dpp: bool = False,
ignore_dpp: bool = False,
verbose: bool = False,
canon_backend: str | None = None,
solver_opts: dict | None = None,
)
| 701 | cls.REGISTERED_SOLVE_METHODS[name] = func |
| 702 | |
| 703 | def get_problem_data( |
| 704 | self, solver, |
| 705 | gp: bool = False, |
| 706 | enforce_dpp: bool = False, |
| 707 | ignore_dpp: bool = False, |
| 708 | verbose: bool = False, |
| 709 | canon_backend: str | None = None, |
| 710 | solver_opts: dict | None = None, |
| 711 | ): |
| 712 | """Returns the problem data used in the call to the solver. |
| 713 | |
| 714 | When a problem is solved, CVXPY creates a chain of reductions enclosed |
| 715 | in a :class:`~cvxpy.reductions.solvers.solving_chain.SolvingChain`, |
| 716 | and compiles it to some low-level representation that is |
| 717 | compatible with the targeted solver. This method returns that low-level |
| 718 | representation. |
| 719 | |
| 720 | For some solving chains, this low-level representation is a dictionary |
| 721 | that contains exactly those arguments that were supplied to the solver; |
| 722 | however, for other solving chains, the data is an intermediate |
| 723 | representation that is compiled even further by the solver interfaces. |
| 724 | |
| 725 | A solution to the equivalent low-level problem can be obtained via the |
| 726 | data by invoking the `solve_via_data` method of the returned solving |
| 727 | chain, a thin wrapper around the code external to CVXPY that further |
| 728 | processes and solves the problem. Invoke the unpack_results method |
| 729 | to recover a solution to the original problem. |
| 730 | |
| 731 | For example: |
| 732 | |
| 733 | :: |
| 734 | |
| 735 | objective = ... |
| 736 | constraints = ... |
| 737 | problem = cp.Problem(objective, constraints) |
| 738 | data, chain, inverse_data = problem.get_problem_data(cp.SCS) |
| 739 | # calls SCS using `data` |
| 740 | soln = chain.solve_via_data(problem, data) |
| 741 | # unpacks the solution returned by SCS into `problem` |
| 742 | problem.unpack_results(soln, chain, inverse_data) |
| 743 | |
| 744 | Alternatively, the `data` dictionary returned by this method |
| 745 | contains enough information to bypass CVXPY and call the solver |
| 746 | directly. |
| 747 | |
| 748 | For example: |
| 749 | |
| 750 | :: |
| 751 | |
| 752 | problem = cp.Problem(objective, constraints) |
| 753 | data, _, _ = problem.get_problem_data(cp.SCS) |
| 754 | |
| 755 | import scs |
| 756 | probdata = { |
| 757 | 'A': data['A'], |
| 758 | 'b': data['b'], |
| 759 | 'c': data['c'], |
| 760 | } |