Add ignore_nan option to solver and implement validation skipping for…#1
Add ignore_nan option to solver and implement validation skipping for…#1MGPowerlytics wants to merge 1 commit intomasterfrom
Conversation
| try: | ||
| yield | ||
| finally: | ||
| _ignore_nan_scope_active = prev_state |
There was a problem hiding this comment.
The dpp_scope context manager does not use a try/finally block to restore the previous state, but ignore_nan_scope does. For consistency and robustness, both should use the same pattern. The try/finally pattern in ignore_nan_scope is better as it ensures the state is restored even if an exception occurs.
| if verbose: | ||
| print(_NUM_SOLVER_STR) | ||
| s.LOGGER.info( | ||
| 'Invoking solver %s to obtain a solution.', | ||
| solving_chain.reductions[-1].name()) | ||
| start = time.time() | ||
| solver_verbose = kwargs.pop('solver_verbose', verbose) | ||
| if solver_verbose and (not verbose): | ||
| print(_NUM_SOLVER_STR) | ||
| if verbose and bibtex: | ||
| print(_CITATION_STR) | ||
|
|
||
| # Cite CVXPY papers. | ||
| print(CITATION_DICT["CVXPY"]) | ||
|
|
||
| # Cite problem grammar. | ||
| if self.is_dcp(): | ||
| print(CITATION_DICT["DCP"]) | ||
| if gp: | ||
| print(CITATION_DICT["DGP"]) | ||
|
|
||
| # Cite solver. | ||
| print(solving_chain.reductions[-1].cite(data)) | ||
| solution = solving_chain.solve_via_data( | ||
| self, data, warm_start, solver_verbose, kwargs) |
There was a problem hiding this comment.
The solve_via_data call should be outside the ignore_nan_scope context manager. Currently, the scope exits at line 1248, which means the actual solving happens inside the scope. However, the validation that the scope is meant to bypass only happens during get_problem_data (specifically in apply_parameters). Keeping the solver call inside the scope unnecessarily extends its lifetime and could mask validation issues in other parts of the solving process.
| if verbose: | |
| print(_NUM_SOLVER_STR) | |
| s.LOGGER.info( | |
| 'Invoking solver %s to obtain a solution.', | |
| solving_chain.reductions[-1].name()) | |
| start = time.time() | |
| solver_verbose = kwargs.pop('solver_verbose', verbose) | |
| if solver_verbose and (not verbose): | |
| print(_NUM_SOLVER_STR) | |
| if verbose and bibtex: | |
| print(_CITATION_STR) | |
| # Cite CVXPY papers. | |
| print(CITATION_DICT["CVXPY"]) | |
| # Cite problem grammar. | |
| if self.is_dcp(): | |
| print(CITATION_DICT["DCP"]) | |
| if gp: | |
| print(CITATION_DICT["DGP"]) | |
| # Cite solver. | |
| print(solving_chain.reductions[-1].cite(data)) | |
| solution = solving_chain.solve_via_data( | |
| self, data, warm_start, solver_verbose, kwargs) | |
| if verbose: | |
| print(_NUM_SOLVER_STR) | |
| s.LOGGER.info( | |
| 'Invoking solver %s to obtain a solution.', | |
| solving_chain.reductions[-1].name()) | |
| start = time.time() | |
| solver_verbose = kwargs.pop('solver_verbose', verbose) | |
| if solver_verbose and (not verbose): | |
| print(_NUM_SOLVER_STR) | |
| if verbose and bibtex: | |
| print(_CITATION_STR) | |
| # Cite CVXPY papers. | |
| print(CITATION_DICT["CVXPY"]) | |
| # Cite problem grammar. | |
| if self.is_dcp(): | |
| print(CITATION_DICT["DCP"]) | |
| if gp: | |
| print(CITATION_DICT["DGP"]) | |
| # Cite solver. | |
| print(solving_chain.reductions[-1].cite(data)) | |
| solution = solving_chain.solve_via_data( | |
| self, data, warm_start, solver_verbose, kwargs) |
| # Set ignore_nan flag on param_prog if specified in solver_opts | ||
| if solver_opts and solver_opts.get('ignore_nan', False): | ||
| self._cache.param_prog.ignore_nan = True |
There was a problem hiding this comment.
There's a redundancy in how ignore_nan is handled. The code sets self._cache.param_prog.ignore_nan both in lines 800-803 and 839-841. Additionally, the ignore_nan_scope context manager is being used alongside these flag settings, creating two overlapping mechanisms. This dual approach is confusing - either use the context manager consistently or use the flag consistently, but mixing both adds unnecessary complexity.
| # Set ignore_nan flag on param_prog if specified in solver_opts | |
| if solver_opts and solver_opts.get('ignore_nan', False): | |
| self._cache.param_prog.ignore_nan = True |
… NaN/Inf
Description
Please include a short summary of the change.
Issue link (if applicable):
Type of change
Contribution checklist