Skip to content

Commit

Permalink
Merge pull request #317 from alphaville/hotfix/316
Browse files Browse the repository at this point in the history
build() returns dictionary with details
  • Loading branch information
alphaville authored Feb 14, 2023
2 parents d833669 + a11de80 commit a83981f
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 5 deletions.
12 changes: 7 additions & 5 deletions open-codegen/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
Note: This is the Changelog file of `opengen` - the Python interface of OpEn


<!--
UNRELEASED!
0.7.1 has not been released yet
-->
## [0.7.1] - Unreleased

## [0.7.1] - 2022-02-14

### Added

* Method `.build` returns a dictionary with information that can assist debugging


### Changed

Expand Down
16 changes: 16 additions & 0 deletions open-codegen/opengen/builder/optimizer_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -792,12 +792,26 @@ def __generate_c_bindings_makefile(self):
with open(cbind_makefile_target_path, "w") as fh:
fh.write(cbind_makefile_output_template)

def __info(self):
info = {
"meta": self.__meta.to_dict(),
"problem": self.__problem.to_dict(),
"build_config": self.__build_config.to_dict(),
"solver_config": self.__solver_config.to_dict(),
"paths": {
"target": self.__target_dir(),
}
}
return info

def build(self):
"""Generate code and build project
:raises Exception: if the build process fails
:raises Exception: if there some parameters have wrong, inadmissible or incompatible values
:returns: Dictionary with information that can be used for debugging
"""
self.__initialize() # initialize default value (if not provided)
self.__check_user_provided_parameters() # check the provided parameters
Expand Down Expand Up @@ -846,3 +860,5 @@ def build(self):
self.__build_config,
self.__solver_config)
ros_builder.build()

return self.__info()
8 changes: 8 additions & 0 deletions open-codegen/opengen/builder/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,11 @@ def w2(self):
This is a CasADi symbol (SX or MX)
"""
return self.__w2

def to_dict(self):
return {
"dim_decision_variables": self.dim_decision_variables(),
"dim_parameters": self.dim_parameters(),
"dim_constraints_penalty": self.dim_constraints_penalty(),
"dim_constraints_aug_lagrangian": self.dim_constraints_aug_lagrangian()
}
16 changes: 16 additions & 0 deletions open-codegen/opengen/config/build_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,19 @@ def with_allocator(self, allocator: RustAllocator):
"""
self.__allocator = allocator
return self

def to_dict(self):
build_dict = {
"target_system": self.__target_system,
"build_mode": self.__build_mode,
"rebuild": self.__rebuild,
"build_directory": self.__build_dir,
"open_version": self.__open_version,
"build_c_bindings": self.__build_c_bindings,
"build_python_bindings": self.__build_python_bindings,
}
if self.__tcp_interface_config is not None:
build_dict["tcp_interface_config"] = self.__tcp_interface_config.to_dict()
if self.__ros_config is not None:
build_dict["ros_config"] = self.__ros_config.to_dict()
return build_dict
8 changes: 8 additions & 0 deletions open-codegen/opengen/config/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,11 @@ def licence(self):
:meta private:
"""
return self.__optimizer_licence

def to_dict(self):
return {
"name": self.__optimizer_name,
"version": self.__optimizer_version,
"author": self.__optimizer_author_list,
"licence": self.__optimizer_licence
}
12 changes: 12 additions & 0 deletions open-codegen/opengen/config/ros_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,15 @@ def with_subscriber_subtopic(self, subscriber_subtopic):
"""
self.__subscriber_subtopic = subscriber_subtopic
return self

def to_dict(self):
return {
"package_name": self.__package_name,
"node_name": self.__node_name,
"description": self.__description,
"rate": self.__rate,
"result_topic_queue_size": self.__result_topic_queue_size,
"params_topic_queue_size": self.__params_topic_queue_size,
"publisher_subtopic": self.__publisher_subtopic,
"subscriber_subtopic": self.__subscriber_subtopic
}
19 changes: 19 additions & 0 deletions open-codegen/opengen/config/solver_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,22 @@ def with_preconditioning(self, do_preconditioning=True):
"""
self.__do_preconditioning = do_preconditioning
return self

def to_dict(self):
return {
"tolerance": self.__tolerance,
"initial_tolerance": self.__initial_tolerance,
"lbfgs_memory": self.__lbfgs_memory,
"max_inner_iterations": self.__max_inner_iterations,
"max_outer_iterations": self.__max_outer_iterations,
"constraints_tolerance": self.__constraints_tolerance,
"initial_penalty": self.__initial_penalty,
"penalty_weight_update_factor": self.__penalty_weight_update_factor,
"max_duration_micros": self.__max_duration_micros,
"inner_tolerance_update_factor": self.__inner_tolerance_update_factor,
"sufficient_decrease_coefficient": self.__sufficient_decrease_coefficient,
"cbfgs_alpha": self.__cbfgs_alpha,
"cbfgs_epsilon": self.__cbfgs_epsilon,
"cbfgs_sy_epsilon": self.__cbfgs_sy_epsilon,
"do_preconditioning": self.__do_preconditioning
}
6 changes: 6 additions & 0 deletions open-codegen/opengen/config/tcp_server_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,9 @@ def bind_port(self):
:return: TCP server port
"""
return self.__bind_port

def to_dict(self):
return {
"ip": self.__bind_ip,
"port": self.__bind_port
}

0 comments on commit a83981f

Please sign in to comment.