<jupyter_start><jupyter_text>Parametric nonconvex optimizationConsider the following minimization problem ([reference](https://alphaville.github.io/optimization-engine/docs/example_rosenbrock_py))$$\begin{align}    \operatorname*{Minimize}_{\|u\|\leq r}& \sum_{i=1}^{n_u - 1} b (u_{i+1} - u_{i}^2)^2 + (a-u_i)^2    \\    \text{subject to: }& 1.5 u_1 - u_2 = 0    \\    &u_3 - u_4 + 0.1 \leq 0    \end{align}$$The parameter vector is $p=(a,b)$. Let us generate a parametric optimiser with $n_u=5$.<jupyter_code>import opengen as og
import casadi.casadi as cs

# Build parametric optimizer
# ------------------------------------
u = cs.SX.sym("u", 5)  # decision variables
p = cs.SX.sym("p", 2)  # parameters, p = (a, b)

# cost function:
phi = og.functions.rosenbrock(u, p)

# constraints:
c = cs.vertcat(1.5 * u[0] - u[1],
               cs.fmax(0.0, u[2] - u[3] + 0.1))

# simple bounds on decision variables:
bounds = og.constraints.Ball2(None, 1.5)

# problem formulation
problem = og.builder.Problem(u, p, phi) \
    .with_penalty_constraints(c)        \
    .with_constraints(bounds)<jupyter_output><empty_output><jupyter_text>Generate optimizerThe following code will generate your parametric optimizer. The auto-generated files will be stored in `optimizers/rosenbrock`.<jupyter_code># Configure and build
# (This might take a while)
# ---------------------------------
build_config = og.config.BuildConfiguration()      \
    .with_build_directory("optimizers")            \
    .with_build_mode(og.config.BuildConfiguration.DEBUG_MODE)  \
    .with_tcp_interface_config()
meta = og.config.OptimizerMeta()                   \
    .with_optimizer_name("rosenbrock")
solver_config = og.config.SolverConfiguration()    \
    .with_tolerance(1e-5)                          \
    .with_delta_tolerance(1e-4)                    \
    .with_initial_penalty(1e3)                     \
    .with_penalty_weight_update_factor(5)
builder = og.builder.OpEnOptimizerBuilder(problem, meta,
                                          build_config, solver_config)
builder.build()<jupyter_output><empty_output><jupyter_text>Use the auto-generated optimizerYou may now use the auto-generated optimizer in Python.Tip: First you need to start the server. Then, you can call it as many times as you like. When you're done, you can kill it.<jupyter_code># Start the optimisation server
# ----------------------------------
mng = og.tcp.OptimizerTcpManager('optimizers/rosenbrock')
mng.start()
# Call the server
# ----------------------------------
response = mng.call([1.0, 50.0])
if response.is_ok():
    # Solver returned a solution
    solution_data = response.get()
    u_star = solution_data.solution
    exit_status = solution_data.exit_status
    solver_time = solution_data.solve_time_ms
    print("u_star = ", u_star)
    print("solved in = ", solver_time, "ms")
    
# Kill the server
# ----------------------------------
mng.kill()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17483936422049373, 'fraction_numerical': 0.014879945891105851, 'mean_word_length': 2.625, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '252400', 'license': 'Apache-2.0', 'n_tokens_mistral': 989, 'n_tokens_neox': 947, 'n_words': 209, 'path': 'docker/example.ipynb', 'repo_name': 'kpwelsh/optimization-engine-wasm', 'size': '2957'}