cvxgrp/cvxpygen

Default solver is not setup in configuration

GNCGenie opened this issue · 2 comments

Trying to generate C code fails when it tries to write the README.html file.
the variable configuration.solve_name has not been initialised and is None, resulting in a error when it tries to replace the HTML string "$CPGSOLVERNAME" with configuration.solver_name.

Pasted below is the trace:

dist.fetch_build_eggs(dist.setup_requires)
[done]
Copying code-generated Python solver to current directory... 	[done]
Traceback (most recent call last):
  File "/home/Inspecity/Codes/RPOS_control/src/MPC_CloseRange.py", line 70, in <module>
    cpg.generate_code(problem, code_dir="MPC_CloseRange")
  File "/home/Inspecity/Codes/Vision/.venv/lib/python3.11/site-packages/cvxpygen/cpg.py", line 85, in generate_code
    write_c_code(problem, configuration, variable_info, dual_variable_info,
  File "/home/Inspecity/Codes/Vision/.venv/lib/python3.11/site-packages/cvxpygen/cpg.py", line 390, in write_c_code
    read_write_file(os.path.join(configuration.code_dir, 'README.html'),
  File "/home/Inspecity/Codes/Vision/.venv/lib/python3.11/site-packages/cvxpygen/utils.py", line 28, in read_write_file
    data = function(data, *args)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/Inspecity/Codes/Vision/.venv/lib/python3.11/site-packages/cvxpygen/utils.py", line 1379, in replace_html_data
    text = text.replace('$CPGSOLVERNAME', configuration.solver_name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: replace() argument 2 must be str, not None

The problem gets resolved when the generate_code function is specified which solver to use by using the solver keyword.
Example :

cpg.generate_code(problem, code_dir="MPC_Euler", solver='SCS')

Perhaps there should be a fallback solver to default to, rather than throwing an error.

Thanks for pointing this out. This is fixed in the newest release v0.3.3.