### Run cyipopt example Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/install.rst Commands to run a cyipopt example after successful installation. ```bash $ cd test $ python -c "import cyipopt" $ python examplehs071.py ``` -------------------------------- ### Build and Link Commands Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/install.rst Example commands showing the build and linking process for cyipopt.c, including compiler flags and library paths. ```bash $ python setup.py build ... x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-3hk45v/python2.7-2.7.15~rc1=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/local/include/coin # points to Ipopt headers -I/usr/local/include/coin/ThirdParty # points to Ipopt third party headers -I/usr/local/include/python2.7/numpy/core/include # points to NumPy headers -I/usr/include/python2.7 # points to Python 2.7 headers -c src/cyipopt.c -o build/temp.linux-x86_64-2.7/src/cyipopt.o x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-3hk45v/python2.7-2.7.15~rc1=. -fstack-protector-strong -Wformat -Werror=format-security -Wl,-Bsymbolic-functions -Wl,-z,relro -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-3hk45v/python2.7-2.7.15~rc1=. -fstack-protector-strong -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/src/cyipopt.o -L/usr/local/lib -L/lib/../lib -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/5 -L/usr/lib/gcc/x86_64-linux-gnu/5/../../.. -L/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib -L/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu -lipopt -llapack -lblas -lm -ldl -lcoinmumps -lblas -lgfortran -lm -lquadmath # linking to relevant libs -lcoinhsl -llapack -lblas -lgfortran -lm -lquadmath -lcoinmetis # linking to relevant libs -o build/lib.linux-x86_64-2.7/cyipopt.so ... ``` -------------------------------- ### pip install cyipopt[docs,examples,tests] Source: https://github.com/mechmotum/cyipopt/blob/master/CHANGELOG.rst Example of installing cyipopt with pip extras for documentation, examples, and tests. ```bash pip install cyipopt[docs,examples,tests] ``` -------------------------------- ### Build and Install HSL Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/install.rst Build and install HSL after configuration. ```bash (hsl-test) $ make (hsl-test) $ make install ``` -------------------------------- ### Install dependencies on Ubuntu 22.04 using APT Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/install.rst Installs all required dependencies for cyipopt using Ubuntu's APT package manager. ```sh $ apt install build-essential pkg-config python3-pip python3-dev cython3 python3-numpy coinor-libipopt1v5 coinor-libipopt-dev ``` -------------------------------- ### Build Ipopt Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/install.rst Commands to build Ipopt from source. ```bash $ mkdir $IPOPTDIR/build $ cd $IPOPTDIR/build $ ../configure $ make $ make test ``` -------------------------------- ### Compile cyipopt Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/install.rst Command to build cyipopt from source. ```bash $ python setup.py build ``` -------------------------------- ### Install cyipopt from source on Linux and macOS Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/install.rst Builds and installs cyipopt from source after dependencies are met. ```sh $ python -m pip install . ``` -------------------------------- ### Install build dependencies on Windows using Pip Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/install.rst Installs necessary build tools and libraries for cyipopt on Windows using Pip. ```powershell > python -m pip install numpy cython setuptools ``` -------------------------------- ### Install dependencies on Ubuntu 18.04 using APT Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/install.rst Installs dependencies for cyipopt on Ubuntu 18.04 using APT. ```sh $ sudo apt install build-essential pkg-config python-dev cython python-numpy coinor-libipopt1v5 coinor-libipopt-dev ``` -------------------------------- ### Install cyipopt from a local copy on Ubuntu 22.04 Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/install.rst Installs cyipopt from a local source directory after APT dependencies are installed. ```sh $ cd /cyipopt/source/directory/ $ python3 -m pip install . ``` -------------------------------- ### Install cyipopt from PyPi on Ubuntu 22.04 Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/install.rst Installs the cyipopt package from PyPi after APT dependencies are installed. ```sh $ python3 -m pip install cyipopt ``` -------------------------------- ### Install cyipopt from source on Windows using Conda's Ipopt binary Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/install.rst Installs Ipopt from Conda Forge and then builds cyipopt from source. ```powershell > conda.exe install -c conda-forge ipopt > python -m pip install --no-deps --no-build-isolation . ``` -------------------------------- ### Install cyipopt Package Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/install.rst Command to install the cyipopt package into the Python environment. ```bash $ python setup.py install ``` -------------------------------- ### Install System Dependencies on Ubuntu Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/install.rst Commands to install necessary system dependencies on Ubuntu 18.04 for compiling Ipopt. ```bash $ sudo apt install pkg-config python-dev wget $ sudo apt build-dep coinor-libipopt1v5 $ sudo apt install python-pip $ pip install --user numpy cython ``` -------------------------------- ### Configure cyipopt with HSL Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/install.rst Set HSL linear solver options in cyipopt. ```python problem.add_option('linear_solver', 'ma57') problem.add_option('hsllib', 'libcoinhsl.so') ``` -------------------------------- ### Install cyipopt on Windows Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/install.rst Create and activate a conda environment for cyipopt. ```bash $ conda create -n hsl-test -c conda-forge cyipopt $ conda activate hsl-test ``` -------------------------------- ### Download and extract cyipopt source Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/install.rst Commands to download and extract the cyipopt source code. ```bash $ cd ~ $ wget https://files.pythonhosted.org/packages/05/57/a7c5a86a8f899c5c109f30b8cdb278b64c43bd2ea04172cbfed721a98fac/ipopt-0.1.9.tar.gz $ tar -xvf ipopt-0.1.8.tar.gz $ cd ipopt ``` -------------------------------- ### Solving the Constrained Optimization Problem Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/tutorial.rst Example of setting up constraints and solving the problem using minimize_ipopt. ```python from scipy.optimize import rosen, rosen_der, rosen_hess constr = {'type': 'ineq', 'fun': con, 'jac': con_jac, 'hess': con_hess} # initial guess x0 = np.array([1.1, 1.1, 1.1, 1.1, 1.1]) # solve the problem res = minimize_ipopt(rosen, jac=rosen_der, hess=rosen_hess, x0=x0, constraints=constr) ``` -------------------------------- ### Build cyipopt from source on Ubuntu 18.04 Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/install.rst Compiles cyipopt from source on Ubuntu 18.04 after installing dependencies. ```sh python setup.py build ``` -------------------------------- ### Install cyipopt using conda Source: https://github.com/mechmotum/cyipopt/blob/master/README.rst Recommended installation method for cyipopt on Linux, Mac, and Windows using conda. ```bash conda install -c conda-forge cyipopt ``` -------------------------------- ### HS071 Problem Setup and Solve Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/tutorial.rst Sets up the bounds, constraints, initial guess, and instantiates the HS071 problem, then solves it using CyIpopt. ```python lb = [1.0, 1.0, 1.0, 1.0] ub = [5.0, 5.0, 5.0, 5.0] cl = [25.0, 40.0] cu = [2.0e19, 40.0] x0 = [1.0, 5.0, 5.0, 1.0] nlp = HS071( n=len(x0), m=len(cl), lb=lb, ub=ub, cl=cl, cu=cu, ) x, info = nlp.solve(x0) ``` -------------------------------- ### SciPy Compatible Interface Example Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/tutorial.rst Demonstrates the usage of the minimize_ipopt function, which mimics scipy.optimize.minimize. ```python from scipy.optimize import rosen, rosen_der from cyipopt import minimize_ipopt x0 = [1.3, 0.7, 0.8, 1.9, 1.2] res = minimize_ipopt(rosen, x0, jac=rosen_der) print(res) ``` -------------------------------- ### Check cyipopt linking with ldd Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/install.rst Command to verify that cyipopt.so is correctly linked. ```bash $ ldd build/lib.linux-x86_64-2.7/cyipopt.so ``` -------------------------------- ### Install cyipopt using Conda Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/install.rst Installs cyipopt and its dependencies from the Conda Forge channel. ```sh $ conda install -c conda-forge cyipopt ``` -------------------------------- ### Install development version Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/development.rst Installs a development version of cyipopt in editable mode. ```sh (cyipopt-dev)$ python -m pip install --no-deps --no-build-isolation -e . ``` -------------------------------- ### Download Ipopt Source Code Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/install.rst Command to download the Ipopt source code using wget. ```bash $ cd ~ $ wget https://www.coin-or.org/download/source/Ipopt/Ipopt-3.12.11.tgz ``` -------------------------------- ### Configure HSL Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/install.rst Configure HSL to install into the current environment, link against environment's BLAS and LAPACK, and use environment's compilers. ```bash (hsl-test) $ cd /path/to/coinhsl-2014.01.10/ (hsl-test) $ ./configure \ --prefix=/home//miniconda/envs/hsl-test/ \ --with-blas="-L/home//miniconda/envs/hsl-test/lib/ -lblas" \ LIBS="-llapack" \ FC=/home//miniconda/envs/hsl-test/bin/gfortran \ CC=/home//miniconda/envs/hsl-test/bin/gcc \ ``` -------------------------------- ### Install build dependencies on Windows using Conda Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/install.rst Installs necessary build tools and libraries for cyipopt on Windows using Conda. ```powershell > conda.exe install -c conda-forge numpy cython setuptools pkg-config ``` -------------------------------- ### Create Conda environment with HSL and cyipopt Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/install.rst Command to create a Conda environment with gfortran and cyipopt. ```bash $ conda create -n hsl-test -c conda-forge gfortran cyipopt $ conda activate hsl-test ``` -------------------------------- ### Configure cyipopt on Windows Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/install.rst Add HSL solver option in cyipopt on Windows. ```python problem.add_option('linear_solver', 'ma57') ``` -------------------------------- ### Set LD_LIBRARY_PATH for cyipopt Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/install.rst Export command to set the LD_LIBRARY_PATH for Ipopt. ```bash $ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/Ipopt-3.12.11/build/lib ``` -------------------------------- ### Set environment variables for Ipopt Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/install.rst Environment variables to set after building Ipopt. ```bash $ export IPOPT_PATH="~/Ipopt-3.12.11/build" $ export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$IPOPT_PATH/lib/pkgconfig $ export PATH=$PATH:$IPOPT_PATH/bin ``` -------------------------------- ### Set Ipopt Directory Environment Variable Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/install.rst Command to set a temporary environment variable pointing to the Ipopt installation directory. ```bash $ export IPOPTDIR=~/Ipopt-3.12.11 ``` -------------------------------- ### Add LD_LIBRARY_PATH to .bashrc Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/install.rst Command to add the LD_LIBRARY_PATH export to the .bashrc file for persistence. ```bash $ echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/Ipopt-3.12.11/build/lib' >> ~/.bashrc ``` -------------------------------- ### Adding an option Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/tutorial.rst Example of adding an option to the NLP problem. ```python nlp.add_option('tol', 1e-7) ``` -------------------------------- ### Build manylinux wheels for linux/amd64 Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/install.rst Build manylinux wheels for a tagged version of cyipopt for linux/amd64 platform using docker. ```bash docker run -v $(pwd):/wheels --rm --platform=linux/amd64 quay.io/pypa/manylinux_2_28_x86_64 bash /wheels/build_manylinux_wheels.sh GIT_TAG ``` -------------------------------- ### Build manylinux wheels for linux/aarch64 Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/install.rst Build manylinux wheels for a tagged version of cyipopt for linux/aarch64 platform using docker. ```bash docker run -v $(pwd):/wheels --rm --platform=linux/aarch64 quay.io/pypa/manylinux_2_28_aarch64 bash /wheels/build_manylinux_wheels.sh GIT_TAG ``` -------------------------------- ### Verify HSL Linking Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/install.rst Check if the HSL shared library is properly linked, especially BLAS. ```bash (hsl-test) $ ldd ~/miniconda/envs/hsl-test/lib/libcoinhsl.so ``` -------------------------------- ### Check Shared Library Dependencies Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/install.rst Command to check the shared library dependencies of the compiled cyipopt.so file using ldd. ```bash $ ldd build/lib.linux-x86_64-2.7/cyipopt.so linux-vdso.so.1 (0x00007ffc1677c000) libipopt.so.0 => /usr/local/lib/libipopt.so.0 (0x00007fcdc8668000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fcdc8277000) libcoinmumps.so.0 => /usr/local/lib/libcoinmumps.so.0 (0x00007fcdc7eef000) libcoinhsl.so.0 => /usr/local/lib/libcoinhsl.so.0 (0x00007fcdc7bb4000) liblapack.so.3 => /usr/lib/x86_64-linux-gnu/liblapack.so.3 (0x00007fcdc732e000) libblas.so.3 => /usr/lib/x86_64-linux-gnu/libblas.so.3 (0x00007fcdc70d3000) libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fcdc6ecf000) libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fcdc6b46000) libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fcdc67a8000) /lib64/ld-linux-x86-64.so.2 (0x00007fcdc8d20000) libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fcdc6590000) libcoinmetis.so.0 => /usr/local/lib/libcoinmetis.so.0 (0x00007fcdc6340000) libgfortran.so.3 => /usr/lib/x86_64-linux-gnu/libgfortran.so.3 (0x00007fcdc600f000) libopenblas.so.0 => /usr/lib/x86_64-linux-gnu/libopenblas.so.0 (0x00007fcdc3d69000) libgfortran.so.4 => /usr/lib/x86_64-linux-gnu/libgfortran.so.4 (0x00007fcdc398a000) libquadmath.so.0 => /usr/lib/x86_64-linux-gnu/libquadmath.so.0 (0x00007fcdc374a000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fcdc352b000) ``` -------------------------------- ### Extract Ipopt Source Code Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/install.rst Command to extract the downloaded Ipopt source code archive. ```bash $ tar -xvf Ipopt-3.12.11.tgz ``` -------------------------------- ### Check Ipopt linking in Conda environment Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/install.rst Command to check what Ipopt is linked against within a Conda environment. ```bash (hsl-test) $ ldd ~/miniconda/envs/hsl-test/lib/libipopt.so ``` -------------------------------- ### Build documentation Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/development.rst Commands to build the HTML documentation. ```sh (cyipopt-dev)$ cd docs (cyipopt-dev)$ make html ``` -------------------------------- ### Importing Libraries Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/tutorial.rst Import necessary libraries from JAX and cyipopt, and configure JAX for 64-bit precision and CPU usage. ```python from jax import config # Enable 64 bit floating point precision config.update("jax_enable_x64", True) # We use the CPU instead of GPU und mute all warnings if no GPU/TPU is found. config.update('jax_platform_name', 'cpu') import jax.numpy as np from jax import jit, grad, jacfwd, jacrev from cyipopt import minimize_ipopt ``` -------------------------------- ### Clone the repository Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/development.rst Steps to clone the cyipopt repository. ```sh $ git clone git@github.com:mechmotum/cyipopt.git $ cd cyipopt ``` -------------------------------- ### Instantiate the Problem class Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/tutorial.rst Create an instance of the cyipopt.Problem class with the defined problem parameters. ```python nlp = cyipopt.Problem( n=len(x0), m=len(cl), problem_obj=HS071(), lb=lb, ub=ub, cl=cl, cu=cu, ) ``` -------------------------------- ### Building Derivatives and JIT Compiling Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/tutorial.rst JIT compile the objective and constraint functions, and then build their derivatives (gradient, Jacobian, Hessian) using JAX's automatic differentiation capabilities. ```python # jit the functions obj_jit = jit(objective) con_eq_jit = jit(eq_constraints) con_ineq_jit = jit(ineq_constrains) # build the derivatives and jit them obj_grad = jit(grad(obj_jit)) # objective gradient obj_hess = jit(jacrev(jacfwd(obj_jit))) # objective hessian con_eq_jac = jit(jacfwd(con_eq_jit)) # jacobian con_ineq_jac = jit(jacfwd(con_ineq_jit)) # jacobian con_eq_hess = jacrev(jacfwd(con_eq_jit)) # hessian con_eq_hessvp = jit(lambda x, v: con_eq_hess(x) * v[0]) # hessian vector-product con_ineq_hess = jacrev(jacfwd(con_ineq_jit)) # hessian con_ineq_hessvp = jit(lambda x, v: con_ineq_hess(x) * v[0]) # hessian vector-product ``` -------------------------------- ### Calling minimize_ipopt Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/tutorial.rst Set up the constraints, initial guess, and bounds, then call cyipopt's minimize_ipopt function to solve the optimization problem. ```python # constraints cons = [ {'type': 'eq', 'fun': con_eq_jit, 'jac': con_eq_jac, 'hess': con_eq_hessvp}, {'type': 'ineq', 'fun': con_ineq_jit, 'jac': con_ineq_jac, 'hess': con_ineq_hessvp} ] # starting point x0 = np.array([1.0, 5.0, 5.0, 1.0]) # variable bounds: 1 <= x[i] <= 5 bnds = [(1, 5) for _ in range(x0.size)] # executing the solver res = minimize_ipopt(obj_jit, jac=obj_grad, hess=obj_hess, x0=x0, bounds=bnds, constraints=cons, options={'disp': 5}) ``` -------------------------------- ### Import cyipopt and numpy Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/tutorial.rst Before using cyipopt, you need to import it along with numpy. ```python import cyipopt import numpy as np ``` -------------------------------- ### Executing the solver Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/tutorial.rst Calling the solve method to run the optimization algorithm. ```python x, info = nlp.solve(x0) ``` -------------------------------- ### Define bounds and initial guess Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/tutorial.rst Define the lower and upper bounds for variables and constraints, as well as an initial guess for the variables. ```python lb = [1.0, 1.0, 1.0, 1.0] ub = [5.0, 5.0, 5.0, 5.0] cl = [25.0, 40.0] cu = [2.0e19, 40.0] x0 = [1.0, 5.0, 5.0, 1.0] ``` -------------------------------- ### Add optimization options Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/tutorial.rst Set optimization parameters by calling the add_option method. ```python nlp.add_option('mu_strategy', 'adaptive') ``` -------------------------------- ### Create and activate Conda environment Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/development.rst Commands to create a Conda environment using the provided yml file and activate it. ```sh $ conda env create -f cyipopt-dev.yml $ conda activate cyipopt-dev ``` -------------------------------- ### Run tests Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/development.rst Command to run the test suite using pytest. ```sh (cyipopt-dev)$ pytest ``` -------------------------------- ### Constraint and Sparse Jacobian Implementation Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/tutorial.rst Implementation of constraint function and its sparse Jacobian using scipy.sparse.coo_array. ```python from scipy.sparse import coo_array def con(x): return np.array([ 10 -x[1]**2 - x[2], 100.0 - x[4]**2 ]) def con_jac(x): # Dense Jacobian: # J = (0 -2*x[1] -1 0 0 ) # (0 0 0 0 -2*x[4] ) # Sparse Jacobian (COO) rows = np.array([0, 0, 1]) cols = np.array(([1, 2, 4])) data = np.array([-2*x[1], -1, -2*x[4]]) return coo_array((data, (rows, cols))) ``` -------------------------------- ### Constraint Hessian Implementation Source: https://github.com/mechmotum/cyipopt/blob/master/docs/source/tutorial.rst Implementation of the Hessian-vector-product for constraints, considering the Lagrangian function. ```python def con_hess(x, _lambda): H1 = np.array([ [0, 0, 0, 0, 0], [0, -2, 0, 0, 0 ], [0, 0, 0, 0, 0 ], [0, 0, 0, 0, 0 ], [0, 0, 0, 0, 0 ] ]) H2 = np.array([ [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, -2] ]) return _lambda[0] * H1 + _lambda[1] * H2 ```