opengen.config package
Submodules
opengen.config.build_config module
- class opengen.config.build_config.BuildConfiguration(build_dir='.')
Bases:
object
Build configuration
Configuration for the code generator
- DEBUG_MODE = 'debug'
Debug mode (fast compilation, worse performance)
- RELEASE_MODE = 'release'
Release mode (great performance, very slow compilation)
- __init__(build_dir='.')
Construct an instance of BuildConfiguration
- Parameters:
build_dir – Target directory, defaults to the current directory
- Returns:
A new instance of BuildConfiguration
- property allocator: RustAllocator
Memory allocator for generated Rust solver
- property build_c_bindings
Whether to build C bindings
- property build_dir
Directory in which the auto-generated optimizer will be stored
- property build_mode
Build mode (
RELEASE_MODE
orDEBUG_MODE
)
- property build_python_bindings
Whether to build Python bindings
- property local_path
Local path of OpEn (if any)
- property open_version
OpEn version used with the auto-generated solver
- Returns:
The method returns either a specific version of OpEn, which will be used with the auto-generated optimizer, or None, in which case, the latest version will be used. You may set your preferred version of OpEn with with_open_version
- property rebuild
Whether to re-build the optimizer from scratch
- property ros_config: RosConfiguration
ROS package configuration
- Returns:
instance of RosConfiguration
- property target_system
Target system
See also:
with_target_system
- property tcp_interface_config
Whether to build a TCP interface
- to_dict()
- with_allocator(allocator: RustAllocator)
Specify a Rust memory allocator.
With this method the user can choose an alternative memory allocator such as jemalloc and rpalloc. For example, if you choose jemalloc as your memory allocator, the autogenerated project will have a Cargo.toml file where optimization-engine is loaded as a dependency with the “jem” feature.
- Parameters:
allocator – allocator; instance of RustAllocator
- Returns:
current instance of BuildConfiguration
- with_build_c_bindings(build_c_bindings=True)
If activated, OpEn will generate C/C++ bindings for the auto-generated solver
- Parameters:
build_c_bindings – whether to build C/C++ bindings for auto-generated solver; default: True, i.e., it suffices to call build_config.with_build_c_bindings() instead of build_config.with_build_c_bindings(True)
- Returns:
current instance of BuildConfiguration
- with_build_directory(build_dir)
Specify the build directory
- Parameters:
build_dir – build directory as string
- Returns:
current instance of BuildConfiguration
- with_build_mode(build_mode)
Set the build mode (debug/release)
- Parameters:
build_mode – Choose either ‘debug’ or ‘release’; the former is fast, but suboptimal, while the latter may take a while to compile, but the generated binary is significantly faster
- Returns:
current instance of BuildConfiguration
- with_build_python_bindings(build_python_bindings=True)
If activated, OpEn will generate python bindings for the auto-generated solver
- Parameters:
build_python_bindings – whether to build python bindings for auto-generated solver; default: True, i.e., it suffices to call build_config.with_build_python_bindings() instead of build_config.with_build_python_bindings(True)
- Returns:
current instance of BuildConfiguration
- with_open_version(open_version='*', local_path=None)
Specify the version of OpEn to link to
- Parameters:
open_version – version of OpEn (in case you want to compile with an older version of OpEn; if not, the latest version of OpEn will be used)
local_path – you can compile using a local version of OpEn. In that case, you need to provide the full absolute path to that local OpEn directory. This option is intended for developers.
- Returns:
current instance of BuildConfiguration
- with_rebuild(do_rebuild)
Whether to clean and rebuild the code generator, if it already exists
- Parameters:
do_rebuild – if set to True, the target code generator will be cleaned and rebuilt from scratch
- Returns:
current instance of BuildConfiguration
- with_ros(ros_config: RosConfiguration)
Activates the generation of a ROS package. The caller must provide an instance of RosConfiguration
- Parameters:
ros_config – Configuation of ROS package
- Returns:
current instance of BuildConfiguration
- with_target_system(target_system)
Specify the target system
- Parameters:
target_system – target system as string (e.g., use “arm-unknown-linux-gnueabihf” or “rpi” for Raspberry Pi). Note that you must have installed the target using rustup if you need to cross-compile.
- Returns:
current instance of BuildConfiguration
- with_tcp_interface_config(tcp_interface_config=<opengen.config.tcp_server_config.TcpServerConfiguration object>)
Specify a TCP server configuration object
- Parameters:
tcp_interface_config – Custom TCP server configuration
- Returns:
current instance of BuildConfiguration
- class opengen.config.build_config.RustAllocator(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)
Bases:
Enum
Memory Allocator for the auto-generated project
- DefaultAllocator = 0
Default allocator
- JemAlloc = 1
Memory allocator: jemalloc
Jemalloc is a generic implementation of malloc that emphasises fragmentation avoidance
- RpAlloc = 2
Memory allocator: rpmalloc
Rpmalloc is a very efficient lock-free thread caching 16-byte aligned memory allocator implemented in C.
opengen.config.meta module
- class opengen.config.meta.OptimizerMeta(optimizer_name='open_optimizer', optimizer_version='0.0.0', optimizer_licence='MIT', optimizer_authors=['John Smith'])
Bases:
object
Metadata of auto-generated parametric optimizer
General metadata for the auto-generated optimizer
The most important piece of information is the name of the optimizer. The optimizer will be stored in a namesake folder inside the target build directory.
- __init__(optimizer_name='open_optimizer', optimizer_version='0.0.0', optimizer_licence='MIT', optimizer_authors=['John Smith'])
Constructor of OptimizerMeta
- Parameters:
optimizer_name – optimizer name (default: open_optimizer)
optimizer_version – version (default: 0.0.0)
optimizer_licence – licence name or URL (default: MIT)
optimizer_authors – list of authors, as list of strings (default: [“John Smith”])
- Returns:
The current instance of OptimizerMeta
- Examples:
>>> import opengen as og >>> meta = og.config.OptimizerMeta() \ >>> .with_version("0.0.2") \ >>> .with_authors(["P. Sopasakis", "E. Fresk"]) \ >>> .with_licence("CC4.0-By") \ >>> .with_optimizer_name("wow_optimizer")
- property alm_mapping_f1_function_name
- property authors
List of authors of optimizer
- property constraint_penalty_function_name
- property cost_function_name
- property grad_function_name
- property initial_penalty_function_name
- property licence
Licence of optimizer :meta private:
- property optimizer_name
Name of optimizer
- property preconditioning_file_name
- to_dict()
- property version
Version of optimizer
- property w_cost_function_name
- property w_f1_function_name
- property w_f2_function_name
- with_authors(optimizer_authors)
Specify list of authors
- Parameters:
optimizer_authors – list of authors
- Returns:
The current instance of OptimizerMeta
- with_licence(optimizer_licence)
Specify licence of auto-generated code
- Parameters:
optimizer_licence – licence name (e.g., MIT) or licence URL
- Returns:
The current instance of OptimizerMeta
- with_optimizer_name(optimizer_name)
Specify the name of the optimizer
- Parameters:
optimizer_name – name of build, may only contain letters, numbers and underscores, and may not start with a number
- Returns:
The current instance of OptimizerMeta
- with_version(optimizer_version)
Specify version
Specify the version of the auto-generated optimizer.
- Parameters:
optimizer_version – version of auto-generated optimizer
- Returns:
The current instance of OptimizerMeta
opengen.config.ros_config module
- class opengen.config.ros_config.RosConfiguration
Bases:
object
Configuration of auto-generated ROS package
- __init__()
Constructor of an instance of RosConfiguration
- property description
Description of ROS package (in
package.xml
)- Returns:
description
- property node_name
Node name (default: ros_node_optimizer)
- Returns:
node name
- property package_name
Package name
- Returns:
package name (default: ‘open_ros’)
- property params_topic_queue_size
Size of “parameter” topic queue
- Returns:
parameter topic name, defaults to 100
- property publisher_subtopic
Name of publisher sub-topic (default: “result”)
- Returns:
publisher sub-topic
- property rate
ROS node rate in Hz
- Returns:
rate, defaults to 10.0
- property result_topic_queue_size
Size of “result” topic
- Returns:
result topic name, defaults to 100
- property subscriber_subtopic
Name of subscriber sub-topic
- Returns:
subscriber sub-topic, defaults to “parameters”
- to_dict()
- with_description(description)
Set the description of the ROS package
- Parameters:
description (string) – description, defaults to “parametric optimization with OpEn”
- Returns:
current object
- with_node_name(node_name)
Set the node name. The node name can contain lowercase and uppercase characters and underscores, but not spaces or other symbols
- Parameters:
node_name (str) – name of node, defaults to “ros_node_optimizer”
- Returns:
current object
- Raises:
ValueError – if node_name is not a legal node name
- with_package_name(pkg_name)
Set the package name, which is the same as the name of the folder that will store the auto-generated ROS node. The node name can contain lowercase and uppercase characters and underscores, but not spaces or other symbols
- Parameters:
pkg_name (str) – package name, defaults to “open_ros”
- Returns:
current object
- Raises:
ValueError – if pkg_name is not a legal package name
- with_publisher_subtopic(publisher_subtopic)
The auto-generated node will output its results to the topic ~/{publisher_subtopic}. The subtopic (publisher_subtopic) can be specified using this method. The default subtopic name is ‘result’. This can be configured after the package is generated, in config/open_params.yaml.
- Parameters:
publisher_subtopic (str) – publisher sub-topic name, defaults to “result”
- Returns:
current object
- with_queue_sizes(result_topic_queue_size=100, parameter_topic_queue_size=100)
Set queue sizes for ROS node
- Parameters:
result_topic_queue_size (int, optional) – queue size of results, defaults to 100
parameter_topic_queue_size (int, optional) – queue size of topic, defaults to 100
- Returns:
current object
- with_rate(rate)
Set the rate of the ROS node
- Parameters:
rate (float) – rate in Hz
- Returns:
current object
- with_subscriber_subtopic(subscriber_subtopic)
The auto-generated node will listen for input at
~/{subscriber_subtopic}
. The subtopic (subscriber_subtopic) can be specified using this method. The default subtopic name is ‘parameters’. This can be configured after the package is generated, in config/open_params.yaml.- Parameters:
subscriber_subtopic (str) – subscriber sub-topic name
- Returns:
- return:
current object
opengen.config.solver_config module
- class opengen.config.solver_config.SolverConfiguration
Bases:
object
Configuration of solver parameters
- __init__()
Construct an instance of solver configuration parameters
- Returns:
- return:
New instance of SolverConfiguration
- property cbfgs_alpha
- property cbfgs_epsilon
- property cbfgs_sy_epsilon
- property constraints_tolerance
Tolerance on the satisfaction of the constraints
- property initial_penalty
Initial penalty
- property initial_tolerance
Initial tolerance of inner solver
- property inner_tolerance_update_factor
“Update factor for inner tolerance
- property lbfgs_memory
LBFGS memory for the inner solver
- property max_duration_micros
Maximum execution time in microseconds
- Returns:
- return:
Integer value
- property max_inner_iterations
Maximum number of iterations for the inner solver
- property max_outer_iterations
Maximum number of iterations for the outer solver
- property penalty_weight_update_factor
Multiplicative factor for the update of the penalty weights
- property preconditioning
Whether an automatic preconditioning should be applied
- Returns:
- return:
True iff preconditioning is active
- property sufficient_decrease_coefficient
Sufficient decrease coefficient
- to_dict()
- property tolerance
Tolerance of inner solver
- with_cbfgs_parameters(alpha, epsilon, sy_epsilon)
Specify the CBFGS parameters alpha and epsilon
- Parameters:
alpha – CBFGS parameter alpha
epsilon – CBFGS parameter epsilon
sy_epsilon – Tolerance on the s-y inner product
- Returns:
the current object
- with_delta_tolerance(constraints_tolerance)
Tolerance on constraint violation
- Parameters:
constraints_tolerance – tolerance delta (related to constraint violation)
- Returns:
the current object
- with_initial_penalty(initial_penalty)
Initial penalty
If preconditioning is activated, then the initial penalty is computed internally following the recommendations of the book of Brigin and Martinez (Chapter 12). If you enable the preconditioning and you use this method, then you will be overriding the value of the initial penalty.
If preconditioning is not enabled, you can set the initial penalty using this method; if you don’t do so, the solver will use the default value (which is 1.0).
- Parameters:
initial_penalty – initial value of penalty
- Returns:
The current object
- with_initial_tolerance(initial_tolerance)
Specify the initial tolerance
- Parameters:
initial_tolerance – initial tolerance
- Returns:
The current object
- with_inner_tolerance_update_factor(inner_tol_update_factor)
Tolerance update factor
The tolerance is initially given by
with_initial_tolerance()
and it is then updated by this update factor until the target tolerance which is given bywith_tolerance()
- with_lbfgs_memory(lbfgs_memory)
Specify L-BFGS memory
- Parameters:
lbfgs_memory – LBFGS memory
- Raises:
It is required that the L-BFGS memory is larger than or equal to 2, otherwise an Exception is raised
- Returns:
Returns the current instance of SolverConfiguration
- with_max_duration_micros(max_duration_micros)
Specify the maximum duration in microseconds (must be an integer)
The solver will interrupt the computation after this time limit and will return the current iterate.
- Parameters:
max_duration_micros – maximum execution duration in microseconds (integer)
- Raises:
Exception: if max_duration_micros is less than 1
- Returns:
The current object
- with_max_inner_iterations(max_iters)
Maximum number of inner iterations
- Parameters:
max_iters – maximum number of iterations
- Returns:
The current object
- with_max_outer_iterations(max_outer_iterations)
Maximum number of outer iterations
- Parameters:
max_outer_iterations – maximum number of outer iterations
- Returns:
the current object
- with_penalty_weight_update_factor(penalty_weight_update_factor)
Penalty update factor
At every outer iteration of the penalty method, the weights are multiplied by this factor.
- Parameters:
penalty_weight_update_factor – penalty weight update factor
- Raises:
Exception, if the update factor is less than 1.0
- Returns:
the current object
- with_preconditioning(do_preconditioning=True)
Whether to apply preconditioning using the approach of [1]
Note that this overrides the computation of the initial penalty
Note also that unless this method is called, no preconditioning is applied (this may change in a future release; we may make enable preconditioning by default)
[1] E.G. Birgin and J.M. Martinez, Practical Augmented Lagrangian Methods for Constrained Optimization, SIAM, 2014
- Parameters:
do_preconditioning – whether to precondition
- Returns:
the current object
- with_sufficient_decrease_coefficient(sufficient_decrease_coefficient)
Specify the sufficient decrease coefficient of the algorithm
- param sufficient_decrease_coefficient:
sufficient decrease coefficient
- returns:
The current object
- with_tolerance(tolerance)
Specify tolerance
- Parameters:
tolerance – tolerance
- Raises:
Exception: if tolerance <= 0
- Returns:
The current object
opengen.config.tcp_server_config module
- class opengen.config.tcp_server_config.TcpServerConfiguration(bind_ip='127.0.0.1', bind_port=8333)
Bases:
object
TCP server configuration
- __init__(bind_ip='127.0.0.1', bind_port=8333)
Configuration of the TCP server
- Parameters:
bind_ip – IP address of generated TCP server. The default value is “127.0.0.1” (localhost). Use “0.0.0.0” for the generated TCP server to bind on all IPs.
bind_port – Port on which the generated TCP server will bind. The default is 8333. Make sure you use an available port and avoid using privileged ports (i.e., 1 to 1024), well-known ports that are potentially used by other services and you should also avoid ephemeral ports (32768 to 65535 on Linux, 1025 to 5000 on Windows)
- Returns:
new instance of TcpServerConfiguration, which can then be provided to an instance of OpEnOptimizerBuilder via enable_tcp_interface
- property bind_ip
IP at which the TCP server should bind, as a string
- Returns:
TCP server IP
- property bind_port
Port at which the TCP server should bind, as int
- Returns:
TCP server port
- to_dict()