diff --git a/open-codegen/CHANGELOG.md b/open-codegen/CHANGELOG.md index 5f960b32..31aecf7e 100644 --- a/open-codegen/CHANGELOG.md +++ b/open-codegen/CHANGELOG.md @@ -8,6 +8,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/). Note: This is the Changelog file of `opengen` - the Python interface of OpEn +## [0.9.2] - 2024-11-05 + +### Fixed + +- In CasADi-generated C files some functions are made static to avoid clashes when creating multiple solvers ## [0.9.1] - 2024-10-14 @@ -214,6 +219,7 @@ Note: This is the Changelog file of `opengen` - the Python interface of OpEn * Fixed `lbfgs` typo +[0.9.2]: https://github.com/alphaville/optimization-engine/compare/opengen-0.9.1...opengen-0.9.2 [0.9.1]: https://github.com/alphaville/optimization-engine/compare/opengen-0.9.0...opengen-0.9.1 [0.9.0]: https://github.com/alphaville/optimization-engine/compare/opengen-0.8.1...opengen-0.9.0 [0.8.1]: https://github.com/alphaville/optimization-engine/compare/v0.9.0...opengen-0.8.1 diff --git a/open-codegen/VERSION b/open-codegen/VERSION index f514a2f0..f76f9131 100644 --- a/open-codegen/VERSION +++ b/open-codegen/VERSION @@ -1 +1 @@ -0.9.1 \ No newline at end of file +0.9.2 \ No newline at end of file diff --git a/open-codegen/opengen/builder/optimizer_builder.py b/open-codegen/opengen/builder/optimizer_builder.py index 55c96f64..8a43c30d 100644 --- a/open-codegen/opengen/builder/optimizer_builder.py +++ b/open-codegen/opengen/builder/optimizer_builder.py @@ -1,8 +1,6 @@ import subprocess import shutil -import datetime import yaml -import warnings import opengen.config as og_cfg import opengen.definitions as og_dfn @@ -809,6 +807,38 @@ def __info(self): } return info + def __casadi_make_static(self): + """Makes some casadi functions static to avoid clashes (see #362) + """ + self.__logger.info("Making CasADi functions static") + + def replace_in_casadi_file(casadi_source_fname, function_names): + # Read casadi_source_fname, line by line, replace, write to destination + # Open the source file in read mode + # Replace and write to a different file (with extension .tmp) + with open(casadi_source_fname, 'r') as fin, open(f"{casadi_source_fname}.tmp", 'w') as fout: + for line_in in fin: + for fnc in function_names: + line_in = line_in.replace( + f"casadi_real {fnc}", f"static casadi_real {fnc}") + fout.write(line_in) + # Move the .tmp file to replace the original one + shutil.move(f"{casadi_source_fname}.tmp", f"{casadi_source_fname}") + + # Folder with external CasADi files (auto-generated C code) + icasadi_extern_dir = os.path.join( + self.__icasadi_target_dir(), "extern") # casadi extern folder + # Function to make static + fncs_list = ["casadi_sq", "casadi_fmax", + "casadi_fmin", "casadi_hypot", "casadi_sign", + "casadi_log1p", "casadi_expm1"] + # make static + for casadi_fname in [_AUTOGEN_COST_FNAME, _AUTOGEN_ALM_MAPPING_F1_FNAME, + _AUTOGEN_GRAD_FNAME, _AUTOGEN_PNLT_CONSTRAINTS_FNAME, + _AUTOGEN_PRECONDITIONING_FNAME]: + replace_in_casadi_file(os.path.join( + icasadi_extern_dir, casadi_fname), fncs_list) + def build(self): """Generate code and build project @@ -837,6 +867,7 @@ def build(self): self.__generate_main_project_code() self.__generate_build_rs() # generate build.rs file self.__generate_yaml_data_file() # create YAML file with metadata + self.__casadi_make_static() # make casadi functions static if not self.__generate_not_build: self.__logger.info("Building optimizer")